1
+ using System . Diagnostics ;
1
2
using DynamoDBGenerator . SourceGenerator . Extensions ;
2
3
using DynamoDBGenerator . SourceGenerator . Generations ;
3
4
using DynamoDBGenerator . SourceGenerator . Generations . Marshalling ;
4
5
using DynamoDBGenerator . SourceGenerator . Types ;
5
6
using Microsoft . CodeAnalysis ;
6
7
using static DynamoDBGenerator . SourceGenerator . Constants . DynamoDBGenerator . Marshaller ;
8
+
7
9
namespace DynamoDBGenerator . SourceGenerator ;
8
10
9
11
public static class MarshallerFactory
@@ -16,14 +18,18 @@ private static IEnumerable<string> CreateImplementations(IEnumerable<DynamoDBMar
16
18
17
19
foreach ( var argument in arguments )
18
20
{
19
- var ( expressionValueMethod , valueTrackerTypeName ) = AttributeExpressionValue . RootSignature ( argument . ArgumentType ) ;
20
- var ( expressionMethodName , nameTrackerTypeName ) = AttributeExpressionName . RootSignature ( argument . EntityTypeSymbol ) ;
21
+ var ( expressionValueMethod , valueTrackerTypeName ) =
22
+ AttributeExpressionValue . RootSignature ( argument . ArgumentType ) ;
23
+ var ( expressionMethodName , nameTrackerTypeName ) =
24
+ AttributeExpressionName . RootSignature ( argument . EntityTypeSymbol ) ;
21
25
22
26
var entityTypeName = argument . AnnotatedEntityType ;
23
27
var argumentTypeName = argument . AnnotatedArgumentType ;
24
28
25
- var constructor = $ "public { argument . ImplementationName } ({ options . FullName } { MarshallerOptions . ParamReference } )"
26
- . CreateScope ( $ "{ MarshallerOptions . FieldReference } = { MarshallerOptions . ParamReference } ;", $ "{ Marshaller . KeyMarshaller . PrimaryKeyMarshallerReference } = { Marshaller . KeyMarshaller . AssignmentRoot ( argument . EntityTypeSymbol ) } ;") ;
29
+ var constructor =
30
+ $ "public { argument . ImplementationName } ({ options . FullName } { MarshallerOptions . ParamReference } )"
31
+ . CreateScope ( $ "{ MarshallerOptions . FieldReference } = { MarshallerOptions . ParamReference } ;",
32
+ $ "{ Marshaller . KeyMarshaller . PrimaryKeyMarshallerReference } = { Marshaller . KeyMarshaller . AssignmentRoot ( argument . EntityTypeSymbol ) } ;") ;
27
33
var interfaceImplementation = constructor
28
34
. Concat ( Marshaller . RootSignature ( argument . EntityTypeSymbol , entityTypeName ) )
29
35
. Concat ( UnMarshaller . RootSignature ( argument . EntityTypeSymbol , entityTypeName ) )
@@ -33,14 +39,16 @@ private static IEnumerable<string> CreateImplementations(IEnumerable<DynamoDBMar
33
39
. Append ( Marshaller . KeyMarshaller . PrimaryKeyMarshallerDeclaration )
34
40
. Prepend ( options . FieldDeclaration ) ;
35
41
36
- var classImplementation = $ "private sealed class { argument . ImplementationName } : { Interface } <{ entityTypeName } , { argumentTypeName } , { nameTrackerTypeName } , { valueTrackerTypeName } >"
37
- . CreateScope ( interfaceImplementation ) ;
42
+ var classImplementation =
43
+ $ "private sealed class { argument . ImplementationName } : { Interface } <{ entityTypeName } , { argumentTypeName } , { nameTrackerTypeName } , { valueTrackerTypeName } >"
44
+ . CreateScope ( interfaceImplementation ) ;
38
45
39
46
yield return options . TryInstantiate ( ) switch
40
47
{
41
- { } arg =>
48
+ { } arg =>
42
49
$ "public static { Interface } <{ entityTypeName } , { argumentTypeName } , { nameTrackerTypeName } , { valueTrackerTypeName } > { argument . AccessName } {{ get; }} = new { argument . ImplementationName } ({ arg } );",
43
- null => $ "public static { Interface } <{ entityTypeName } , { argumentTypeName } , { nameTrackerTypeName } , { valueTrackerTypeName } > { argument . AccessName } ({ options . FullName } options) => new { argument . ImplementationName } (options);"
50
+ null =>
51
+ $ "public static { Interface } <{ entityTypeName } , { argumentTypeName } , { nameTrackerTypeName } , { valueTrackerTypeName } > { argument . AccessName } ({ options . FullName } options) => new { argument . ImplementationName } (options);"
44
52
} ;
45
53
46
54
foreach ( var s in classImplementation )
@@ -49,16 +57,39 @@ private static IEnumerable<string> CreateImplementations(IEnumerable<DynamoDBMar
49
57
}
50
58
51
59
52
- public static IEnumerable < string > CreateRepository ( IEnumerable < DynamoDBMarshallerArguments > arguments , MarshallerOptions options )
60
+ public static IEnumerable < string > Create (
61
+ INamedTypeSymbol originatingType ,
62
+ DynamoDBMarshallerArguments [ ] arguments ,
63
+ MarshallerOptions options
64
+ )
53
65
{
54
- var loadedArguments = arguments . ToArray ( ) ;
55
- var getDynamoDbProperties = TypeExtensions . CacheFactory ( SymbolEqualityComparer . IncludeNullability , TypeExtensions . GetDynamoDbProperties ) ;
56
- var code = CreateImplementations ( loadedArguments , options )
57
- . Concat ( Marshaller . CreateClass ( loadedArguments , getDynamoDbProperties , options ) )
58
- . Concat ( UnMarshaller . CreateClass ( loadedArguments , getDynamoDbProperties , options ) )
59
- . Concat ( AttributeExpressionName . CreateClasses ( loadedArguments , getDynamoDbProperties , options ) )
60
- . Concat ( AttributeExpressionValue . CreateExpressionAttributeValue ( loadedArguments , getDynamoDbProperties , options ) ) ;
66
+ var timestamp = Stopwatch . GetTimestamp ( ) ;
67
+ yield return $@ "// <auto-generated | TimeStamp: { DateTime . Now : yyyy-MM-dd HH:mm:ss} >
68
+ #nullable enable
69
+ using System;
70
+ using System.Linq;
71
+ using System.Collections.Generic;
72
+ using System.Runtime.CompilerServices;
73
+ using { Constants . AWSSDK_DynamoDBv2 . Namespace . ModelFullName } ;
74
+ using { Constants . DynamoDBGenerator . Namespace . Root } ;
75
+ using { Constants . DynamoDBGenerator . Namespace . AttributesFullName } ;
76
+ using { Constants . DynamoDBGenerator . Namespace . ExceptionsFullName } ;
77
+ using { Constants . DynamoDBGenerator . Namespace . InternalFullName } ;" ;
78
+
79
+ var dynamoDbProperties = TypeExtensions . CacheFactory (
80
+ SymbolEqualityComparer . IncludeNullability ,
81
+ TypeExtensions . GetDynamoDbProperties
82
+ ) ;
83
+
84
+ var code = CreateImplementations ( arguments , options )
85
+ . Concat ( Marshaller . CreateClass ( arguments , dynamoDbProperties , options ) )
86
+ . Concat ( UnMarshaller . CreateClass ( arguments , dynamoDbProperties , options ) )
87
+ . Concat ( AttributeExpressionName . CreateClasses ( arguments , dynamoDbProperties , options ) )
88
+ . Concat ( AttributeExpressionValue . CreateExpressionAttributeValue ( arguments , dynamoDbProperties , options ) ) ;
89
+
90
+ foreach ( var x in originatingType . NamespaceDeclaration ( originatingType . TypeDeclaration ( ) . CreateScope ( code ) ) )
91
+ yield return x ;
61
92
62
- return code ;
93
+ yield return $ "// <auto-generated | Duration { TimeSpan . FromTicks ( Stopwatch . GetTimestamp ( ) - timestamp ) } >" ;
63
94
}
64
- }
95
+ }
0 commit comments