diff --git a/src/rgen/Microsoft.Macios.Transformer.Generator/Microsoft.Macios.Transformer.Generator/XamarinBindingAPIGenerator.cs b/src/rgen/Microsoft.Macios.Transformer.Generator/Microsoft.Macios.Transformer.Generator/XamarinBindingAPIGenerator.cs index 95a7cb6f37ba..72cff4800382 100644 --- a/src/rgen/Microsoft.Macios.Transformer.Generator/Microsoft.Macios.Transformer.Generator/XamarinBindingAPIGenerator.cs +++ b/src/rgen/Microsoft.Macios.Transformer.Generator/Microsoft.Macios.Transformer.Generator/XamarinBindingAPIGenerator.cs @@ -68,7 +68,7 @@ public void Initialize (IncrementalGeneratorInitializationContext context) } static string [] GetFlagsForTarget (Dictionary flags, - AttributeTargets[] targets) + AttributeTargets [] targets) => flags.Where (kv => targets.Any (t => kv.Value.Targets.HasFlag (t))) .Select (kv => kv.Key) .ToArray (); @@ -80,7 +80,7 @@ static string [] GetFlagsForTarget (Dictionary dataAttribute.Where (kv => targets.Any (t => kv.Value.Data.Target.HasFlag (t))) .Select (kv => kv.Value) .ToArray (); - + static void WriteFlagProperty (TabbedStringBuilder sb, string flagName) { @@ -96,14 +96,14 @@ static void WriteAttributeProperty (TabbedStringBuilder sb, (string AttributeFullName, string AttributeName, BindingAttributeData Data) attrData) { // add a property that will state if we have the attr, this will help with nullability - sb.AppendLine($"readonly bool _has{attrData.AttributeName} = false;"); + sb.AppendLine ($"readonly bool _has{attrData.AttributeName} = false;"); sb.AppendLine ($"[MemberNotNullWhen (true, nameof ({attrData.AttributeName}))]"); using (var flagPropertyBlock = sb.CreateBlock ($"public bool Has{attrData.AttributeName}", block: true)) { flagPropertyBlock.AppendLine ($"get => _has{attrData.AttributeName};"); flagPropertyBlock.AppendLine ($"private init => _has{attrData.AttributeName} = value;"); } - sb.AppendLine (); - sb.AppendLine($"readonly {attrData.Data.DataModelType}? _{attrData.AttributeName} = null;"); + sb.AppendLine (); + sb.AppendLine ($"readonly {attrData.Data.DataModelType}? _{attrData.AttributeName} = null;"); // decorate to help with nullability using (var attributePropertyBlock = sb.CreateBlock ($"public {attrData.Data.DataModelType}? {attrData.AttributeName}", block: true)) { attributePropertyBlock.AppendLine ($"get => _{attrData.AttributeName};"); @@ -111,8 +111,8 @@ static void WriteAttributeProperty (TabbedStringBuilder sb, } } - static void WriteDataModelExtension (TabbedStringBuilder sb, string dataModel, string [] flags, - (string AttributeFullName, string AttributeName, BindingAttributeData Data)[] attributes) + static void WriteDataModelExtension (TabbedStringBuilder sb, string dataModel, string [] flags, + (string AttributeFullName, string AttributeName, BindingAttributeData Data) [] attributes) { sb.Clear (); sb.AppendLine ("// "); @@ -142,8 +142,8 @@ static void WriteDataModelExtension (TabbedStringBuilder sb, string dataModel, s modelBlock.AppendLine (); modelBlock.AppendLine ("readonly Dictionary>? _attributesDictionary = null;"); using (var dictionaryPropertyBlock = - modelBlock.CreateBlock ("public Dictionary>? AttributesDictionary", - block: true)) { + modelBlock.CreateBlock ("public Dictionary>? AttributesDictionary", + block: true)) { dictionaryPropertyBlock.AppendLine ("get => _attributesDictionary;"); using (var initBlock = dictionaryPropertyBlock.CreateBlock ("private init", block: true)) { initBlock.AppendLine ("_attributesDictionary = value;"); @@ -154,7 +154,7 @@ static void WriteDataModelExtension (TabbedStringBuilder sb, string dataModel, s foreach (var attributeData in attributes) { // check if the attribute is present, if it is, set the value - ifBlock.AppendLine($"Has{attributeData.AttributeName} = _attributesDictionary.Has{attributeData.AttributeName} ();"); + ifBlock.AppendLine ($"Has{attributeData.AttributeName} = _attributesDictionary.Has{attributeData.AttributeName} ();"); using (var attrIfBlock = ifBlock.CreateBlock ($"if (Has{attributeData.AttributeName})", block: true)) { attrIfBlock.AppendLine ($"{attributeData.AttributeName} = _attributesDictionary.Get{attributeData.AttributeName} ();"); } @@ -166,9 +166,9 @@ static void WriteDataModelExtension (TabbedStringBuilder sb, string dataModel, s } static void GenerateModelExtension (TabbedStringBuilder sb, string dataModel, - Dictionary flags, - Dictionary attributes, - AttributeTargets[] targets, + Dictionary flags, + Dictionary attributes, + AttributeTargets [] targets, SourceProductionContext context) { var methodFlags = GetFlagsForTarget (flags, targets); @@ -184,7 +184,7 @@ static AttributeTargets GetTarget (ISymbol symbol) // loop over attrs, if we find the BindingFlagAttribute, return the target foreach (var attr in attrData) { if (attr.AttributeClass?.Name == BindingFlagData.Name - && BindingFlagData.TryParse (attr, out var data)) { + && BindingFlagData.TryParse (attr, out var data)) { return data.Value.Target; } } @@ -198,7 +198,7 @@ static AttributeTargets GetTarget (ISymbol symbol) // loop over attrs, if we find the BindingFlagAttribute, return the target foreach (var attr in attrData) { if (attr.AttributeClass?.Name == BindingAttributeData.Name - && BindingAttributeData.TryParse (attr, out var data)) { + && BindingAttributeData.TryParse (attr, out var data)) { return data; } } @@ -230,7 +230,7 @@ void GenerateCode (SourceProductionContext context, Compilation compilation, } // all flags are collected, generate the code - var sb = new TabbedStringBuilder (new()); + var sb = new TabbedStringBuilder (new ()); GenerateDictionaryExtension (sb, flags, dataAttributes); // Add the source code to the compilation. @@ -270,8 +270,8 @@ static void GenerateDictionaryExtension (TabbedStringBuilder sb, // loop over the flags and generate a helper static method to retrieve it from a attribute data dict foreach (var (methodName, attributeName) in flags) { using (var methodBlock = classBlock.CreateBlock ( - $"public static bool {methodName} (this Dictionary> self)", - block: true)) { + $"public static bool {methodName} (this Dictionary> self)", + block: true)) { methodBlock.AppendLine ($"return self.ContainsKey ({attributeName.AttributeFullName});"); } @@ -282,16 +282,16 @@ static void GenerateDictionaryExtension (TabbedStringBuilder sb, foreach (var (methodName, attributeInfo) in dataAttributes) { // property to check if the attribute is present using (var methodBlock = classBlock.CreateBlock ( - $"public static bool {methodName} (this Dictionary> self)", - block: true)) { + $"public static bool {methodName} (this Dictionary> self)", + block: true)) { methodBlock.AppendLine ($"return self.ContainsKey ({attributeInfo.AttributeFullName});"); } classBlock.AppendLine (); // property to access the attribute using (var methodBlock = classBlock.CreateBlock ( - $"public static {attributeInfo.Data.DataModelType}? Get{attributeInfo.AttributeName} (this Dictionary> self)", - block: true)) { + $"public static {attributeInfo.Data.DataModelType}? Get{attributeInfo.AttributeName} (this Dictionary> self)", + block: true)) { methodBlock.AppendRaw ( $@"if (self.{methodName} ()) {{ var data = self.GetAttribute<{attributeInfo.Data.DataModelType}> ({attributeInfo.AttributeFullName}, {attributeInfo.Data.DataModelType}.TryParse); diff --git a/src/rgen/Microsoft.Macios.Transformer/Attributes/SnippetData.cs b/src/rgen/Microsoft.Macios.Transformer/Attributes/SnippetData.cs index 72389b4b1276..94d3f74dc3db 100644 --- a/src/rgen/Microsoft.Macios.Transformer/Attributes/SnippetData.cs +++ b/src/rgen/Microsoft.Macios.Transformer/Attributes/SnippetData.cs @@ -7,16 +7,16 @@ namespace Microsoft.Macios.Transformer.Attributes; readonly struct SnippetData : IEquatable { - + public string Code { get; } public bool Optimizable { get; } - + public SnippetData (string code) { Code = code; } - + public SnippetData (string code, bool optimizable) { Code = code; @@ -61,10 +61,10 @@ public static bool TryParse (AttributeData attributeData, } } - data = new (code, optimizable); + data = new (code, optimizable); return true; } - + public bool Equals (SnippetData other) { if (Code != other.Code) diff --git a/src/rgen/Microsoft.Macios.Transformer/Attributes/StrongDictionaryData.cs b/src/rgen/Microsoft.Macios.Transformer/Attributes/StrongDictionaryData.cs index f238f54ccb04..c518efedef29 100644 --- a/src/rgen/Microsoft.Macios.Transformer/Attributes/StrongDictionaryData.cs +++ b/src/rgen/Microsoft.Macios.Transformer/Attributes/StrongDictionaryData.cs @@ -7,15 +7,15 @@ namespace Microsoft.Macios.Transformer.Attributes; readonly struct StrongDictionaryData : IEquatable { - + public string TypeWithKeys { get; } public string? Suffix { get; } - + public StrongDictionaryData (string typeWithKeys) { TypeWithKeys = typeWithKeys; } - + public StrongDictionaryData (string typeWithKeys, string? suffix) { TypeWithKeys = typeWithKeys; @@ -60,7 +60,7 @@ public static bool TryParse (AttributeData attributeData, data = new (typeWithKeys, suffix); return true; } - + public bool Equals (StrongDictionaryData other) { if (TypeWithKeys != other.TypeWithKeys) diff --git a/src/rgen/Microsoft.Macios.Transformer/Attributes/ThreadSafeData.cs b/src/rgen/Microsoft.Macios.Transformer/Attributes/ThreadSafeData.cs index 3c42045a7c08..4f7fdeb37e56 100644 --- a/src/rgen/Microsoft.Macios.Transformer/Attributes/ThreadSafeData.cs +++ b/src/rgen/Microsoft.Macios.Transformer/Attributes/ThreadSafeData.cs @@ -7,11 +7,11 @@ namespace Microsoft.Macios.Transformer.Attributes; readonly struct ThreadSafeData : IEquatable { - + public bool Safe { get; } = true; - - public ThreadSafeData () : this (true) {} - + + public ThreadSafeData () : this (true) { } + public ThreadSafeData (bool safe) { Safe = safe; @@ -23,7 +23,7 @@ public static bool TryParse (AttributeData attributeData, data = null; var count = attributeData.ConstructorArguments.Length; if (count == 0) { - data = new(); + data = new (); return true; } bool safe = true; diff --git a/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/SnippetDataTests.cs b/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/SnippetDataTests.cs index 288647f989ed..dc867315cffe 100644 --- a/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/SnippetDataTests.cs +++ b/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/SnippetDataTests.cs @@ -13,7 +13,7 @@ namespace Microsoft.Macios.Transformer.Tests.Attributes; public class SnippetDataTests : BaseTransformerTestClass { class TestDataTryCreate : IEnumerable { - + public IEnumerator GetEnumerator () { const string path = "/some/random/path.cs"; @@ -30,8 +30,8 @@ namespace Test; [Dispose (""dispatcher = null;"", Optimizable = true)] interface NSButton { } "; - - yield return [(Source: disposeAttribute, Path: path), new SnippetData("dispatcher = null;", true)]; + + yield return [(Source: disposeAttribute, Path: path), new SnippetData ("dispatcher = null;", true)]; } IEnumerator IEnumerable.GetEnumerator () => GetEnumerator (); diff --git a/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/StrongDictionaryDataTests.cs b/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/StrongDictionaryDataTests.cs index 537901455df0..835161e2e9d3 100644 --- a/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/StrongDictionaryDataTests.cs +++ b/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/StrongDictionaryDataTests.cs @@ -12,7 +12,7 @@ namespace Microsoft.Macios.Transformer.Tests.Attributes; public class StrongDictionaryDataTests : BaseTransformerTestClass { - + class TestDataTryCreate : IEnumerable { public IEnumerator GetEnumerator () { @@ -33,8 +33,8 @@ interface AVCapturePhotoSettingsThumbnailFormat { NSNumber Height { get; set; } } "; - - yield return [(Source: strongDictionary, Path: "/some/random/path.cs"), new StrongDictionaryData("AVCapturePhotoSettingsThumbnailFormatKeys")]; + + yield return [(Source: strongDictionary, Path: "/some/random/path.cs"), new StrongDictionaryData ("AVCapturePhotoSettingsThumbnailFormatKeys")]; } IEnumerator IEnumerable.GetEnumerator () => GetEnumerator (); diff --git a/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/ThreadSafeDataTests.cs b/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/ThreadSafeDataTests.cs index 768d5d1865a9..87d9b004a77c 100644 --- a/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/ThreadSafeDataTests.cs +++ b/tests/rgen/Microsoft.Macios.Transformer.Tests/Attributes/ThreadSafeDataTests.cs @@ -12,7 +12,7 @@ namespace Microsoft.Macios.Transformer.Tests.Attributes; public class ThreadSafeDataTests : BaseTransformerTestClass { - + class TestDataTryCreate : IEnumerable { public IEnumerator GetEnumerator () { @@ -37,8 +37,8 @@ interface UIFeedbackGenerator : UIInteraction { void Prepare (); } "; - - yield return [(Source: threadSageMethod, Path: path), new ThreadSafeData()]; + + yield return [(Source: threadSageMethod, Path: path), new ThreadSafeData ()]; const string notThreadSafeMethod = @" using System; @@ -59,8 +59,8 @@ interface UIFeedbackGenerator : UIInteraction { void Prepare (); } "; - - yield return [(Source: notThreadSafeMethod, Path: path), new ThreadSafeData(false)]; + + yield return [(Source: notThreadSafeMethod, Path: path), new ThreadSafeData (false)]; }