@@ -8,28 +8,37 @@ public readonly struct MarshallerOptions
8
8
{
9
9
private readonly INamedTypeSymbol _convertersType ;
10
10
private readonly int _enumStrategy ;
11
+ // TODO name needs to take namespace etc into account in order to make it accessible from the outside.
11
12
public const string Name = "MarshallerOptions" ;
12
13
public const string FieldReference = "_options" ;
13
14
public const string ParamReference = "options" ;
14
15
private const string ConvertersProperty = "Converters" ;
15
16
public const string FieldDeclaration = $ "private readonly { Name } { FieldReference } ;";
16
17
private readonly string _converterFullPath ;
18
+ private readonly string _optionsFullPath ;
17
19
18
- private MarshallerOptions ( INamedTypeSymbol convertersType ,
19
- IEnumerable < KeyValuePair < string , ITypeSymbol > > converters , int enumStrategy )
20
+
21
+ private MarshallerOptions (
22
+ INamedTypeSymbol orignalType ,
23
+ INamedTypeSymbol convertersType ,
24
+ IEnumerable < KeyValuePair < string , ITypeSymbol > > converters ,
25
+ int enumStrategy
26
+ )
20
27
{
21
28
Converters = converters . ToDictionary ( x => x . Value , x => x , SymbolEqualityComparer . Default ) ;
22
29
_convertersType = convertersType ;
23
30
_enumStrategy = enumStrategy ;
24
31
_converterFullPath = _convertersType . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ;
32
+ _optionsFullPath =
33
+ $ "{ orignalType . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) } .{ Name } ";
25
34
}
26
35
27
36
public string ? TryInstantiate ( )
28
37
{
29
38
if ( _convertersType . InstanceConstructors . Length is 0 ||
30
39
_convertersType . InstanceConstructors . All ( x => x . Parameters . Length is 0 ) )
31
40
{
32
- return $ "new { Name } (new { _converterFullPath } ())";
41
+ return $ "new { _optionsFullPath } (new { _converterFullPath } ())";
33
42
}
34
43
35
44
return null ;
@@ -100,15 +109,15 @@ public IEnumerable<string> ClassDeclaration
100
109
}
101
110
}
102
111
103
- public static MarshallerOptions Create ( INamedTypeSymbol typeSymbol , int enumStrategy )
112
+ public static MarshallerOptions Create ( INamedTypeSymbol orignalType , INamedTypeSymbol converterTypeSymbol , int enumStrategy )
104
113
{
105
- var keyValuePairs = typeSymbol
114
+ var keyValuePairs = converterTypeSymbol
106
115
. GetMembersToObject ( )
107
116
. Select ( ConverterDataMemberOrNull )
108
117
. Where ( x => x . HasValue )
109
118
. Select ( x => x ! . Value ) ;
110
119
111
- return new MarshallerOptions ( typeSymbol , keyValuePairs , enumStrategy ) ;
120
+ return new MarshallerOptions ( orignalType , converterTypeSymbol , keyValuePairs , enumStrategy ) ;
112
121
}
113
122
114
123
private static KeyValuePair < string , ITypeSymbol > ? ConverterDataMemberOrNull ( ISymbol symbol )
0 commit comments