@@ -68,7 +68,7 @@ public void Initialize (IncrementalGeneratorInitializationContext context)
6868 }
6969
7070 static string [ ] GetFlagsForTarget ( Dictionary < string , ( string AttributeFullName , AttributeTargets Targets ) > flags ,
71- AttributeTargets [ ] targets )
71+ AttributeTargets [ ] targets )
7272 => flags . Where ( kv => targets . Any ( t => kv . Value . Targets . HasFlag ( t ) ) )
7373 . Select ( kv => kv . Key )
7474 . ToArray ( ) ;
@@ -80,7 +80,7 @@ static string [] GetFlagsForTarget (Dictionary<string, (string AttributeFullName
8080 => dataAttribute . Where ( kv => targets . Any ( t => kv . Value . Data . Target . HasFlag ( t ) ) )
8181 . Select ( kv => kv . Value )
8282 . ToArray ( ) ;
83-
83+
8484
8585 static void WriteFlagProperty ( TabbedStringBuilder sb , string flagName )
8686 {
@@ -96,23 +96,23 @@ static void WriteAttributeProperty (TabbedStringBuilder sb,
9696 ( string AttributeFullName , string AttributeName , BindingAttributeData Data ) attrData )
9797 {
9898 // add a property that will state if we have the attr, this will help with nullability
99- sb . AppendLine ( $ "readonly bool _has{ attrData . AttributeName } = false;") ;
99+ sb . AppendLine ( $ "readonly bool _has{ attrData . AttributeName } = false;") ;
100100 sb . AppendLine ( $ "[MemberNotNullWhen (true, nameof ({ attrData . AttributeName } ))]") ;
101101 using ( var flagPropertyBlock = sb . CreateBlock ( $ "public bool Has{ attrData . AttributeName } ", block : true ) ) {
102102 flagPropertyBlock . AppendLine ( $ "get => _has{ attrData . AttributeName } ;") ;
103103 flagPropertyBlock . AppendLine ( $ "private init => _has{ attrData . AttributeName } = value;") ;
104104 }
105- sb . AppendLine ( ) ;
106- sb . AppendLine ( $ "readonly { attrData . Data . DataModelType } ? _{ attrData . AttributeName } = null;") ;
105+ sb . AppendLine ( ) ;
106+ sb . AppendLine ( $ "readonly { attrData . Data . DataModelType } ? _{ attrData . AttributeName } = null;") ;
107107 // decorate to help with nullability
108108 using ( var attributePropertyBlock = sb . CreateBlock ( $ "public { attrData . Data . DataModelType } ? { attrData . AttributeName } ", block : true ) ) {
109109 attributePropertyBlock . AppendLine ( $ "get => _{ attrData . AttributeName } ;") ;
110110 attributePropertyBlock . AppendLine ( $ "private init => _{ attrData . AttributeName } = value;") ;
111111 }
112112 }
113113
114- static void WriteDataModelExtension ( TabbedStringBuilder sb , string dataModel , string [ ] flags ,
115- ( string AttributeFullName , string AttributeName , BindingAttributeData Data ) [ ] attributes )
114+ static void WriteDataModelExtension ( TabbedStringBuilder sb , string dataModel , string [ ] flags ,
115+ ( string AttributeFullName , string AttributeName , BindingAttributeData Data ) [ ] attributes )
116116 {
117117 sb . Clear ( ) ;
118118 sb . AppendLine ( "// <auto-generated/>" ) ;
@@ -142,8 +142,8 @@ static void WriteDataModelExtension (TabbedStringBuilder sb, string dataModel, s
142142 modelBlock . AppendLine ( ) ;
143143 modelBlock . AppendLine ( "readonly Dictionary<string, List<AttributeData>>? _attributesDictionary = null;" ) ;
144144 using ( var dictionaryPropertyBlock =
145- modelBlock . CreateBlock ( "public Dictionary<string, List<AttributeData>>? AttributesDictionary" ,
146- block : true ) ) {
145+ modelBlock . CreateBlock ( "public Dictionary<string, List<AttributeData>>? AttributesDictionary" ,
146+ block : true ) ) {
147147 dictionaryPropertyBlock . AppendLine ( "get => _attributesDictionary;" ) ;
148148 using ( var initBlock = dictionaryPropertyBlock . CreateBlock ( "private init" , block : true ) ) {
149149 initBlock . AppendLine ( "_attributesDictionary = value;" ) ;
@@ -154,7 +154,7 @@ static void WriteDataModelExtension (TabbedStringBuilder sb, string dataModel, s
154154
155155 foreach ( var attributeData in attributes ) {
156156 // check if the attribute is present, if it is, set the value
157- ifBlock . AppendLine ( $ "Has{ attributeData . AttributeName } = _attributesDictionary.Has{ attributeData . AttributeName } ();") ;
157+ ifBlock . AppendLine ( $ "Has{ attributeData . AttributeName } = _attributesDictionary.Has{ attributeData . AttributeName } ();") ;
158158 using ( var attrIfBlock = ifBlock . CreateBlock ( $ "if (Has{ attributeData . AttributeName } )", block : true ) ) {
159159 attrIfBlock . AppendLine ( $ "{ attributeData . AttributeName } = _attributesDictionary.Get{ attributeData . AttributeName } ();") ;
160160 }
@@ -166,9 +166,9 @@ static void WriteDataModelExtension (TabbedStringBuilder sb, string dataModel, s
166166 }
167167
168168 static void GenerateModelExtension ( TabbedStringBuilder sb , string dataModel ,
169- Dictionary < string , ( string AttributeFullName , AttributeTargets Targets ) > flags ,
170- Dictionary < string , ( string AttributeFullName , string AttributeName , BindingAttributeData Data ) > attributes ,
171- AttributeTargets [ ] targets ,
169+ Dictionary < string , ( string AttributeFullName , AttributeTargets Targets ) > flags ,
170+ Dictionary < string , ( string AttributeFullName , string AttributeName , BindingAttributeData Data ) > attributes ,
171+ AttributeTargets [ ] targets ,
172172 SourceProductionContext context )
173173 {
174174 var methodFlags = GetFlagsForTarget ( flags , targets ) ;
@@ -184,7 +184,7 @@ static AttributeTargets GetTarget (ISymbol symbol)
184184 // loop over attrs, if we find the BindingFlagAttribute, return the target
185185 foreach ( var attr in attrData ) {
186186 if ( attr . AttributeClass ? . Name == BindingFlagData . Name
187- && BindingFlagData . TryParse ( attr , out var data ) ) {
187+ && BindingFlagData . TryParse ( attr , out var data ) ) {
188188 return data . Value . Target ;
189189 }
190190 }
@@ -198,7 +198,7 @@ static AttributeTargets GetTarget (ISymbol symbol)
198198 // loop over attrs, if we find the BindingFlagAttribute, return the target
199199 foreach ( var attr in attrData ) {
200200 if ( attr . AttributeClass ? . Name == BindingAttributeData . Name
201- && BindingAttributeData . TryParse ( attr , out var data ) ) {
201+ && BindingAttributeData . TryParse ( attr , out var data ) ) {
202202 return data ;
203203 }
204204 }
@@ -230,7 +230,7 @@ void GenerateCode (SourceProductionContext context, Compilation compilation,
230230 }
231231
232232 // all flags are collected, generate the code
233- var sb = new TabbedStringBuilder ( new ( ) ) ;
233+ var sb = new TabbedStringBuilder ( new ( ) ) ;
234234 GenerateDictionaryExtension ( sb , flags , dataAttributes ) ;
235235
236236 // Add the source code to the compilation.
@@ -270,8 +270,8 @@ static void GenerateDictionaryExtension (TabbedStringBuilder sb,
270270 // loop over the flags and generate a helper static method to retrieve it from a attribute data dict
271271 foreach ( var ( methodName , attributeName ) in flags ) {
272272 using ( var methodBlock = classBlock . CreateBlock (
273- $ "public static bool { methodName } (this Dictionary<string, List<AttributeData>> self)",
274- block : true ) ) {
273+ $ "public static bool { methodName } (this Dictionary<string, List<AttributeData>> self)",
274+ block : true ) ) {
275275 methodBlock . AppendLine ( $ "return self.ContainsKey ({ attributeName . AttributeFullName } );") ;
276276 }
277277
@@ -282,16 +282,16 @@ static void GenerateDictionaryExtension (TabbedStringBuilder sb,
282282 foreach ( var ( methodName , attributeInfo ) in dataAttributes ) {
283283 // property to check if the attribute is present
284284 using ( var methodBlock = classBlock . CreateBlock (
285- $ "public static bool { methodName } (this Dictionary<string, List<AttributeData>> self)",
286- block : true ) ) {
285+ $ "public static bool { methodName } (this Dictionary<string, List<AttributeData>> self)",
286+ block : true ) ) {
287287 methodBlock . AppendLine ( $ "return self.ContainsKey ({ attributeInfo . AttributeFullName } );") ;
288288 }
289289
290290 classBlock . AppendLine ( ) ;
291291 // property to access the attribute
292292 using ( var methodBlock = classBlock . CreateBlock (
293- $ "public static { attributeInfo . Data . DataModelType } ? Get{ attributeInfo . AttributeName } (this Dictionary<string, List<AttributeData>> self)",
294- block : true ) ) {
293+ $ "public static { attributeInfo . Data . DataModelType } ? Get{ attributeInfo . AttributeName } (this Dictionary<string, List<AttributeData>> self)",
294+ block : true ) ) {
295295 methodBlock . AppendRaw (
296296$@ "if (self.{ methodName } ()) {{
297297 var data = self.GetAttribute<{ attributeInfo . Data . DataModelType } > ({ attributeInfo . AttributeFullName } , { attributeInfo . Data . DataModelType } .TryParse);
0 commit comments