From 8a9507c736a0be1bd5d4490bc4caceeb4bed0067 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 28 Sep 2021 17:37:59 -0700 Subject: [PATCH 1/7] Fix naming violations (IDE1006) --- .../ManualTypeMarshallingAnalyzer.cs | 46 ++-- .../gen/DllImportGenerator/Comparers.cs | 16 +- .../DllImportGenerator/DllImportGenerator.cs | 12 +- .../ForwarderMarshallingGeneratorFactory.cs | 4 +- .../GeneratorDiagnostics.cs | 24 +- ...oPreserveSigMarshallingGeneratorFactory.cs | 10 +- .../PInvokeStubCodeGenerator.cs | 62 ++--- ...CollectionElementMarshallingCodeContext.cs | 8 +- .../Marshalling/ArrayMarshaller.cs | 34 +-- ...ributedMarshallingModelGeneratorFactory.cs | 14 +- .../ByValueContentsMarshalKindValidator.cs | 6 +- .../Marshalling/CharMarshaller.cs | 4 +- .../CustomNativeTypeMarshallingGenerator.cs | 28 +-- .../Marshalling/HResultExceptionMarshaller.cs | 4 +- .../ICustomNativeTypeMarshallingStrategy.cs | 224 +++++++++--------- .../Marshalling/MarshallerHelpers.cs | 12 +- .../MarshallingGeneratorFactory.cs | 68 +++--- .../PinnableManagedValueMarshaller.cs | 16 +- .../Marshalling/StringMarshaller.Ansi.cs | 12 +- .../StringMarshaller.PlatformDefined.cs | 28 +-- .../Marshalling/StringMarshaller.Utf16.cs | 4 +- .../Marshalling/StringMarshaller.Utf8.cs | 8 +- 22 files changed, 322 insertions(+), 322 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs index 7901b3f628a2f..fae3f7dc1cf99 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs @@ -225,13 +225,13 @@ private void PrepareForAnalysis(CompilationStartAnalysisContext context) private class PerCompilationAnalyzer { - private readonly INamedTypeSymbol GeneratedMarshallingAttribute; - private readonly INamedTypeSymbol BlittableTypeAttribute; - private readonly INamedTypeSymbol NativeMarshallingAttribute; - private readonly INamedTypeSymbol MarshalUsingAttribute; - private readonly INamedTypeSymbol GenericContiguousCollectionMarshallerAttribute; - private readonly INamedTypeSymbol SpanOfByte; - private readonly INamedTypeSymbol StructLayoutAttribute; + private readonly INamedTypeSymbol _generatedMarshallingAttribute; + private readonly INamedTypeSymbol _blittableTypeAttribute; + private readonly INamedTypeSymbol _nativeMarshallingAttribute; + private readonly INamedTypeSymbol _marshalUsingAttribute; + private readonly INamedTypeSymbol _genericContiguousCollectionMarshallerAttribute; + private readonly INamedTypeSymbol _spanOfByte; + private readonly INamedTypeSymbol _structLayoutAttribute; public PerCompilationAnalyzer(INamedTypeSymbol generatedMarshallingAttribute, INamedTypeSymbol blittableTypeAttribute, @@ -241,13 +241,13 @@ public PerCompilationAnalyzer(INamedTypeSymbol generatedMarshallingAttribute, INamedTypeSymbol spanOfByte, INamedTypeSymbol structLayoutAttribute) { - GeneratedMarshallingAttribute = generatedMarshallingAttribute; - BlittableTypeAttribute = blittableTypeAttribute; - NativeMarshallingAttribute = nativeMarshallingAttribute; - MarshalUsingAttribute = marshalUsingAttribute; - GenericContiguousCollectionMarshallerAttribute = genericContiguousCollectionMarshallerAttribute; - SpanOfByte = spanOfByte; - StructLayoutAttribute = structLayoutAttribute; + _generatedMarshallingAttribute = generatedMarshallingAttribute; + _blittableTypeAttribute = blittableTypeAttribute; + _nativeMarshallingAttribute = nativeMarshallingAttribute; + _marshalUsingAttribute = marshalUsingAttribute; + _genericContiguousCollectionMarshallerAttribute = genericContiguousCollectionMarshallerAttribute; + _spanOfByte = spanOfByte; + _structLayoutAttribute = structLayoutAttribute; } public void AnalyzeTypeDefinition(SymbolAnalysisContext context) @@ -258,17 +258,17 @@ public void AnalyzeTypeDefinition(SymbolAnalysisContext context) AttributeData? nativeMarshallingAttributeData = null; foreach (var attr in type.GetAttributes()) { - if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, GeneratedMarshallingAttribute)) + if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, _generatedMarshallingAttribute)) { // If the type has the GeneratedMarshallingAttribute, // we let the source generator handle error checking. return; } - else if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, BlittableTypeAttribute)) + else if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, _blittableTypeAttribute)) { blittableTypeAttributeData = attr; } - else if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, NativeMarshallingAttribute)) + else if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, _nativeMarshallingAttribute)) { nativeMarshallingAttributeData = attr; } @@ -281,7 +281,7 @@ public void AnalyzeTypeDefinition(SymbolAnalysisContext context) CannotHaveMultipleMarshallingAttributesRule, type.ToDisplayString())); } - else if (blittableTypeAttributeData is not null && (!type.HasOnlyBlittableFields() || type.IsAutoLayout(StructLayoutAttribute))) + else if (blittableTypeAttributeData is not null && (!type.HasOnlyBlittableFields() || type.IsAutoLayout(_structLayoutAttribute))) { context.ReportDiagnostic( blittableTypeAttributeData.CreateDiagnostic( @@ -307,7 +307,7 @@ private bool HasMultipleMarshallingAttributes(AttributeData? blittableTypeAttrib public void AnalyzeElement(SymbolAnalysisContext context) { - AttributeData? attrData = context.Symbol.GetAttributes().FirstOrDefault(attr => SymbolEqualityComparer.Default.Equals(MarshalUsingAttribute, attr.AttributeClass)); + AttributeData? attrData = context.Symbol.GetAttributes().FirstOrDefault(attr => SymbolEqualityComparer.Default.Equals(_marshalUsingAttribute, attr.AttributeClass)); if (attrData is not null) { if (context.Symbol is IParameterSymbol param) @@ -324,7 +324,7 @@ public void AnalyzeElement(SymbolAnalysisContext context) public void AnalyzeReturnType(SymbolAnalysisContext context) { var method = (IMethodSymbol)context.Symbol; - AttributeData? attrData = method.GetReturnTypeAttributes().FirstOrDefault(attr => SymbolEqualityComparer.Default.Equals(MarshalUsingAttribute, attr.AttributeClass)); + AttributeData? attrData = method.GetReturnTypeAttributes().FirstOrDefault(attr => SymbolEqualityComparer.Default.Equals(_marshalUsingAttribute, attr.AttributeClass)); if (attrData is not null) { AnalyzeNativeMarshalerType(context, method.ReturnType, attrData, isNativeMarshallingAttribute: false); @@ -364,12 +364,12 @@ private void AnalyzeNativeMarshalerType(SymbolAnalysisContext context, ITypeSymb DiagnosticDescriptor requiredShapeRule = NativeTypeMustHaveRequiredShapeRule; ManualTypeMarshallingHelper.NativeTypeMarshallingVariant variant = ManualTypeMarshallingHelper.NativeTypeMarshallingVariant.Standard; - if (marshalerType.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(GenericContiguousCollectionMarshallerAttribute, a.AttributeClass))) + if (marshalerType.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(_genericContiguousCollectionMarshallerAttribute, a.AttributeClass))) { variant = ManualTypeMarshallingHelper.NativeTypeMarshallingVariant.ContiguousCollection; requiredShapeRule = CollectionNativeTypeMustHaveRequiredShapeRule; if (!ManualTypeMarshallingHelper.TryGetManagedValuesProperty(marshalerType, out _) - || !ManualTypeMarshallingHelper.HasNativeValueStorageProperty(marshalerType, SpanOfByte)) + || !ManualTypeMarshallingHelper.HasNativeValueStorageProperty(marshalerType, _spanOfByte)) { context.ReportDiagnostic( GetDiagnosticLocations(context, marshalerType, nativeMarshalerAttributeData).CreateDiagnostic( @@ -425,7 +425,7 @@ private void AnalyzeNativeMarshalerType(SymbolAnalysisContext context, ITypeSymb hasConstructor = hasConstructor || ManualTypeMarshallingHelper.IsManagedToNativeConstructor(ctor, type, variant); - if (!hasStackallocConstructor && ManualTypeMarshallingHelper.IsStackallocConstructor(ctor, type, SpanOfByte, variant)) + if (!hasStackallocConstructor && ManualTypeMarshallingHelper.IsStackallocConstructor(ctor, type, _spanOfByte, variant)) { hasStackallocConstructor = true; IFieldSymbol stackAllocSizeField = nativeType.GetMembers("StackBufferSize").OfType().FirstOrDefault(); diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Comparers.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Comparers.cs index e830159c49f3d..3e86f4eae8326 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Comparers.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Comparers.cs @@ -39,7 +39,7 @@ internal static class Comparers /// The type of immutable array element. internal class ImmutableArraySequenceEqualComparer : IEqualityComparer> { - private readonly IEqualityComparer elementComparer; + private readonly IEqualityComparer _elementComparer; /// /// Creates an with a custom comparer for the elements of the collection. @@ -47,12 +47,12 @@ internal class ImmutableArraySequenceEqualComparer : IEqualityComparerThe comparer instance for the collection elements. public ImmutableArraySequenceEqualComparer(IEqualityComparer elementComparer) { - this.elementComparer = elementComparer; + this._elementComparer = elementComparer; } public bool Equals(ImmutableArray x, ImmutableArray y) { - return x.SequenceEqual(y, elementComparer); + return x.SequenceEqual(y, _elementComparer); } public int GetHashCode(ImmutableArray obj) @@ -76,18 +76,18 @@ public int GetHashCode(SyntaxNode obj) internal class CustomValueTupleElementComparer : IEqualityComparer<(T, U)> { - private readonly IEqualityComparer item1Comparer; - private readonly IEqualityComparer item2Comparer; + private readonly IEqualityComparer _item1Comparer; + private readonly IEqualityComparer _item2Comparer; public CustomValueTupleElementComparer(IEqualityComparer item1Comparer, IEqualityComparer item2Comparer) { - this.item1Comparer = item1Comparer; - this.item2Comparer = item2Comparer; + this._item1Comparer = item1Comparer; + this._item2Comparer = item2Comparer; } public bool Equals((T, U) x, (T, U) y) { - return item1Comparer.Equals(x.Item1, y.Item1) && item2Comparer.Equals(x.Item2, y.Item2); + return _item1Comparer.Equals(x.Item1, y.Item1) && _item2Comparer.Equals(x.Item2, y.Item2); } public int GetHashCode((T, U) obj) diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs index 94e26409c29d0..89e321c7623ec 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs @@ -25,7 +25,7 @@ public sealed class DllImportGenerator : IIncrementalGenerator private const string GeneratedDllImport = nameof(GeneratedDllImport); private const string GeneratedDllImportAttribute = nameof(GeneratedDllImportAttribute); - private static readonly Version MinimumSupportedFrameworkVersion = new Version(5, 0); + private static readonly Version s_minimumSupportedFrameworkVersion = new Version(5, 0); internal sealed record IncrementalStubGenerationContext(DllImportStubContext StubContext, ImmutableArray ForwardedAttributes, GeneratedDllImportData DllImportData, ImmutableArray Diagnostics) { @@ -57,10 +57,10 @@ public enum StepName public record ExecutedStepInfo(StepName Step, object Input); - private List executedSteps = new(); - public IEnumerable ExecutedSteps => executedSteps; + private List _executedSteps = new(); + public IEnumerable ExecutedSteps => _executedSteps; - internal void RecordExecutedStep(ExecutedStepInfo step) => executedSteps.Add(step); + internal void RecordExecutedStep(ExecutedStepInfo step) => _executedSteps.Add(step); } /// @@ -106,7 +106,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) Diagnostic.Create( GeneratorDiagnostics.TargetFrameworkNotSupported, Location.None, - MinimumSupportedFrameworkVersion.ToString(2))); + s_minimumSupportedFrameworkVersion.ToString(2))); } }); @@ -294,7 +294,7 @@ private static bool IsSupportedTargetFramework(Compilation compilation, out Vers // .NET Standard "netstandard" => false, // .NET Core (when version < 5.0) or .NET - "System.Runtime" or "System.Private.CoreLib" => version >= MinimumSupportedFrameworkVersion, + "System.Runtime" or "System.Private.CoreLib" => version >= s_minimumSupportedFrameworkVersion, _ => false, }; } diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/ForwarderMarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/ForwarderMarshallingGeneratorFactory.cs index 26824f5d8a1ac..53fb3235c2d8b 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/ForwarderMarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/ForwarderMarshallingGeneratorFactory.cs @@ -9,8 +9,8 @@ namespace Microsoft.Interop { internal class ForwarderMarshallingGeneratorFactory : IMarshallingGeneratorFactory { - private static readonly Forwarder Forwarder = new Forwarder(); + private static readonly Forwarder s_forwarder = new Forwarder(); - public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) => Forwarder; + public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) => s_forwarder; } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/GeneratorDiagnostics.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/GeneratorDiagnostics.cs index 5b6cc3518a41a..0ebfe4830d8ba 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/GeneratorDiagnostics.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/GeneratorDiagnostics.cs @@ -127,9 +127,9 @@ public class Ids isEnabledByDefault: true, description: GetResourceString(nameof(Resources.TargetFrameworkNotSupportedDescription))); - private readonly List diagnostics = new List(); + private readonly List _diagnostics = new List(); - public IEnumerable Diagnostics => diagnostics; + public IEnumerable Diagnostics => _diagnostics; /// /// Report diagnostic for configuration that is not supported by the DLL import source generator @@ -144,14 +144,14 @@ public void ReportConfigurationNotSupported( { if (unsupportedValue == null) { - diagnostics.Add( + _diagnostics.Add( attributeData.CreateDiagnostic( GeneratorDiagnostics.ConfigurationNotSupported, configurationName)); } else { - diagnostics.Add( + _diagnostics.Add( attributeData.CreateDiagnostic( GeneratorDiagnostics.ConfigurationValueNotSupported, unsupportedValue, @@ -191,7 +191,7 @@ public void ReportMarshallingNotSupported( // Report the specific not-supported reason. if (info.IsManagedReturnPosition) { - diagnostics.Add( + _diagnostics.Add( diagnosticLocation.CreateDiagnostic( GeneratorDiagnostics.ReturnTypeNotSupportedWithDetails, notSupportedDetails!, @@ -199,7 +199,7 @@ public void ReportMarshallingNotSupported( } else { - diagnostics.Add( + _diagnostics.Add( diagnosticLocation.CreateDiagnostic( GeneratorDiagnostics.ParameterTypeNotSupportedWithDetails, notSupportedDetails!, @@ -213,7 +213,7 @@ public void ReportMarshallingNotSupported( // than when there is no attribute and the type itself is not supported. if (info.IsManagedReturnPosition) { - diagnostics.Add( + _diagnostics.Add( diagnosticLocation.CreateDiagnostic( GeneratorDiagnostics.ReturnConfigurationNotSupported, nameof(System.Runtime.InteropServices.MarshalAsAttribute), @@ -221,7 +221,7 @@ public void ReportMarshallingNotSupported( } else { - diagnostics.Add( + _diagnostics.Add( diagnosticLocation.CreateDiagnostic( GeneratorDiagnostics.ParameterConfigurationNotSupported, nameof(System.Runtime.InteropServices.MarshalAsAttribute), @@ -233,7 +233,7 @@ public void ReportMarshallingNotSupported( // Report that the type is not supported if (info.IsManagedReturnPosition) { - diagnostics.Add( + _diagnostics.Add( diagnosticLocation.CreateDiagnostic( GeneratorDiagnostics.ReturnTypeNotSupported, info.ManagedType.DiagnosticFormattedName, @@ -241,7 +241,7 @@ public void ReportMarshallingNotSupported( } else { - diagnostics.Add( + _diagnostics.Add( diagnosticLocation.CreateDiagnostic( GeneratorDiagnostics.ParameterTypeNotSupported, info.ManagedType.DiagnosticFormattedName, @@ -255,7 +255,7 @@ public void ReportInvalidMarshallingAttributeInfo( string reasonResourceName, params string[] reasonArgs) { - diagnostics.Add( + _diagnostics.Add( attributeData.CreateDiagnostic( GeneratorDiagnostics.MarshallingAttributeConfigurationNotSupported, new LocalizableResourceString(reasonResourceName, Resources.ResourceManager, typeof(Resources), reasonArgs))); @@ -267,7 +267,7 @@ public void ReportInvalidMarshallingAttributeInfo( /// Minimum supported version of .NET public void ReportTargetFrameworkNotSupported(Version minimumSupportedVersion) { - diagnostics.Add( + _diagnostics.Add( Diagnostic.Create( TargetFrameworkNotSupported, Location.None, diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/NoPreserveSigMarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/NoPreserveSigMarshallingGeneratorFactory.cs index d46e1d42325c2..3ac176c0016e6 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/NoPreserveSigMarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/NoPreserveSigMarshallingGeneratorFactory.cs @@ -11,12 +11,12 @@ namespace Microsoft.Interop { internal class NoPreserveSigMarshallingGeneratorFactory : IMarshallingGeneratorFactory { - private static readonly HResultExceptionMarshaller HResultException = new HResultExceptionMarshaller(); - private readonly IMarshallingGeneratorFactory inner; + private static readonly HResultExceptionMarshaller s_hResultException = new HResultExceptionMarshaller(); + private readonly IMarshallingGeneratorFactory _inner; public NoPreserveSigMarshallingGeneratorFactory(IMarshallingGeneratorFactory inner) { - this.inner = inner; + this._inner = inner; } public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) @@ -25,9 +25,9 @@ public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext conte { // Use marshaller for native HRESULT return / exception throwing System.Diagnostics.Debug.Assert(info.ManagedType.Equals(SpecialTypeInfo.Int32)); - return HResultException; + return s_hResultException; } - return inner.Create(info, context); + return _inner.Create(info, context); } } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/PInvokeStubCodeGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/PInvokeStubCodeGenerator.cs index 74c5322881879..ec026ee163f61 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/PInvokeStubCodeGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/PInvokeStubCodeGenerator.cs @@ -55,11 +55,11 @@ private record struct BoundGenerator(TypePositionInfo TypeInfo, IMarshallingGene // Error code representing success. This maps to S_OK for Windows HRESULT semantics and 0 for POSIX errno semantics. private const int SuccessErrorCode = 0; - private readonly bool setLastError; - private readonly List paramMarshallers; - private readonly BoundGenerator retMarshaller; - private readonly List sortedMarshallers; - private readonly bool stubReturnsVoid; + private readonly bool _setLastError; + private readonly List _paramMarshallers; + private readonly BoundGenerator _retMarshaller; + private readonly List _sortedMarshallers; + private readonly bool _stubReturnsVoid; public PInvokeStubCodeGenerator( IEnumerable argTypes, @@ -67,7 +67,7 @@ public PInvokeStubCodeGenerator( Action marshallingNotSupportedCallback, IMarshallingGeneratorFactory generatorFactory) { - this.setLastError = setLastError; + this._setLastError = setLastError; List allMarshallers = new(); List paramMarshallers = new(); @@ -98,17 +98,17 @@ public PInvokeStubCodeGenerator( } } - this.stubReturnsVoid = managedRetMarshaller.TypeInfo.ManagedType == SpecialTypeInfo.Void; + this._stubReturnsVoid = managedRetMarshaller.TypeInfo.ManagedType == SpecialTypeInfo.Void; - if (!managedRetMarshaller.TypeInfo.IsNativeReturnPosition && !this.stubReturnsVoid) + if (!managedRetMarshaller.TypeInfo.IsNativeReturnPosition && !this._stubReturnsVoid) { // If the managed ret marshaller isn't the native ret marshaller, then the managed ret marshaller // is a parameter. paramMarshallers.Add(managedRetMarshaller); } - this.retMarshaller = nativeRetMarshaller; - this.paramMarshallers = paramMarshallers; + this._retMarshaller = nativeRetMarshaller; + this._paramMarshallers = paramMarshallers; // We are doing a topological sort of our marshallers to ensure that each parameter/return value's // dependencies are unmarshalled before their dependents. This comes up in the case of contiguous @@ -132,7 +132,7 @@ public PInvokeStubCodeGenerator( // the return value has dependencies on numRows and numColumns and numRows has a dependency on numColumns, // we want to unmarshal numColumns, then numRows, then the return value. // A topological sort ensures we get this order correct. - this.sortedMarshallers = MarshallerHelpers.GetTopologicallySortedElements( + this._sortedMarshallers = MarshallerHelpers.GetTopologicallySortedElements( allMarshallers, static m => GetInfoIndex(m.TypeInfo), static m => GetInfoDependencies(m.TypeInfo)) @@ -214,7 +214,7 @@ public BlockSyntax GeneratePInvokeBody(string dllImportName) { var setupStatements = new List(); - foreach (var marshaller in paramMarshallers) + foreach (var marshaller in _paramMarshallers) { TypePositionInfo info = marshaller.TypeInfo; if (info.IsManagedReturnPosition) @@ -236,15 +236,15 @@ public BlockSyntax GeneratePInvokeBody(string dllImportName) AppendVariableDeclations(setupStatements, info, marshaller.Generator); } - bool invokeReturnsVoid = retMarshaller.TypeInfo.ManagedType == SpecialTypeInfo.Void; + bool invokeReturnsVoid = _retMarshaller.TypeInfo.ManagedType == SpecialTypeInfo.Void; // Stub return is not the same as invoke return - if (!stubReturnsVoid && !retMarshaller.TypeInfo.IsManagedReturnPosition) + if (!_stubReturnsVoid && !_retMarshaller.TypeInfo.IsManagedReturnPosition) { // Stub return should be the last parameter for the invoke - Debug.Assert(paramMarshallers.Any() && paramMarshallers.Last().TypeInfo.IsManagedReturnPosition, "Expected stub return to be the last parameter for the invoke"); + Debug.Assert(_paramMarshallers.Any() && _paramMarshallers.Last().TypeInfo.IsManagedReturnPosition, "Expected stub return to be the last parameter for the invoke"); - (TypePositionInfo stubRetTypeInfo, IMarshallingGenerator stubRetGenerator) = paramMarshallers.Last(); + (TypePositionInfo stubRetTypeInfo, IMarshallingGenerator stubRetGenerator) = _paramMarshallers.Last(); // Declare variables for stub return value AppendVariableDeclations(setupStatements, stubRetTypeInfo, stubRetGenerator); @@ -253,12 +253,12 @@ public BlockSyntax GeneratePInvokeBody(string dllImportName) if (!invokeReturnsVoid) { // Declare variables for invoke return value - AppendVariableDeclations(setupStatements, retMarshaller.TypeInfo, retMarshaller.Generator); + AppendVariableDeclations(setupStatements, _retMarshaller.TypeInfo, _retMarshaller.Generator); } // Do not manually handle SetLastError when generating forwarders. // We want the runtime to handle everything. - if (this.setLastError) + if (this._setLastError) { // Declare variable for last error setupStatements.Add(MarshallerHelpers.DeclareWithDefault( @@ -304,7 +304,7 @@ public BlockSyntax GeneratePInvokeBody(string dllImportName) allStatements.AddRange(tryStatements); } - if (this.setLastError) + if (this._setLastError) { // Marshal.SetLastPInvokeError(); allStatements.Add(ExpressionStatement( @@ -318,7 +318,7 @@ public BlockSyntax GeneratePInvokeBody(string dllImportName) } // Return - if (!stubReturnsVoid) + if (!_stubReturnsVoid) allStatements.Add(ReturnStatement(IdentifierName(ReturnIdentifier))); // Wrap all statements in an unsafe block @@ -331,7 +331,7 @@ void GenerateStatementsForStage(Stage stage, List statementsToU if (!invokeReturnsVoid && (stage is Stage.Setup or Stage.Cleanup)) { - var retStatements = retMarshaller.Generator.Generate(retMarshaller.TypeInfo, this); + var retStatements = _retMarshaller.Generator.Generate(_retMarshaller.TypeInfo, this); statementsToUpdate.AddRange(retStatements); } @@ -340,7 +340,7 @@ void GenerateStatementsForStage(Stage stage, List statementsToU // For Unmarshal and GuaranteedUnmarshal stages, use the topologically sorted // marshaller list to generate the marshalling statements - foreach (var marshaller in sortedMarshallers) + foreach (var marshaller in _sortedMarshallers) { statementsToUpdate.AddRange(marshaller.Generator.Generate(marshaller.TypeInfo, this)); } @@ -348,7 +348,7 @@ void GenerateStatementsForStage(Stage stage, List statementsToU else { // Generate code for each parameter for the current stage in declaration order. - foreach (var marshaller in paramMarshallers) + foreach (var marshaller in _paramMarshallers) { var generatedStatements = marshaller.Generator.Generate(marshaller.TypeInfo, this); statementsToUpdate.AddRange(generatedStatements); @@ -373,7 +373,7 @@ void GenerateStatementsForInvoke(List statementsToUpdate, Invoc var fixedStatements = new List(); this.CurrentStage = Stage.Pin; // Generate code for each parameter for the current stage - foreach (var marshaller in paramMarshallers) + foreach (var marshaller in _paramMarshallers) { var generatedStatements = marshaller.Generator.Generate(marshaller.TypeInfo, this); // Collect all the fixed statements. These will be used in the Invoke stage. @@ -388,7 +388,7 @@ void GenerateStatementsForInvoke(List statementsToUpdate, Invoc this.CurrentStage = Stage.Invoke; // Generate code for each parameter for the current stage - foreach (var marshaller in paramMarshallers) + foreach (var marshaller in _paramMarshallers) { // Get arguments for invocation ArgumentSyntax argSyntax = marshaller.Generator.AsArgument(marshaller.TypeInfo, this); @@ -406,13 +406,13 @@ void GenerateStatementsForInvoke(List statementsToUpdate, Invoc invokeStatement = ExpressionStatement( AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, - IdentifierName(this.GetIdentifiers(retMarshaller.TypeInfo).native), + IdentifierName(this.GetIdentifiers(_retMarshaller.TypeInfo).native), invoke)); } // Do not manually handle SetLastError when generating forwarders. // We want the runtime to handle everything. - if (setLastError) + if (_setLastError) { // Marshal.SetLastSystemError(0); var clearLastError = ExpressionStatement( @@ -464,10 +464,10 @@ void GenerateStatementsForInvoke(List statementsToUpdate, Invoc return ( ParameterList( SeparatedList( - paramMarshallers.Select(marshaler => marshaler.Generator.AsParameter(marshaler.TypeInfo)))), - retMarshaller.Generator.AsNativeType(retMarshaller.TypeInfo), - retMarshaller.Generator is IAttributedReturnTypeMarshallingGenerator attributedReturn - ? attributedReturn.GenerateAttributesForReturnType(retMarshaller.TypeInfo) + _paramMarshallers.Select(marshaler => marshaler.Generator.AsParameter(marshaler.TypeInfo)))), + _retMarshaller.Generator.AsNativeType(_retMarshaller.TypeInfo), + _retMarshaller.Generator is IAttributedReturnTypeMarshallingGenerator attributedReturn + ? attributedReturn.GenerateAttributesForReturnType(_retMarshaller.TypeInfo) : null ); } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContiguousCollectionElementMarshallingCodeContext.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContiguousCollectionElementMarshallingCodeContext.cs index 01d8d2f45e921..67e7c37831523 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContiguousCollectionElementMarshallingCodeContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContiguousCollectionElementMarshallingCodeContext.cs @@ -15,7 +15,7 @@ namespace Microsoft.Interop { internal sealed class ContiguousCollectionElementMarshallingCodeContext : StubCodeContext { - private readonly string nativeSpanIdentifier; + private readonly string _nativeSpanIdentifier; public override bool SingleFrameSpansNativeContext => false; @@ -37,7 +37,7 @@ public ContiguousCollectionElementMarshallingCodeContext( { CurrentStage = currentStage; IndexerIdentifier = CalculateIndexerIdentifierBasedOnParentContext(parentContext); - this.nativeSpanIdentifier = nativeSpanIdentifier; + this._nativeSpanIdentifier = nativeSpanIdentifier; ParentContext = parentContext; } @@ -51,13 +51,13 @@ public override (string managed, string native) GetIdentifiers(TypePositionInfo var (_, native) = ParentContext!.GetIdentifiers(info); return ( $"{native}.ManagedValues[{IndexerIdentifier}]", - $"{nativeSpanIdentifier}[{IndexerIdentifier}]" + $"{_nativeSpanIdentifier}[{IndexerIdentifier}]" ); } public override string GetAdditionalIdentifier(TypePositionInfo info, string name) { - return $"{nativeSpanIdentifier}__{IndexerIdentifier}__{name}"; + return $"{_nativeSpanIdentifier}__{IndexerIdentifier}__{name}"; } private static string CalculateIndexerIdentifierBasedOnParentContext(StubCodeContext? parentContext) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs index 566c81dd550bd..ee39b97247883 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs @@ -11,17 +11,17 @@ namespace Microsoft.Interop { public sealed class ArrayMarshaller : IMarshallingGenerator { - private readonly IMarshallingGenerator manualMarshallingGenerator; - private readonly TypeSyntax elementType; - private readonly bool enablePinning; - private readonly InteropGenerationOptions options; + private readonly IMarshallingGenerator _manualMarshallingGenerator; + private readonly TypeSyntax _elementType; + private readonly bool _enablePinning; + private readonly InteropGenerationOptions _options; public ArrayMarshaller(IMarshallingGenerator manualMarshallingGenerator, TypeSyntax elementType, bool enablePinning, InteropGenerationOptions options) { - this.manualMarshallingGenerator = manualMarshallingGenerator; - this.elementType = elementType; - this.enablePinning = enablePinning; - this.options = options; + this._manualMarshallingGenerator = manualMarshallingGenerator; + this._elementType = elementType; + this._enablePinning = enablePinning; + this._options = options; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -31,17 +31,17 @@ public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) string identifier = context.GetIdentifiers(info).native; return Argument(CastExpression(AsNativeType(info), IdentifierName(identifier))); } - return manualMarshallingGenerator.AsArgument(info, context); + return _manualMarshallingGenerator.AsArgument(info, context); } public TypeSyntax AsNativeType(TypePositionInfo info) { - return manualMarshallingGenerator.AsNativeType(info); + return _manualMarshallingGenerator.AsNativeType(info); } public ParameterSyntax AsParameter(TypePositionInfo info) { - return manualMarshallingGenerator.AsParameter(info); + return _manualMarshallingGenerator.AsParameter(info); } public IEnumerable Generate(TypePositionInfo info, StubCodeContext context) @@ -50,12 +50,12 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont { return GeneratePinningPath(info, context); } - return manualMarshallingGenerator.Generate(info, context); + return _manualMarshallingGenerator.Generate(info, context); } public bool SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) { - if (context.SingleFrameSpansNativeContext && enablePinning) + if (context.SingleFrameSpansNativeContext && _enablePinning) { return false; } @@ -68,19 +68,19 @@ public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) { return false; } - return manualMarshallingGenerator.UsesNativeIdentifier(info, context); + return _manualMarshallingGenerator.UsesNativeIdentifier(info, context); } private bool IsPinningPathSupported(TypePositionInfo info, StubCodeContext context) { - return context.SingleFrameSpansNativeContext && enablePinning && !info.IsByRef && !info.IsManagedReturnPosition; + return context.SingleFrameSpansNativeContext && _enablePinning && !info.IsByRef && !info.IsManagedReturnPosition; } private IEnumerable GeneratePinningPath(TypePositionInfo info, StubCodeContext context) { var (managedIdentifer, nativeIdentifier) = context.GetIdentifiers(info); string byRefIdentifier = $"__byref_{managedIdentifer}"; - TypeSyntax arrayElementType = elementType; + TypeSyntax arrayElementType = _elementType; if (context.CurrentStage == StubCodeContext.Stage.Marshal) { // [COMPAT] We use explicit byref calculations here instead of just using a fixed statement @@ -133,7 +133,7 @@ private IEnumerable GeneratePinningPath(TypePositionInfo info, PrefixUnaryExpression(SyntaxKind.AddressOfExpression, InvocationExpression( MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, - ParseTypeName(TypeNames.Unsafe(options)), + ParseTypeName(TypeNames.Unsafe(_options)), GenericName("As").AddTypeArgumentListArguments( arrayElementType, PredefinedType(Token(SyntaxKind.ByteKeyword))))) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs index 277fbe6d6d31f..20b40426a75a5 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs @@ -14,15 +14,15 @@ namespace Microsoft.Interop { public class AttributedMarshallingModelGeneratorFactory : IMarshallingGeneratorFactory { - private static readonly BlittableMarshaller Blittable = new BlittableMarshaller(); - private static readonly Forwarder Forwarder = new Forwarder(); + private static readonly BlittableMarshaller s_blittable = new BlittableMarshaller(); + private static readonly Forwarder s_forwarder = new Forwarder(); - private readonly IMarshallingGeneratorFactory innerMarshallingGenerator; + private readonly IMarshallingGeneratorFactory _innerMarshallingGenerator; public AttributedMarshallingModelGeneratorFactory(IMarshallingGeneratorFactory innerMarshallingGenerator, InteropGenerationOptions options) { Options = options; - this.innerMarshallingGenerator = innerMarshallingGenerator; + this._innerMarshallingGenerator = innerMarshallingGenerator; ElementMarshallingGeneratorFactory = this; } @@ -39,9 +39,9 @@ public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext conte return info.MarshallingAttributeInfo switch { NativeMarshallingAttributeInfo marshalInfo => CreateCustomNativeTypeMarshaller(info, context, marshalInfo), - BlittableTypeAttributeInfo => Blittable, - GeneratedNativeMarshallingAttributeInfo => Forwarder, - _ => innerMarshallingGenerator.Create(info, context) + BlittableTypeAttributeInfo => s_blittable, + GeneratedNativeMarshallingAttributeInfo => s_forwarder, + _ => _innerMarshallingGenerator.Create(info, context) }; } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs index 909b261f886c3..fdc572d451bb4 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs @@ -12,16 +12,16 @@ namespace Microsoft.Interop /// public class ByValueContentsMarshalKindValidator : IMarshallingGeneratorFactory { - private readonly IMarshallingGeneratorFactory inner; + private readonly IMarshallingGeneratorFactory _inner; public ByValueContentsMarshalKindValidator(IMarshallingGeneratorFactory inner) { - this.inner = inner; + this._inner = inner; } public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) { - return ValidateByValueMarshalKind(info, context, inner.Create(info, context)); + return ValidateByValueMarshalKind(info, context, _inner.Create(info, context)); } private static IMarshallingGenerator ValidateByValueMarshalKind(TypePositionInfo info, StubCodeContext context, IMarshallingGenerator generator) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshaller.cs index fe77d1aba9266..466b715e80c6a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CharMarshaller.cs @@ -14,7 +14,7 @@ namespace Microsoft.Interop { public sealed class Utf16CharMarshaller : IMarshallingGenerator { - private static readonly PredefinedTypeSyntax NativeType = PredefinedType(Token(SyntaxKind.UShortKeyword)); + private static readonly PredefinedTypeSyntax s_nativeType = PredefinedType(Token(SyntaxKind.UShortKeyword)); public Utf16CharMarshaller() { @@ -50,7 +50,7 @@ public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) public TypeSyntax AsNativeType(TypePositionInfo info) { Debug.Assert(info.ManagedType is SpecialTypeInfo(_, _, SpecialType.System_Char)); - return NativeType; + return s_nativeType; } public ParameterSyntax AsParameter(TypePositionInfo info) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomNativeTypeMarshallingGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomNativeTypeMarshallingGenerator.cs index 0859c4bf54d96..70efa90b99992 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomNativeTypeMarshallingGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomNativeTypeMarshallingGenerator.cs @@ -14,23 +14,23 @@ namespace Microsoft.Interop /// internal sealed class CustomNativeTypeMarshallingGenerator : IMarshallingGenerator { - private readonly ICustomNativeTypeMarshallingStrategy nativeTypeMarshaller; - private readonly bool enableByValueContentsMarshalling; + private readonly ICustomNativeTypeMarshallingStrategy _nativeTypeMarshaller; + private readonly bool _enableByValueContentsMarshalling; public CustomNativeTypeMarshallingGenerator(ICustomNativeTypeMarshallingStrategy nativeTypeMarshaller, bool enableByValueContentsMarshalling) { - this.nativeTypeMarshaller = nativeTypeMarshaller; - this.enableByValueContentsMarshalling = enableByValueContentsMarshalling; + this._nativeTypeMarshaller = nativeTypeMarshaller; + this._enableByValueContentsMarshalling = enableByValueContentsMarshalling; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { - return nativeTypeMarshaller.AsArgument(info, context); + return _nativeTypeMarshaller.AsArgument(info, context); } public TypeSyntax AsNativeType(TypePositionInfo info) { - return nativeTypeMarshaller.AsNativeType(info); + return _nativeTypeMarshaller.AsNativeType(info); } public ParameterSyntax AsParameter(TypePositionInfo info) @@ -49,28 +49,28 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont switch (context.CurrentStage) { case StubCodeContext.Stage.Setup: - return nativeTypeMarshaller.GenerateSetupStatements(info, context); + return _nativeTypeMarshaller.GenerateSetupStatements(info, context); case StubCodeContext.Stage.Marshal: if (!info.IsManagedReturnPosition && info.RefKind != RefKind.Out) { - return nativeTypeMarshaller.GenerateMarshalStatements(info, context, nativeTypeMarshaller.GetNativeTypeConstructorArguments(info, context)); + return _nativeTypeMarshaller.GenerateMarshalStatements(info, context, _nativeTypeMarshaller.GetNativeTypeConstructorArguments(info, context)); } break; case StubCodeContext.Stage.Pin: if (!info.IsByRef || info.RefKind == RefKind.In) { - return nativeTypeMarshaller.GeneratePinStatements(info, context); + return _nativeTypeMarshaller.GeneratePinStatements(info, context); } break; case StubCodeContext.Stage.Unmarshal: if (info.IsManagedReturnPosition || (info.IsByRef && info.RefKind != RefKind.In) - || (enableByValueContentsMarshalling && !info.IsByRef && info.ByValueContentsMarshalKind.HasFlag(ByValueContentsMarshalKind.Out))) + || (_enableByValueContentsMarshalling && !info.IsByRef && info.ByValueContentsMarshalKind.HasFlag(ByValueContentsMarshalKind.Out))) { - return nativeTypeMarshaller.GenerateUnmarshalStatements(info, context); + return _nativeTypeMarshaller.GenerateUnmarshalStatements(info, context); } break; case StubCodeContext.Stage.Cleanup: - return nativeTypeMarshaller.GenerateCleanupStatements(info, context); + return _nativeTypeMarshaller.GenerateCleanupStatements(info, context); default: break; } @@ -80,12 +80,12 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont public bool SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) { - return enableByValueContentsMarshalling; + return _enableByValueContentsMarshalling; } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) { - return nativeTypeMarshaller.UsesNativeIdentifier(info, context); + return _nativeTypeMarshaller.UsesNativeIdentifier(info, context); } } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/HResultExceptionMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/HResultExceptionMarshaller.cs index 2b97467a8fd6a..446750e2bc5ca 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/HResultExceptionMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/HResultExceptionMarshaller.cs @@ -14,12 +14,12 @@ namespace Microsoft.Interop { public sealed class HResultExceptionMarshaller : IMarshallingGenerator { - private static readonly TypeSyntax NativeType = PredefinedType(Token(SyntaxKind.IntKeyword)); + private static readonly TypeSyntax s_nativeType = PredefinedType(Token(SyntaxKind.IntKeyword)); public TypeSyntax AsNativeType(TypePositionInfo info) { Debug.Assert(info.ManagedType is SpecialTypeInfo(_, _, SpecialType.System_Int32)); - return NativeType; + return s_nativeType; } // Should only be used for return value diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomNativeTypeMarshallingStrategy.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomNativeTypeMarshallingStrategy.cs index 917a2a55cf735..bbd8ae15875ae 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomNativeTypeMarshallingStrategy.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomNativeTypeMarshallingStrategy.cs @@ -41,11 +41,11 @@ internal interface ICustomNativeTypeMarshallingStrategy /// internal sealed class SimpleCustomNativeTypeMarshalling : ICustomNativeTypeMarshallingStrategy { - private readonly TypeSyntax nativeTypeSyntax; + private readonly TypeSyntax _nativeTypeSyntax; public SimpleCustomNativeTypeMarshalling(TypeSyntax nativeTypeSyntax) { - this.nativeTypeSyntax = nativeTypeSyntax; + this._nativeTypeSyntax = nativeTypeSyntax; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -64,7 +64,7 @@ public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) public TypeSyntax AsNativeType(TypePositionInfo info) { - return nativeTypeSyntax; + return _nativeTypeSyntax; } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) @@ -151,13 +151,13 @@ public override (string managed, string native) GetIdentifiers(TypePositionInfo /// internal sealed class CustomNativeTypeWithValuePropertyMarshalling : ICustomNativeTypeMarshallingStrategy { - private readonly ICustomNativeTypeMarshallingStrategy innerMarshaller; - private readonly TypeSyntax valuePropertyType; + private readonly ICustomNativeTypeMarshallingStrategy _innerMarshaller; + private readonly TypeSyntax _valuePropertyType; public CustomNativeTypeWithValuePropertyMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller, TypeSyntax valuePropertyType) { - this.innerMarshaller = innerMarshaller; - this.valuePropertyType = valuePropertyType; + this._innerMarshaller = innerMarshaller; + this._valuePropertyType = valuePropertyType; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -176,7 +176,7 @@ public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) public TypeSyntax AsNativeType(TypePositionInfo info) { - return valuePropertyType; + return _valuePropertyType; } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) @@ -196,7 +196,7 @@ public IEnumerable GenerateCleanupStatements(TypePositionInfo i yield return GenerateValuePropertyAssignment(info, context, subContext); } - foreach (var statement in innerMarshaller.GenerateCleanupStatements(info, subContext)) + foreach (var statement in _innerMarshaller.GenerateCleanupStatements(info, subContext)) { yield return statement; } @@ -205,7 +205,7 @@ public IEnumerable GenerateCleanupStatements(TypePositionInfo i public IEnumerable GenerateMarshalStatements(TypePositionInfo info, StubCodeContext context, IEnumerable nativeTypeConstructorArguments) { var subContext = new CustomNativeTypeWithValuePropertyStubContext(context); - foreach (var statement in innerMarshaller.GenerateMarshalStatements(info, subContext, nativeTypeConstructorArguments)) + foreach (var statement in _innerMarshaller.GenerateMarshalStatements(info, subContext, nativeTypeConstructorArguments)) { yield return statement; } @@ -238,7 +238,7 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo yield return GenerateValuePropertyAssignment(info, context, subContext); - foreach (var statement in innerMarshaller.GenerateUnmarshalStatements(info, subContext)) + foreach (var statement in _innerMarshaller.GenerateUnmarshalStatements(info, subContext)) { yield return statement; } @@ -247,7 +247,7 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo public IEnumerable GetNativeTypeConstructorArguments(TypePositionInfo info, StubCodeContext context) { var subContext = new CustomNativeTypeWithValuePropertyStubContext(context); - return innerMarshaller.GetNativeTypeConstructorArguments(info, subContext); + return _innerMarshaller.GetNativeTypeConstructorArguments(info, subContext); } public IEnumerable GenerateSetupStatements(TypePositionInfo info, StubCodeContext context) @@ -255,12 +255,12 @@ public IEnumerable GenerateSetupStatements(TypePositionInfo inf var subContext = new CustomNativeTypeWithValuePropertyStubContext(context); yield return LocalDeclarationStatement( VariableDeclaration( - innerMarshaller.AsNativeType(info), + _innerMarshaller.AsNativeType(info), SingletonSeparatedList( VariableDeclarator(subContext.GetIdentifiers(info).native) .WithInitializer(EqualsValueClause(LiteralExpression(SyntaxKind.DefaultLiteralExpression)))))); - foreach (var statement in innerMarshaller.GenerateSetupStatements(info, subContext)) + foreach (var statement in _innerMarshaller.GenerateSetupStatements(info, subContext)) { yield return statement; } @@ -269,7 +269,7 @@ public IEnumerable GenerateSetupStatements(TypePositionInfo inf public IEnumerable GeneratePinStatements(TypePositionInfo info, StubCodeContext context) { var subContext = new CustomNativeTypeWithValuePropertyStubContext(context); - return innerMarshaller.GeneratePinStatements(info, subContext); + return _innerMarshaller.GeneratePinStatements(info, subContext); } } @@ -278,26 +278,26 @@ public IEnumerable GeneratePinStatements(TypePositionInfo info, /// internal sealed class StackallocOptimizationMarshalling : ICustomNativeTypeMarshallingStrategy { - private readonly ICustomNativeTypeMarshallingStrategy innerMarshaller; + private readonly ICustomNativeTypeMarshallingStrategy _innerMarshaller; public StackallocOptimizationMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller) { - this.innerMarshaller = innerMarshaller; + this._innerMarshaller = innerMarshaller; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.AsArgument(info, context); + return _innerMarshaller.AsArgument(info, context); } public TypeSyntax AsNativeType(TypePositionInfo info) { - return innerMarshaller.AsNativeType(info); + return _innerMarshaller.AsNativeType(info); } public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GenerateCleanupStatements(info, context); + return _innerMarshaller.GenerateCleanupStatements(info, context); } public IEnumerable GenerateMarshalStatements(TypePositionInfo info, StubCodeContext context, IEnumerable nativeTypeConstructorArguments) @@ -321,7 +321,7 @@ public IEnumerable GenerateMarshalStatements(TypePositionInfo i )))))))))); } - foreach (var statement in innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments)) + foreach (var statement in _innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments)) { yield return statement; } @@ -339,22 +339,22 @@ private static string GetStackAllocPointerIdentifier(TypePositionInfo info, Stub public IEnumerable GeneratePinStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GeneratePinStatements(info, context); + return _innerMarshaller.GeneratePinStatements(info, context); } public IEnumerable GenerateSetupStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GenerateSetupStatements(info, context); + return _innerMarshaller.GenerateSetupStatements(info, context); } public IEnumerable GenerateUnmarshalStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GenerateUnmarshalStatements(info, context); + return _innerMarshaller.GenerateUnmarshalStatements(info, context); } public IEnumerable GetNativeTypeConstructorArguments(TypePositionInfo info, StubCodeContext context) { - foreach (var arg in innerMarshaller.GetNativeTypeConstructorArguments(info, context)) + foreach (var arg in _innerMarshaller.GetNativeTypeConstructorArguments(info, context)) { yield return arg; } @@ -378,7 +378,7 @@ public IEnumerable GetNativeTypeConstructorArguments(TypePositio public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.UsesNativeIdentifier(info, context); + return _innerMarshaller.UsesNativeIdentifier(info, context); } } @@ -387,26 +387,26 @@ public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) /// internal sealed class FreeNativeCleanupStrategy : ICustomNativeTypeMarshallingStrategy { - private readonly ICustomNativeTypeMarshallingStrategy innerMarshaller; + private readonly ICustomNativeTypeMarshallingStrategy _innerMarshaller; public FreeNativeCleanupStrategy(ICustomNativeTypeMarshallingStrategy innerMarshaller) { - this.innerMarshaller = innerMarshaller; + this._innerMarshaller = innerMarshaller; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.AsArgument(info, context); + return _innerMarshaller.AsArgument(info, context); } public TypeSyntax AsNativeType(TypePositionInfo info) { - return innerMarshaller.AsNativeType(info); + return _innerMarshaller.AsNativeType(info); } public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) { - foreach (var statement in innerMarshaller.GenerateCleanupStatements(info, context)) + foreach (var statement in _innerMarshaller.GenerateCleanupStatements(info, context)) { yield return statement; } @@ -421,32 +421,32 @@ public IEnumerable GenerateCleanupStatements(TypePositionInfo i public IEnumerable GenerateMarshalStatements(TypePositionInfo info, StubCodeContext context, IEnumerable nativeTypeConstructorArguments) { - return innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments); + return _innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments); } public IEnumerable GeneratePinStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GeneratePinStatements(info, context); + return _innerMarshaller.GeneratePinStatements(info, context); } public IEnumerable GenerateSetupStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GenerateSetupStatements(info, context); + return _innerMarshaller.GenerateSetupStatements(info, context); } public IEnumerable GenerateUnmarshalStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GenerateUnmarshalStatements(info, context); + return _innerMarshaller.GenerateUnmarshalStatements(info, context); } public IEnumerable GetNativeTypeConstructorArguments(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GetNativeTypeConstructorArguments(info, context); + return _innerMarshaller.GetNativeTypeConstructorArguments(info, context); } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.UsesNativeIdentifier(info, context); + return _innerMarshaller.UsesNativeIdentifier(info, context); } } @@ -455,13 +455,13 @@ public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) /// internal sealed class PinnableMarshallerTypeMarshalling : ICustomNativeTypeMarshallingStrategy { - private readonly ICustomNativeTypeMarshallingStrategy innerMarshaller; - private readonly TypeSyntax valuePropertyType; + private readonly ICustomNativeTypeMarshallingStrategy _innerMarshaller; + private readonly TypeSyntax _valuePropertyType; public PinnableMarshallerTypeMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller, TypeSyntax valuePropertyType) { - this.innerMarshaller = innerMarshaller; - this.valuePropertyType = valuePropertyType; + this._innerMarshaller = innerMarshaller; + this._valuePropertyType = valuePropertyType; } private bool CanPinMarshaller(TypePositionInfo info, StubCodeContext context) @@ -471,12 +471,12 @@ private bool CanPinMarshaller(TypePositionInfo info, StubCodeContext context) public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.AsArgument(info, context); + return _innerMarshaller.AsArgument(info, context); } public TypeSyntax AsNativeType(TypePositionInfo info) { - return valuePropertyType; + return _valuePropertyType; } public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) @@ -489,7 +489,7 @@ public IEnumerable GenerateCleanupStatements(TypePositionInfo i yield return GenerateValuePropertyAssignment(info, context, subContext); } - foreach (var statement in innerMarshaller.GenerateCleanupStatements(info, subContext)) + foreach (var statement in _innerMarshaller.GenerateCleanupStatements(info, subContext)) { yield return statement; } @@ -498,7 +498,7 @@ public IEnumerable GenerateCleanupStatements(TypePositionInfo i public IEnumerable GenerateMarshalStatements(TypePositionInfo info, StubCodeContext context, IEnumerable nativeTypeConstructorArguments) { var subContext = new CustomNativeTypeWithValuePropertyStubContext(context); - foreach (var statement in innerMarshaller.GenerateMarshalStatements(info, subContext, nativeTypeConstructorArguments)) + foreach (var statement in _innerMarshaller.GenerateMarshalStatements(info, subContext, nativeTypeConstructorArguments)) { yield return statement; } @@ -522,7 +522,7 @@ public IEnumerable GeneratePinStatements(TypePositionInfo info, var subContext = new CustomNativeTypeWithValuePropertyStubContext(context); yield return FixedStatement( VariableDeclaration( - valuePropertyType, + _valuePropertyType, SingletonSeparatedList( VariableDeclarator(context.GetIdentifiers(info).native) .WithInitializer(EqualsValueClause( @@ -540,12 +540,12 @@ public IEnumerable GenerateSetupStatements(TypePositionInfo inf var subContext = new CustomNativeTypeWithValuePropertyStubContext(context); yield return LocalDeclarationStatement( VariableDeclaration( - innerMarshaller.AsNativeType(info), + _innerMarshaller.AsNativeType(info), SingletonSeparatedList( VariableDeclarator(subContext.GetIdentifiers(info).native) .WithInitializer(EqualsValueClause(LiteralExpression(SyntaxKind.DefaultLiteralExpression)))))); - foreach (var statement in innerMarshaller.GenerateSetupStatements(info, subContext)) + foreach (var statement in _innerMarshaller.GenerateSetupStatements(info, subContext)) { yield return statement; } @@ -573,7 +573,7 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo yield return GenerateValuePropertyAssignment(info, context, subContext); } - foreach (var statement in innerMarshaller.GenerateUnmarshalStatements(info, subContext)) + foreach (var statement in _innerMarshaller.GenerateUnmarshalStatements(info, subContext)) { yield return statement; } @@ -582,7 +582,7 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo public IEnumerable GetNativeTypeConstructorArguments(TypePositionInfo info, StubCodeContext context) { var subContext = new CustomNativeTypeWithValuePropertyStubContext(context); - return innerMarshaller.GetNativeTypeConstructorArguments(info, subContext); + return _innerMarshaller.GetNativeTypeConstructorArguments(info, subContext); } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) @@ -591,7 +591,7 @@ public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) { return false; } - return innerMarshaller.UsesNativeIdentifier(info, context); + return _innerMarshaller.UsesNativeIdentifier(info, context); } } @@ -600,25 +600,25 @@ public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) /// internal sealed class NumElementsExpressionMarshalling : ICustomNativeTypeMarshallingStrategy { - private readonly ICustomNativeTypeMarshallingStrategy innerMarshaller; - private readonly ExpressionSyntax numElementsExpression; - private readonly ExpressionSyntax sizeOfElementExpression; + private readonly ICustomNativeTypeMarshallingStrategy _innerMarshaller; + private readonly ExpressionSyntax _numElementsExpression; + private readonly ExpressionSyntax _sizeOfElementExpression; public NumElementsExpressionMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller, ExpressionSyntax numElementsExpression, ExpressionSyntax sizeOfElementExpression) { - this.innerMarshaller = innerMarshaller; - this.numElementsExpression = numElementsExpression; - this.sizeOfElementExpression = sizeOfElementExpression; + this._innerMarshaller = innerMarshaller; + this._numElementsExpression = numElementsExpression; + this._sizeOfElementExpression = sizeOfElementExpression; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.AsArgument(info, context); + return _innerMarshaller.AsArgument(info, context); } public TypeSyntax AsNativeType(TypePositionInfo info) { - return innerMarshaller.AsNativeType(info); + return _innerMarshaller.AsNativeType(info); } public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) @@ -634,7 +634,7 @@ public IEnumerable GenerateCleanupStatements(TypePositionInfo i } } - foreach (var statement in innerMarshaller.GenerateCleanupStatements(info, context)) + foreach (var statement in _innerMarshaller.GenerateCleanupStatements(info, context)) { yield return statement; } @@ -642,17 +642,17 @@ public IEnumerable GenerateCleanupStatements(TypePositionInfo i public IEnumerable GenerateMarshalStatements(TypePositionInfo info, StubCodeContext context, IEnumerable nativeTypeConstructorArguments) { - return innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments); + return _innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments); } public IEnumerable GeneratePinStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GeneratePinStatements(info, context); + return _innerMarshaller.GeneratePinStatements(info, context); } public IEnumerable GenerateSetupStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GenerateSetupStatements(info, context); + return _innerMarshaller.GenerateSetupStatements(info, context); } private IEnumerable GenerateUnmarshallerCollectionInitialization(TypePositionInfo info, StubCodeContext context) @@ -662,7 +662,7 @@ private IEnumerable GenerateUnmarshallerCollectionInitializatio { yield return ExpressionStatement(AssignmentExpression(SyntaxKind.SimpleAssignmentExpression, IdentifierName(marshalerIdentifier), - ImplicitObjectCreationExpression().AddArgumentListArguments(Argument(sizeOfElementExpression)))); + ImplicitObjectCreationExpression().AddArgumentListArguments(Argument(_sizeOfElementExpression)))); } if (info.IsByRef || !info.ByValueContentsMarshalKind.HasFlag(ByValueContentsMarshalKind.Out)) @@ -673,7 +673,7 @@ private IEnumerable GenerateUnmarshallerCollectionInitializatio SyntaxKind.SimpleMemberAccessExpression, IdentifierName(marshalerIdentifier), IdentifierName(ManualTypeMarshallingHelper.SetUnmarshalledCollectionLengthMethodName))) - .AddArgumentListArguments(Argument(numElementsExpression))); + .AddArgumentListArguments(Argument(_numElementsExpression))); } } @@ -689,7 +689,7 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo yield return statement; } - foreach (var statement in innerMarshaller.GenerateUnmarshalStatements(info, context)) + foreach (var statement in _innerMarshaller.GenerateUnmarshalStatements(info, context)) { yield return statement; } @@ -697,16 +697,16 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo public IEnumerable GetNativeTypeConstructorArguments(TypePositionInfo info, StubCodeContext context) { - foreach (var arg in innerMarshaller.GetNativeTypeConstructorArguments(info, context)) + foreach (var arg in _innerMarshaller.GetNativeTypeConstructorArguments(info, context)) { yield return arg; } - yield return Argument(sizeOfElementExpression); + yield return Argument(_sizeOfElementExpression); } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.UsesNativeIdentifier(info, context); + return _innerMarshaller.UsesNativeIdentifier(info, context); } } @@ -715,34 +715,34 @@ public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) /// internal sealed class ContiguousBlittableElementCollectionMarshalling : ICustomNativeTypeMarshallingStrategy { - private readonly ICustomNativeTypeMarshallingStrategy innerMarshaller; - private readonly TypeSyntax elementType; + private readonly ICustomNativeTypeMarshallingStrategy _innerMarshaller; + private readonly TypeSyntax _elementType; public ContiguousBlittableElementCollectionMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller, TypeSyntax elementType) { - this.innerMarshaller = innerMarshaller; - this.elementType = elementType; + this._innerMarshaller = innerMarshaller; + this._elementType = elementType; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.AsArgument(info, context); + return _innerMarshaller.AsArgument(info, context); } public TypeSyntax AsNativeType(TypePositionInfo info) { - return innerMarshaller.AsNativeType(info); + return _innerMarshaller.AsNativeType(info); } public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GenerateCleanupStatements(info, context); + return _innerMarshaller.GenerateCleanupStatements(info, context); } public IEnumerable GenerateMarshalStatements(TypePositionInfo info, StubCodeContext context, IEnumerable nativeTypeConstructorArguments) { string nativeIdentifier = context.GetIdentifiers(info).native; - foreach (var statement in innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments)) + foreach (var statement in _innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments)) { yield return statement; } @@ -777,7 +777,7 @@ public IEnumerable GenerateMarshalStatements(TypePositionInfo i new[] { PredefinedType(Token(SyntaxKind.ByteKeyword)), - elementType + _elementType }))))) .AddArgumentListArguments( Argument( @@ -789,12 +789,12 @@ public IEnumerable GenerateMarshalStatements(TypePositionInfo i public IEnumerable GeneratePinStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GeneratePinStatements(info, context); + return _innerMarshaller.GeneratePinStatements(info, context); } public IEnumerable GenerateSetupStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GenerateSetupStatements(info, context); + return _innerMarshaller.GenerateSetupStatements(info, context); } public IEnumerable GenerateUnmarshalStatements(TypePositionInfo info, StubCodeContext context) @@ -817,7 +817,7 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo new[] { PredefinedType(Token(SyntaxKind.ByteKeyword)), - elementType + _elementType }))))) .AddArgumentListArguments( Argument( @@ -833,7 +833,7 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo IdentifierName(nativeIdentifier), IdentifierName(ManualTypeMarshallingHelper.ManagedValuesPropertyName))))); - foreach (var statement in innerMarshaller.GenerateUnmarshalStatements(info, context)) + foreach (var statement in _innerMarshaller.GenerateUnmarshalStatements(info, context)) { yield return statement; } @@ -841,12 +841,12 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo public IEnumerable GetNativeTypeConstructorArguments(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GetNativeTypeConstructorArguments(info, context); + return _innerMarshaller.GetNativeTypeConstructorArguments(info, context); } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.UsesNativeIdentifier(info, context); + return _innerMarshaller.UsesNativeIdentifier(info, context); } } @@ -855,17 +855,17 @@ public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) /// internal sealed class ContiguousNonBlittableElementCollectionMarshalling : ICustomNativeTypeMarshallingStrategy { - private readonly ICustomNativeTypeMarshallingStrategy innerMarshaller; - private readonly IMarshallingGenerator elementMarshaller; - private readonly TypePositionInfo elementInfo; + private readonly ICustomNativeTypeMarshallingStrategy _innerMarshaller; + private readonly IMarshallingGenerator _elementMarshaller; + private readonly TypePositionInfo _elementInfo; public ContiguousNonBlittableElementCollectionMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller, IMarshallingGenerator elementMarshaller, TypePositionInfo elementInfo) { - this.innerMarshaller = innerMarshaller; - this.elementMarshaller = elementMarshaller; - this.elementInfo = elementInfo; + this._innerMarshaller = innerMarshaller; + this._elementMarshaller = elementMarshaller; + this._elementInfo = elementInfo; } private LocalDeclarationStatementSyntax GenerateNativeSpanDeclaration(TypePositionInfo info, StubCodeContext context) @@ -876,7 +876,7 @@ private LocalDeclarationStatementSyntax GenerateNativeSpanDeclaration(TypePositi GenericName( Identifier(TypeNames.System_Span), TypeArgumentList( - SingletonSeparatedList(elementMarshaller.AsNativeType(elementInfo).GetCompatibleGenericTypeParameterSyntax())) + SingletonSeparatedList(_elementMarshaller.AsNativeType(_elementInfo).GetCompatibleGenericTypeParameterSyntax())) ), SingletonSeparatedList( VariableDeclarator(Identifier(nativeSpanIdentifier)) @@ -893,7 +893,7 @@ private LocalDeclarationStatementSyntax GenerateNativeSpanDeclaration(TypePositi new[] { PredefinedType(Token(SyntaxKind.ByteKeyword)), - elementMarshaller.AsNativeType(elementInfo).GetCompatibleGenericTypeParameterSyntax() + _elementMarshaller.AsNativeType(_elementInfo).GetCompatibleGenericTypeParameterSyntax() }))))) .AddArgumentListArguments( Argument(MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, @@ -918,7 +918,7 @@ private StatementSyntax GenerateContentsMarshallingStatement(TypePositionInfo in ? $"{nativeIdentifier}.{ManualTypeMarshallingHelper.ManagedValuesPropertyName}" : nativeSpanIdentifier; - TypePositionInfo localElementInfo = elementInfo with + TypePositionInfo localElementInfo = _elementInfo with { InstanceIdentifier = info.InstanceIdentifier, RefKind = info.IsByRef ? info.RefKind : info.ByValueContentsMarshalKind.GetRefKindForByValueContentsKind(), @@ -926,15 +926,15 @@ private StatementSyntax GenerateContentsMarshallingStatement(TypePositionInfo in NativeIndex = info.NativeIndex }; - List elementStatements = elementMarshaller.Generate(localElementInfo, elementSubContext).ToList(); + List elementStatements = _elementMarshaller.Generate(localElementInfo, elementSubContext).ToList(); if (elementStatements.Any()) { StatementSyntax marshallingStatement = Block( - List(elementMarshaller.Generate(localElementInfo, elementSetupSubContext) + List(_elementMarshaller.Generate(localElementInfo, elementSetupSubContext) .Concat(elementStatements))); - if (elementMarshaller.AsNativeType(elementInfo) is PointerTypeSyntax elementNativeType) + if (_elementMarshaller.AsNativeType(_elementInfo) is PointerTypeSyntax elementNativeType) { PointerNativeTypeAssignmentRewriter rewriter = new(elementSubContext.GetIdentifiers(localElementInfo).native, elementNativeType); marshallingStatement = (StatementSyntax)rewriter.Visit(marshallingStatement); @@ -951,18 +951,18 @@ private StatementSyntax GenerateContentsMarshallingStatement(TypePositionInfo in public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.AsArgument(info, context); + return _innerMarshaller.AsArgument(info, context); } public TypeSyntax AsNativeType(TypePositionInfo info) { - return innerMarshaller.AsNativeType(info); + return _innerMarshaller.AsNativeType(info); } public IEnumerable GenerateCleanupStatements(TypePositionInfo info, StubCodeContext context) { yield return GenerateContentsMarshallingStatement(info, context, useManagedSpanForLength: false); - foreach (var statement in innerMarshaller.GenerateCleanupStatements(info, context)) + foreach (var statement in _innerMarshaller.GenerateCleanupStatements(info, context)) { yield return statement; } @@ -970,7 +970,7 @@ public IEnumerable GenerateCleanupStatements(TypePositionInfo i public IEnumerable GenerateMarshalStatements(TypePositionInfo info, StubCodeContext context, IEnumerable nativeTypeConstructorArguments) { - foreach (var statement in innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments)) + foreach (var statement in _innerMarshaller.GenerateMarshalStatements(info, context, nativeTypeConstructorArguments)) { yield return statement; } @@ -986,18 +986,18 @@ public IEnumerable GenerateMarshalStatements(TypePositionInfo i public IEnumerable GeneratePinStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GeneratePinStatements(info, context); + return _innerMarshaller.GeneratePinStatements(info, context); } public IEnumerable GenerateSetupStatements(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GenerateSetupStatements(info, context); + return _innerMarshaller.GenerateSetupStatements(info, context); } public IEnumerable GenerateUnmarshalStatements(TypePositionInfo info, StubCodeContext context) { yield return GenerateContentsMarshallingStatement(info, context, useManagedSpanForLength: false); - foreach (var statement in innerMarshaller.GenerateUnmarshalStatements(info, context)) + foreach (var statement in _innerMarshaller.GenerateUnmarshalStatements(info, context)) { yield return statement; } @@ -1005,12 +1005,12 @@ public IEnumerable GenerateUnmarshalStatements(TypePositionInfo public IEnumerable GetNativeTypeConstructorArguments(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.GetNativeTypeConstructorArguments(info, context); + return _innerMarshaller.GetNativeTypeConstructorArguments(info, context); } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) { - return innerMarshaller.UsesNativeIdentifier(info, context); + return _innerMarshaller.UsesNativeIdentifier(info, context); } /// @@ -1020,25 +1020,25 @@ public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) /// private class PointerNativeTypeAssignmentRewriter : CSharpSyntaxRewriter { - private readonly string nativeIdentifier; - private readonly PointerTypeSyntax nativeType; + private readonly string _nativeIdentifier; + private readonly PointerTypeSyntax _nativeType; public PointerNativeTypeAssignmentRewriter(string nativeIdentifier, PointerTypeSyntax nativeType) { - this.nativeIdentifier = nativeIdentifier; - this.nativeType = nativeType; + this._nativeIdentifier = nativeIdentifier; + this._nativeType = nativeType; } public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax node) { - if (node.Left.ToString() == nativeIdentifier) + if (node.Left.ToString() == _nativeIdentifier) { return node.WithRight( CastExpression(MarshallerHelpers.SystemIntPtrType, node.Right)); } - if (node.Right.ToString() == nativeIdentifier) + if (node.Right.ToString() == _nativeIdentifier) { - return node.WithRight(CastExpression(nativeType, node.Right)); + return node.WithRight(CastExpression(_nativeType, node.Right)); } return node; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallerHelpers.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallerHelpers.cs index 1edc06838b6db..2adc953ce3c3a 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallerHelpers.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallerHelpers.cs @@ -192,12 +192,12 @@ public static IEnumerable GetTopologicallySortedElements( private struct EdgeMap { - private readonly bool[] edgeMap; + private readonly bool[] _edgeMap; public EdgeMap(int numNodes) { NodeCount = numNodes; - edgeMap = new bool[NodeCount * NodeCount]; + _edgeMap = new bool[NodeCount * NodeCount]; } /// @@ -209,17 +209,17 @@ public EdgeMap(int numNodes) /// If there exists an edge that starts at and ends at public bool this[int to, int from] { - get => edgeMap[to * NodeCount + from]; - set => edgeMap[to * NodeCount + from] = value; + get => _edgeMap[to * NodeCount + from]; + set => _edgeMap[to * NodeCount + from] = value; } - public bool AnyEdges => Array.IndexOf(edgeMap, true) != -1; + public bool AnyEdges => Array.IndexOf(_edgeMap, true) != -1; public int NodeCount { get; } public bool AnyIncomingEdge(int to) { - return Array.IndexOf(edgeMap, true, to * NodeCount, NodeCount) != -1; + return Array.IndexOf(_edgeMap, true, to * NodeCount, NodeCount) != -1; } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs index 6d17c99ae84e2..a2432f4cdf8ac 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs @@ -27,20 +27,20 @@ public IMarshallingGenerator Create( public sealed class DefaultMarshallingGeneratorFactory : IMarshallingGeneratorFactory { - private static readonly ByteBoolMarshaller ByteBool = new(); - private static readonly WinBoolMarshaller WinBool = new(); - private static readonly VariantBoolMarshaller VariantBool = new(); - - private static readonly Utf16CharMarshaller Utf16Char = new(); - private static readonly Utf16StringMarshaller Utf16String = new(); - private static readonly Utf8StringMarshaller Utf8String = new(); - private static readonly AnsiStringMarshaller AnsiString = new AnsiStringMarshaller(Utf8String); - private static readonly PlatformDefinedStringMarshaller PlatformDefinedString = new PlatformDefinedStringMarshaller(Utf16String, Utf8String); - - private static readonly Forwarder Forwarder = new(); - private static readonly BlittableMarshaller Blittable = new(); - private static readonly DelegateMarshaller Delegate = new(); - private static readonly SafeHandleMarshaller SafeHandle = new(); + private static readonly ByteBoolMarshaller s_byteBool = new(); + private static readonly WinBoolMarshaller s_winBool = new(); + private static readonly VariantBoolMarshaller s_variantBool = new(); + + private static readonly Utf16CharMarshaller s_utf16Char = new(); + private static readonly Utf16StringMarshaller s_utf16String = new(); + private static readonly Utf8StringMarshaller s_utf8String = new(); + private static readonly AnsiStringMarshaller s_ansiString = new AnsiStringMarshaller(s_utf8String); + private static readonly PlatformDefinedStringMarshaller s_platformDefinedString = new PlatformDefinedStringMarshaller(s_utf16String, s_utf8String); + + private static readonly Forwarder s_forwarder = new(); + private static readonly BlittableMarshaller s_blittable = new(); + private static readonly DelegateMarshaller s_delegate = new(); + private static readonly SafeHandleMarshaller s_safeHandle = new(); private InteropGenerationOptions Options { get; } public DefaultMarshallingGeneratorFactory(InteropGenerationOptions options) @@ -73,7 +73,7 @@ public IMarshallingGenerator Create( or { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_UIntPtr }, MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.SysUInt, _) } or { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Single }, MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.R4, _) } or { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Double }, MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.R8, _) }: - return Blittable; + return s_blittable; // Enum with no marshalling info case { ManagedType: EnumTypeInfo enumType, MarshallingAttributeInfo: NoMarshallingInfo }: @@ -83,27 +83,27 @@ public IMarshallingGenerator Create( { throw new MarshallingNotSupportedException(info, context); } - return Blittable; + return s_blittable; // Pointer with no marshalling info case { ManagedType: PointerTypeInfo(_, _, IsFunctionPointer: false), MarshallingAttributeInfo: NoMarshallingInfo }: - return Blittable; + return s_blittable; // Function pointer with no marshalling info case { ManagedType: PointerTypeInfo(_, _, IsFunctionPointer: true), MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.FunctionPtr, _) }: - return Blittable; + return s_blittable; case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Boolean }, MarshallingAttributeInfo: NoMarshallingInfo }: - return WinBool; // [Compat] Matching the default for the built-in runtime marshallers. + return s_winBool; // [Compat] Matching the default for the built-in runtime marshallers. case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Boolean }, MarshallingAttributeInfo: MarshalAsInfo(UnmanagedType.I1 or UnmanagedType.U1, _) }: - return ByteBool; + return s_byteBool; case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Boolean }, MarshallingAttributeInfo: MarshalAsInfo(UnmanagedType.I4 or UnmanagedType.U4 or UnmanagedType.Bool, _) }: - return WinBool; + return s_winBool; case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Boolean }, MarshallingAttributeInfo: MarshalAsInfo(UnmanagedType.VariantBool, _) }: - return VariantBool; + return s_variantBool; case { ManagedType: DelegateTypeInfo, MarshallingAttributeInfo: NoMarshallingInfo or MarshalAsInfo(UnmanagedType.FunctionPtr, _) }: - return Delegate; + return s_delegate; case { MarshallingAttributeInfo: SafeHandleMarshallingInfo(_, bool isAbstract) }: if (!context.AdditionalTemporaryStateLivesAcrossStages) @@ -117,7 +117,7 @@ public IMarshallingGenerator Create( NotSupportedDetails = Resources.SafeHandleByRefMustBeConcrete }; } - return SafeHandle; + return s_safeHandle; case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Char } }: return CreateCharMarshaller(info, context); @@ -126,7 +126,7 @@ public IMarshallingGenerator Create( return CreateStringMarshaller(info, context); case { ManagedType: SpecialTypeInfo { SpecialType: SpecialType.System_Void } }: - return Forwarder; + return s_forwarder; default: throw new MarshallingNotSupportedException(info, context); @@ -152,7 +152,7 @@ private IMarshallingGenerator CreateCharMarshaller(TypePositionInfo info, StubCo { case UnmanagedType.I2: case UnmanagedType.U2: - return Utf16Char; + return s_utf16Char; } } else if (marshalInfo is MarshallingInfoStringSupport marshalStringInfo) @@ -160,7 +160,7 @@ private IMarshallingGenerator CreateCharMarshaller(TypePositionInfo info, StubCo switch (marshalStringInfo.CharEncoding) { case CharEncoding.Utf16: - return Utf16Char; + return s_utf16Char; case CharEncoding.Ansi: throw new MarshallingNotSupportedException(info, context) // [Compat] ANSI is not supported for char { @@ -195,12 +195,12 @@ private IMarshallingGenerator CreateStringMarshaller(TypePositionInfo info, Stub switch (marshalAsInfo.UnmanagedType) { case UnmanagedType.LPStr: - return AnsiString; + return s_ansiString; case UnmanagedType.LPTStr: case UnmanagedType.LPWStr: - return Utf16String; + return s_utf16String; case (UnmanagedType)0x30:// UnmanagedType.LPUTF8Str - return Utf8String; + return s_utf8String; } } else if (marshalInfo is MarshallingInfoStringSupport marshalStringInfo) @@ -208,13 +208,13 @@ private IMarshallingGenerator CreateStringMarshaller(TypePositionInfo info, Stub switch (marshalStringInfo.CharEncoding) { case CharEncoding.Ansi: - return AnsiString; + return s_ansiString; case CharEncoding.Utf16: - return Utf16String; + return s_utf16String; case CharEncoding.Utf8: - return Utf8String; + return s_utf8String; case CharEncoding.PlatformDefined: - return PlatformDefinedString; + return s_platformDefinedString; } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PinnableManagedValueMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PinnableManagedValueMarshaller.cs index 1ba665ed1a3e2..5fe05bd0780b2 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PinnableManagedValueMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PinnableManagedValueMarshaller.cs @@ -10,11 +10,11 @@ namespace Microsoft.Interop { public sealed class PinnableManagedValueMarshaller : IMarshallingGenerator { - private readonly IMarshallingGenerator manualMarshallingGenerator; + private readonly IMarshallingGenerator _manualMarshallingGenerator; public PinnableManagedValueMarshaller(IMarshallingGenerator manualMarshallingGenerator) { - this.manualMarshallingGenerator = manualMarshallingGenerator; + this._manualMarshallingGenerator = manualMarshallingGenerator; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -24,17 +24,17 @@ public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) string identifier = context.GetIdentifiers(info).native; return Argument(CastExpression(AsNativeType(info), IdentifierName(identifier))); } - return manualMarshallingGenerator.AsArgument(info, context); + return _manualMarshallingGenerator.AsArgument(info, context); } public TypeSyntax AsNativeType(TypePositionInfo info) { - return manualMarshallingGenerator.AsNativeType(info); + return _manualMarshallingGenerator.AsNativeType(info); } public ParameterSyntax AsParameter(TypePositionInfo info) { - return manualMarshallingGenerator.AsParameter(info); + return _manualMarshallingGenerator.AsParameter(info); } public IEnumerable Generate(TypePositionInfo info, StubCodeContext context) @@ -43,12 +43,12 @@ public IEnumerable Generate(TypePositionInfo info, StubCodeCont { return GeneratePinningPath(info, context); } - return manualMarshallingGenerator.Generate(info, context); + return _manualMarshallingGenerator.Generate(info, context); } public bool SupportsByValueMarshalKind(ByValueContentsMarshalKind marshalKind, StubCodeContext context) { - return manualMarshallingGenerator.SupportsByValueMarshalKind(marshalKind, context); + return _manualMarshallingGenerator.SupportsByValueMarshalKind(marshalKind, context); } public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) @@ -57,7 +57,7 @@ public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context) { return false; } - return manualMarshallingGenerator.UsesNativeIdentifier(info, context); + return _manualMarshallingGenerator.UsesNativeIdentifier(info, context); } private static bool IsPinningPathSupported(TypePositionInfo info, StubCodeContext context) { diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Ansi.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Ansi.cs index 8809740b3e1dc..685e1747ff001 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Ansi.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Ansi.cs @@ -14,13 +14,13 @@ namespace Microsoft.Interop { public sealed class AnsiStringMarshaller : ConditionalStackallocMarshallingGenerator { - private static readonly TypeSyntax NativeType = PointerType(PredefinedType(Token(SyntaxKind.ByteKeyword))); + private static readonly TypeSyntax s_nativeType = PointerType(PredefinedType(Token(SyntaxKind.ByteKeyword))); - private readonly Utf8StringMarshaller utf8StringMarshaller; + private readonly Utf8StringMarshaller _utf8StringMarshaller; public AnsiStringMarshaller(Utf8StringMarshaller utf8StringMarshaller) { - this.utf8StringMarshaller = utf8StringMarshaller; + this._utf8StringMarshaller = utf8StringMarshaller; } public override ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -42,7 +42,7 @@ public override ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext public override TypeSyntax AsNativeType(TypePositionInfo info) { // byte* - return NativeType; + return s_nativeType; } public override ParameterSyntax AsParameter(TypePositionInfo info) @@ -105,7 +105,7 @@ public override IEnumerable Generate(TypePositionInfo info, Stu yield return IfStatement(IsWindows, windowsBlock, ElseClause( - Block(this.utf8StringMarshaller.Generate(info, context)))); + Block(this._utf8StringMarshaller.Generate(info, context)))); } break; case StubCodeContext.Stage.Unmarshal: @@ -140,7 +140,7 @@ public override IEnumerable Generate(TypePositionInfo info, Stu IdentifierName(nativeIdentifier))))), initializer: null))))), ElseClause( - Block(this.utf8StringMarshaller.Generate(info, context)))); + Block(this._utf8StringMarshaller.Generate(info, context)))); } break; case StubCodeContext.Stage.Cleanup: diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.PlatformDefined.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.PlatformDefined.cs index 26f45d820757b..7f4a080a3d2fd 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.PlatformDefined.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.PlatformDefined.cs @@ -15,21 +15,21 @@ namespace Microsoft.Interop { public sealed class PlatformDefinedStringMarshaller : ConditionalStackallocMarshallingGenerator { - private static readonly TypeSyntax NativeType = PointerType(PredefinedType(Token(SyntaxKind.VoidKeyword))); + private static readonly TypeSyntax s_nativeType = PointerType(PredefinedType(Token(SyntaxKind.VoidKeyword))); - private readonly IMarshallingGenerator windowsMarshaller; - private readonly IMarshallingGenerator nonWindowsMarshaller; + private readonly IMarshallingGenerator _windowsMarshaller; + private readonly IMarshallingGenerator _nonWindowsMarshaller; public PlatformDefinedStringMarshaller(IMarshallingGenerator windowsMarshaller, IMarshallingGenerator nonWindowsMarshaller) { - this.windowsMarshaller = windowsMarshaller; - this.nonWindowsMarshaller = nonWindowsMarshaller; + this._windowsMarshaller = windowsMarshaller; + this._nonWindowsMarshaller = nonWindowsMarshaller; } public override ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { - var windowsExpr = this.windowsMarshaller.AsArgument(info, context).Expression; - var nonWindowsExpr = this.nonWindowsMarshaller.AsArgument(info, context).Expression; + var windowsExpr = this._windowsMarshaller.AsArgument(info, context).Expression; + var nonWindowsExpr = this._nonWindowsMarshaller.AsArgument(info, context).Expression; // If the Windows and non-Windows syntax are equivalent, just return one of them. if (windowsExpr.IsEquivalentTo(nonWindowsExpr)) @@ -46,7 +46,7 @@ public override ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext public override TypeSyntax AsNativeType(TypePositionInfo info) { // void* - return NativeType; + return s_nativeType; } public override ParameterSyntax AsParameter(TypePositionInfo info) @@ -74,8 +74,8 @@ public override IEnumerable Generate(TypePositionInfo info, Stu if (info.RefKind != RefKind.Out) { if (this.TryGetConditionalBlockForStatements( - this.windowsMarshaller.Generate(info, context), - this.nonWindowsMarshaller.Generate(info, context), + this._windowsMarshaller.Generate(info, context), + this._nonWindowsMarshaller.Generate(info, context), out StatementSyntax marshal)) { yield return marshal; @@ -86,10 +86,10 @@ public override IEnumerable Generate(TypePositionInfo info, Stu // [Compat] The built-in system could determine the platform at runtime and pin only on // the platform on which is is needed. In the generated source, if pinning is needed for // any platform, it is done on every platform. - foreach (var s in this.windowsMarshaller.Generate(info, context)) + foreach (var s in this._windowsMarshaller.Generate(info, context)) yield return s; - foreach (var s in this.nonWindowsMarshaller.Generate(info, context)) + foreach (var s in this._nonWindowsMarshaller.Generate(info, context)) yield return s; break; @@ -97,8 +97,8 @@ public override IEnumerable Generate(TypePositionInfo info, Stu if (info.IsManagedReturnPosition || (info.IsByRef && info.RefKind != RefKind.In)) { if (this.TryGetConditionalBlockForStatements( - this.windowsMarshaller.Generate(info, context), - this.nonWindowsMarshaller.Generate(info, context), + this._windowsMarshaller.Generate(info, context), + this._nonWindowsMarshaller.Generate(info, context), out StatementSyntax unmarshal)) { yield return unmarshal; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Utf16.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Utf16.cs index 78733f1ce62e5..d374fbb77b892 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Utf16.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Utf16.cs @@ -18,7 +18,7 @@ public sealed class Utf16StringMarshaller : ConditionalStackallocMarshallingGene // so the threshold for optimized allocation is based on that length. private const int StackAllocBytesThreshold = 260 * sizeof(ushort); - private static readonly TypeSyntax NativeType = PointerType(PredefinedType(Token(SyntaxKind.UShortKeyword))); + private static readonly TypeSyntax s_nativeType = PointerType(PredefinedType(Token(SyntaxKind.UShortKeyword))); private static string PinnedIdentifier(string nativeIdentifier) => $"{nativeIdentifier}__pinned"; @@ -49,7 +49,7 @@ public override ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext public override TypeSyntax AsNativeType(TypePositionInfo info) { // ushort* - return NativeType; + return s_nativeType; } public override ParameterSyntax AsParameter(TypePositionInfo info) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Utf8.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Utf8.cs index c5c9b4eda1a96..9afc473842cf6 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Utf8.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Utf8.cs @@ -26,8 +26,8 @@ public sealed class Utf8StringMarshaller : ConditionalStackallocMarshallingGener // maximum number of bytes per 'char' is 3. private const int MaxByteCountPerChar = 3; - private static readonly TypeSyntax NativeType = PointerType(PredefinedType(Token(SyntaxKind.ByteKeyword))); - private static readonly TypeSyntax UTF8EncodingType = ParseTypeName("System.Text.Encoding.UTF8"); + private static readonly TypeSyntax s_nativeType = PointerType(PredefinedType(Token(SyntaxKind.ByteKeyword))); + private static readonly TypeSyntax s_utf8EncodingType = ParseTypeName("System.Text.Encoding.UTF8"); public override ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { @@ -43,7 +43,7 @@ public override ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext return Argument(IdentifierName(identifier)); } - public override TypeSyntax AsNativeType(TypePositionInfo info) => NativeType; + public override TypeSyntax AsNativeType(TypePositionInfo info) => s_nativeType; public override ParameterSyntax AsParameter(TypePositionInfo info) { @@ -155,7 +155,7 @@ protected override StatementSyntax GenerateStackallocOnlyValueMarshalling( InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, - UTF8EncodingType, + s_utf8EncodingType, IdentifierName("GetBytes")), ArgumentList( SeparatedList(new ArgumentSyntax[] { From 4336bed35cb7ca48d695a5ffb9e4002b99d1c1e0 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 28 Sep 2021 17:43:02 -0700 Subject: [PATCH 2/7] Remove 'this' qualification (IDE0003) --- .../gen/DllImportGenerator/Comparers.cs | 6 ++-- .../DllImportGenerator/Diagnostics/Events.cs | 4 +-- ...oPreserveSigMarshallingGeneratorFactory.cs | 2 +- .../PInvokeStubCodeGenerator.cs | 28 +++++++-------- ...CollectionElementMarshallingCodeContext.cs | 2 +- .../Marshalling/ArrayMarshaller.cs | 8 ++--- ...ributedMarshallingModelGeneratorFactory.cs | 2 +- .../ByValueContentsMarshalKindValidator.cs | 2 +- .../CustomNativeTypeMarshallingGenerator.cs | 4 +-- .../ICustomNativeTypeMarshallingStrategy.cs | 34 +++++++++---------- .../Marshalling/MarshallingGenerator.cs | 4 +-- .../MarshallingGeneratorFactory.cs | 2 +- .../PinnableManagedValueMarshaller.cs | 2 +- .../Marshalling/StringMarshaller.Ansi.cs | 6 ++-- .../StringMarshaller.PlatformDefined.cs | 24 ++++++------- .../TypePositionInfo.cs | 4 +-- 16 files changed, 67 insertions(+), 67 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Comparers.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Comparers.cs index 3e86f4eae8326..71ecae6a88860 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Comparers.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Comparers.cs @@ -47,7 +47,7 @@ internal class ImmutableArraySequenceEqualComparer : IEqualityComparerThe comparer instance for the collection elements. public ImmutableArraySequenceEqualComparer(IEqualityComparer elementComparer) { - this._elementComparer = elementComparer; + _elementComparer = elementComparer; } public bool Equals(ImmutableArray x, ImmutableArray y) @@ -81,8 +81,8 @@ internal class CustomValueTupleElementComparer : IEqualityComparer<(T, U)> public CustomValueTupleElementComparer(IEqualityComparer item1Comparer, IEqualityComparer item2Comparer) { - this._item1Comparer = item1Comparer; - this._item2Comparer = item2Comparer; + _item1Comparer = item1Comparer; + _item2Comparer = item2Comparer; } public bool Equals((T, U) x, (T, U) y) diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Diagnostics/Events.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Diagnostics/Events.cs index f1f34123af67a..785d253bdcd9e 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Diagnostics/Events.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Diagnostics/Events.cs @@ -45,7 +45,7 @@ public static IDisposable SourceGenerationStartStop(int methodCount) [Event(StartSourceGenerationEventId, Level = EventLevel.Informational, Keywords = Keywords.SourceGeneration)] public void SourceGenerationStart(int methodCount) { - this.WriteEvent(StartSourceGenerationEventId, methodCount); + WriteEvent(StartSourceGenerationEventId, methodCount); } /// @@ -54,7 +54,7 @@ public void SourceGenerationStart(int methodCount) [Event(StopSourceGenerationEventId, Level = EventLevel.Informational, Keywords = Keywords.SourceGeneration)] public void SourceGenerationStop() { - this.WriteEvent(StopSourceGenerationEventId); + WriteEvent(StopSourceGenerationEventId); } private class StartStopEvent : IDisposable diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/NoPreserveSigMarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/NoPreserveSigMarshallingGeneratorFactory.cs index 3ac176c0016e6..d06e7db251cfd 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/NoPreserveSigMarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/NoPreserveSigMarshallingGeneratorFactory.cs @@ -16,7 +16,7 @@ internal class NoPreserveSigMarshallingGeneratorFactory : IMarshallingGeneratorF public NoPreserveSigMarshallingGeneratorFactory(IMarshallingGeneratorFactory inner) { - this._inner = inner; + _inner = inner; } public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/PInvokeStubCodeGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/PInvokeStubCodeGenerator.cs index ec026ee163f61..27ee9e161e94b 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/PInvokeStubCodeGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/PInvokeStubCodeGenerator.cs @@ -67,7 +67,7 @@ public PInvokeStubCodeGenerator( Action marshallingNotSupportedCallback, IMarshallingGeneratorFactory generatorFactory) { - this._setLastError = setLastError; + _setLastError = setLastError; List allMarshallers = new(); List paramMarshallers = new(); @@ -98,17 +98,17 @@ public PInvokeStubCodeGenerator( } } - this._stubReturnsVoid = managedRetMarshaller.TypeInfo.ManagedType == SpecialTypeInfo.Void; + _stubReturnsVoid = managedRetMarshaller.TypeInfo.ManagedType == SpecialTypeInfo.Void; - if (!managedRetMarshaller.TypeInfo.IsNativeReturnPosition && !this._stubReturnsVoid) + if (!managedRetMarshaller.TypeInfo.IsNativeReturnPosition && !_stubReturnsVoid) { // If the managed ret marshaller isn't the native ret marshaller, then the managed ret marshaller // is a parameter. paramMarshallers.Add(managedRetMarshaller); } - this._retMarshaller = nativeRetMarshaller; - this._paramMarshallers = paramMarshallers; + _retMarshaller = nativeRetMarshaller; + _paramMarshallers = paramMarshallers; // We are doing a topological sort of our marshallers to ensure that each parameter/return value's // dependencies are unmarshalled before their dependents. This comes up in the case of contiguous @@ -132,7 +132,7 @@ public PInvokeStubCodeGenerator( // the return value has dependencies on numRows and numColumns and numRows has a dependency on numColumns, // we want to unmarshal numColumns, then numRows, then the return value. // A topological sort ensures we get this order correct. - this._sortedMarshallers = MarshallerHelpers.GetTopologicallySortedElements( + _sortedMarshallers = MarshallerHelpers.GetTopologicallySortedElements( allMarshallers, static m => GetInfoIndex(m.TypeInfo), static m => GetInfoDependencies(m.TypeInfo)) @@ -141,7 +141,7 @@ public PInvokeStubCodeGenerator( if (managedRetMarshaller.Generator.UsesNativeIdentifier(managedRetMarshaller.TypeInfo, this)) { // Update the native identifier for the return value - this.ReturnNativeIdentifier = $"{ReturnIdentifier}{GeneratedNativeIdentifierSuffix}"; + ReturnNativeIdentifier = $"{ReturnIdentifier}{GeneratedNativeIdentifierSuffix}"; } static IEnumerable GetInfoDependencies(TypePositionInfo info) @@ -258,7 +258,7 @@ public BlockSyntax GeneratePInvokeBody(string dllImportName) // Do not manually handle SetLastError when generating forwarders. // We want the runtime to handle everything. - if (this._setLastError) + if (_setLastError) { // Declare variable for last error setupStatements.Add(MarshallerHelpers.DeclareWithDefault( @@ -304,7 +304,7 @@ public BlockSyntax GeneratePInvokeBody(string dllImportName) allStatements.AddRange(tryStatements); } - if (this._setLastError) + if (_setLastError) { // Marshal.SetLastPInvokeError(); allStatements.Add(ExpressionStatement( @@ -327,7 +327,7 @@ public BlockSyntax GeneratePInvokeBody(string dllImportName) void GenerateStatementsForStage(Stage stage, List statementsToUpdate) { int initialCount = statementsToUpdate.Count; - this.CurrentStage = stage; + CurrentStage = stage; if (!invokeReturnsVoid && (stage is Stage.Setup or Stage.Cleanup)) { @@ -371,7 +371,7 @@ void GenerateStatementsForStage(Stage stage, List statementsToU void GenerateStatementsForInvoke(List statementsToUpdate, InvocationExpressionSyntax invoke) { var fixedStatements = new List(); - this.CurrentStage = Stage.Pin; + CurrentStage = Stage.Pin; // Generate code for each parameter for the current stage foreach (var marshaller in _paramMarshallers) { @@ -386,7 +386,7 @@ void GenerateStatementsForInvoke(List statementsToUpdate, Invoc } } - this.CurrentStage = Stage.Invoke; + CurrentStage = Stage.Invoke; // Generate code for each parameter for the current stage foreach (var marshaller in _paramMarshallers) { @@ -406,7 +406,7 @@ void GenerateStatementsForInvoke(List statementsToUpdate, Invoc invokeStatement = ExpressionStatement( AssignmentExpression( SyntaxKind.SimpleAssignmentExpression, - IdentifierName(this.GetIdentifiers(_retMarshaller.TypeInfo).native), + IdentifierName(GetIdentifiers(_retMarshaller.TypeInfo).native), invoke)); } @@ -474,7 +474,7 @@ _retMarshaller.Generator is IAttributedReturnTypeMarshallingGenerator attributed private void AppendVariableDeclations(List statementsToUpdate, TypePositionInfo info, IMarshallingGenerator generator) { - var (managed, native) = this.GetIdentifiers(info); + var (managed, native) = GetIdentifiers(info); // Declare variable for return value if (info.IsManagedReturnPosition || info.IsNativeReturnPosition) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContiguousCollectionElementMarshallingCodeContext.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContiguousCollectionElementMarshallingCodeContext.cs index 67e7c37831523..82eb6f3f2686f 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContiguousCollectionElementMarshallingCodeContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ContiguousCollectionElementMarshallingCodeContext.cs @@ -37,7 +37,7 @@ public ContiguousCollectionElementMarshallingCodeContext( { CurrentStage = currentStage; IndexerIdentifier = CalculateIndexerIdentifierBasedOnParentContext(parentContext); - this._nativeSpanIdentifier = nativeSpanIdentifier; + _nativeSpanIdentifier = nativeSpanIdentifier; ParentContext = parentContext; } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs index ee39b97247883..b9319b751febb 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ArrayMarshaller.cs @@ -18,10 +18,10 @@ public sealed class ArrayMarshaller : IMarshallingGenerator public ArrayMarshaller(IMarshallingGenerator manualMarshallingGenerator, TypeSyntax elementType, bool enablePinning, InteropGenerationOptions options) { - this._manualMarshallingGenerator = manualMarshallingGenerator; - this._elementType = elementType; - this._enablePinning = enablePinning; - this._options = options; + _manualMarshallingGenerator = manualMarshallingGenerator; + _elementType = elementType; + _enablePinning = enablePinning; + _options = options; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs index 20b40426a75a5..8a8aae6fca7ad 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs @@ -22,7 +22,7 @@ public class AttributedMarshallingModelGeneratorFactory : IMarshallingGeneratorF public AttributedMarshallingModelGeneratorFactory(IMarshallingGeneratorFactory innerMarshallingGenerator, InteropGenerationOptions options) { Options = options; - this._innerMarshallingGenerator = innerMarshallingGenerator; + _innerMarshallingGenerator = innerMarshallingGenerator; ElementMarshallingGeneratorFactory = this; } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs index fdc572d451bb4..1d36a8789c925 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs @@ -16,7 +16,7 @@ public class ByValueContentsMarshalKindValidator : IMarshallingGeneratorFactory public ByValueContentsMarshalKindValidator(IMarshallingGeneratorFactory inner) { - this._inner = inner; + _inner = inner; } public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomNativeTypeMarshallingGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomNativeTypeMarshallingGenerator.cs index 70efa90b99992..d114c9092aaa7 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomNativeTypeMarshallingGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/CustomNativeTypeMarshallingGenerator.cs @@ -19,8 +19,8 @@ internal sealed class CustomNativeTypeMarshallingGenerator : IMarshallingGenerat public CustomNativeTypeMarshallingGenerator(ICustomNativeTypeMarshallingStrategy nativeTypeMarshaller, bool enableByValueContentsMarshalling) { - this._nativeTypeMarshaller = nativeTypeMarshaller; - this._enableByValueContentsMarshalling = enableByValueContentsMarshalling; + _nativeTypeMarshaller = nativeTypeMarshaller; + _enableByValueContentsMarshalling = enableByValueContentsMarshalling; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomNativeTypeMarshallingStrategy.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomNativeTypeMarshallingStrategy.cs index bbd8ae15875ae..87e25faf55445 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomNativeTypeMarshallingStrategy.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomNativeTypeMarshallingStrategy.cs @@ -45,7 +45,7 @@ internal sealed class SimpleCustomNativeTypeMarshalling : ICustomNativeTypeMarsh public SimpleCustomNativeTypeMarshalling(TypeSyntax nativeTypeSyntax) { - this._nativeTypeSyntax = nativeTypeSyntax; + _nativeTypeSyntax = nativeTypeSyntax; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -156,8 +156,8 @@ internal sealed class CustomNativeTypeWithValuePropertyMarshalling : ICustomNati public CustomNativeTypeWithValuePropertyMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller, TypeSyntax valuePropertyType) { - this._innerMarshaller = innerMarshaller; - this._valuePropertyType = valuePropertyType; + _innerMarshaller = innerMarshaller; + _valuePropertyType = valuePropertyType; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -282,7 +282,7 @@ internal sealed class StackallocOptimizationMarshalling : ICustomNativeTypeMarsh public StackallocOptimizationMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller) { - this._innerMarshaller = innerMarshaller; + _innerMarshaller = innerMarshaller; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -391,7 +391,7 @@ internal sealed class FreeNativeCleanupStrategy : ICustomNativeTypeMarshallingSt public FreeNativeCleanupStrategy(ICustomNativeTypeMarshallingStrategy innerMarshaller) { - this._innerMarshaller = innerMarshaller; + _innerMarshaller = innerMarshaller; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -460,8 +460,8 @@ internal sealed class PinnableMarshallerTypeMarshalling : ICustomNativeTypeMarsh public PinnableMarshallerTypeMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller, TypeSyntax valuePropertyType) { - this._innerMarshaller = innerMarshaller; - this._valuePropertyType = valuePropertyType; + _innerMarshaller = innerMarshaller; + _valuePropertyType = valuePropertyType; } private bool CanPinMarshaller(TypePositionInfo info, StubCodeContext context) @@ -606,9 +606,9 @@ internal sealed class NumElementsExpressionMarshalling : ICustomNativeTypeMarsha public NumElementsExpressionMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller, ExpressionSyntax numElementsExpression, ExpressionSyntax sizeOfElementExpression) { - this._innerMarshaller = innerMarshaller; - this._numElementsExpression = numElementsExpression; - this._sizeOfElementExpression = sizeOfElementExpression; + _innerMarshaller = innerMarshaller; + _numElementsExpression = numElementsExpression; + _sizeOfElementExpression = sizeOfElementExpression; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -720,8 +720,8 @@ internal sealed class ContiguousBlittableElementCollectionMarshalling : ICustomN public ContiguousBlittableElementCollectionMarshalling(ICustomNativeTypeMarshallingStrategy innerMarshaller, TypeSyntax elementType) { - this._innerMarshaller = innerMarshaller; - this._elementType = elementType; + _innerMarshaller = innerMarshaller; + _elementType = elementType; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -863,9 +863,9 @@ public ContiguousNonBlittableElementCollectionMarshalling(ICustomNativeTypeMarsh IMarshallingGenerator elementMarshaller, TypePositionInfo elementInfo) { - this._innerMarshaller = innerMarshaller; - this._elementMarshaller = elementMarshaller; - this._elementInfo = elementInfo; + _innerMarshaller = innerMarshaller; + _elementMarshaller = elementMarshaller; + _elementInfo = elementInfo; } private LocalDeclarationStatementSyntax GenerateNativeSpanDeclaration(TypePositionInfo info, StubCodeContext context) @@ -1025,8 +1025,8 @@ private class PointerNativeTypeAssignmentRewriter : CSharpSyntaxRewriter public PointerNativeTypeAssignmentRewriter(string nativeIdentifier, PointerTypeSyntax nativeType) { - this._nativeIdentifier = nativeIdentifier; - this._nativeType = nativeType; + _nativeIdentifier = nativeIdentifier; + _nativeType = nativeType; } public override SyntaxNode VisitAssignmentExpression(AssignmentExpressionSyntax node) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs index 8b412a89e5d96..74e7a517a4707 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGenerator.cs @@ -97,8 +97,8 @@ public sealed class MarshallingNotSupportedException : Exception /// instance public MarshallingNotSupportedException(TypePositionInfo info, StubCodeContext context) { - this.TypePositionInfo = info; - this.StubCodeContext = context; + TypePositionInfo = info; + StubCodeContext = context; } /// diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs index a2432f4cdf8ac..bc496a1982eb8 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs @@ -45,7 +45,7 @@ public sealed class DefaultMarshallingGeneratorFactory : IMarshallingGeneratorFa public DefaultMarshallingGeneratorFactory(InteropGenerationOptions options) { - this.Options = options; + Options = options; } /// diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PinnableManagedValueMarshaller.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PinnableManagedValueMarshaller.cs index 5fe05bd0780b2..8a17dd5aeba3d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PinnableManagedValueMarshaller.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/PinnableManagedValueMarshaller.cs @@ -14,7 +14,7 @@ public sealed class PinnableManagedValueMarshaller : IMarshallingGenerator public PinnableManagedValueMarshaller(IMarshallingGenerator manualMarshallingGenerator) { - this._manualMarshallingGenerator = manualMarshallingGenerator; + _manualMarshallingGenerator = manualMarshallingGenerator; } public ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Ansi.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Ansi.cs index 685e1747ff001..c26ea8467d866 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Ansi.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.Ansi.cs @@ -20,7 +20,7 @@ public sealed class AnsiStringMarshaller : ConditionalStackallocMarshallingGener public AnsiStringMarshaller(Utf8StringMarshaller utf8StringMarshaller) { - this._utf8StringMarshaller = utf8StringMarshaller; + _utf8StringMarshaller = utf8StringMarshaller; } public override ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) @@ -105,7 +105,7 @@ public override IEnumerable Generate(TypePositionInfo info, Stu yield return IfStatement(IsWindows, windowsBlock, ElseClause( - Block(this._utf8StringMarshaller.Generate(info, context)))); + Block(_utf8StringMarshaller.Generate(info, context)))); } break; case StubCodeContext.Stage.Unmarshal: @@ -140,7 +140,7 @@ public override IEnumerable Generate(TypePositionInfo info, Stu IdentifierName(nativeIdentifier))))), initializer: null))))), ElseClause( - Block(this._utf8StringMarshaller.Generate(info, context)))); + Block(_utf8StringMarshaller.Generate(info, context)))); } break; case StubCodeContext.Stage.Cleanup: diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.PlatformDefined.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.PlatformDefined.cs index 7f4a080a3d2fd..0b30170f1e0ec 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.PlatformDefined.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/StringMarshaller.PlatformDefined.cs @@ -22,14 +22,14 @@ public sealed class PlatformDefinedStringMarshaller : ConditionalStackallocMarsh public PlatformDefinedStringMarshaller(IMarshallingGenerator windowsMarshaller, IMarshallingGenerator nonWindowsMarshaller) { - this._windowsMarshaller = windowsMarshaller; - this._nonWindowsMarshaller = nonWindowsMarshaller; + _windowsMarshaller = windowsMarshaller; + _nonWindowsMarshaller = nonWindowsMarshaller; } public override ArgumentSyntax AsArgument(TypePositionInfo info, StubCodeContext context) { - var windowsExpr = this._windowsMarshaller.AsArgument(info, context).Expression; - var nonWindowsExpr = this._nonWindowsMarshaller.AsArgument(info, context).Expression; + var windowsExpr = _windowsMarshaller.AsArgument(info, context).Expression; + var nonWindowsExpr = _nonWindowsMarshaller.AsArgument(info, context).Expression; // If the Windows and non-Windows syntax are equivalent, just return one of them. if (windowsExpr.IsEquivalentTo(nonWindowsExpr)) @@ -73,9 +73,9 @@ public override IEnumerable Generate(TypePositionInfo info, Stu case StubCodeContext.Stage.Marshal: if (info.RefKind != RefKind.Out) { - if (this.TryGetConditionalBlockForStatements( - this._windowsMarshaller.Generate(info, context), - this._nonWindowsMarshaller.Generate(info, context), + if (TryGetConditionalBlockForStatements( + _windowsMarshaller.Generate(info, context), + _nonWindowsMarshaller.Generate(info, context), out StatementSyntax marshal)) { yield return marshal; @@ -86,19 +86,19 @@ public override IEnumerable Generate(TypePositionInfo info, Stu // [Compat] The built-in system could determine the platform at runtime and pin only on // the platform on which is is needed. In the generated source, if pinning is needed for // any platform, it is done on every platform. - foreach (var s in this._windowsMarshaller.Generate(info, context)) + foreach (var s in _windowsMarshaller.Generate(info, context)) yield return s; - foreach (var s in this._nonWindowsMarshaller.Generate(info, context)) + foreach (var s in _nonWindowsMarshaller.Generate(info, context)) yield return s; break; case StubCodeContext.Stage.Unmarshal: if (info.IsManagedReturnPosition || (info.IsByRef && info.RefKind != RefKind.In)) { - if (this.TryGetConditionalBlockForStatements( - this._windowsMarshaller.Generate(info, context), - this._nonWindowsMarshaller.Generate(info, context), + if (TryGetConditionalBlockForStatements( + _windowsMarshaller.Generate(info, context), + _nonWindowsMarshaller.Generate(info, context), out StatementSyntax unmarshal)) { yield return unmarshal; diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypePositionInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypePositionInfo.cs index 5195372bc63c6..baa8c150fda06 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypePositionInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypePositionInfo.cs @@ -57,8 +57,8 @@ public sealed record TypePositionInfo(ManagedTypeInfo ManagedType, MarshallingIn public ByValueContentsMarshalKind ByValueContentsMarshalKind { get; init; } - public bool IsManagedReturnPosition { get => this.ManagedIndex == ReturnIndex; } - public bool IsNativeReturnPosition { get => this.NativeIndex == ReturnIndex; } + public bool IsManagedReturnPosition { get => ManagedIndex == ReturnIndex; } + public bool IsNativeReturnPosition { get => NativeIndex == ReturnIndex; } public int ManagedIndex { get; init; } = UnsetIndex; public int NativeIndex { get; init; } = UnsetIndex; From b9da0faad03eec5abd3d9448559a7d8b40a3c5ff Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 28 Sep 2021 17:50:22 -0700 Subject: [PATCH 3/7] Fix formatting violations (IDE0055) --- .../InteropServices/ArrayMarshaller.cs | 2 +- .../GeneratedMarshallingAttribute.cs | 2 +- .../ManualTypeMarshallingAnalyzer.cs | 2 +- .../DllImportStubContext.cs | 6 ++-- .../gen/DllImportGenerator/LanguageSupport.cs | 2 +- .../LanguageSupport.cs | 2 +- .../ManualTypeMarshallingHelper.cs | 12 +++---- .../MarshallingAttributeInfo.cs | 4 +-- .../TypeSymbolExtensions.cs | 34 +++++++++---------- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs b/src/libraries/Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs index 4014154b4824c..2293743aa87fe 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs +++ b/src/libraries/Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs @@ -26,7 +26,7 @@ unsafe ref struct ArrayMarshaller private IntPtr _allocatedMemory; public ArrayMarshaller(int sizeOfNativeElement) - :this() + : this() { _sizeOfNativeElement = sizeOfNativeElement; } diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs b/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs index f9308081c2b2f..2fc73b41e3cb8 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs +++ b/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs @@ -57,7 +57,7 @@ public MarshalUsingAttribute() } public MarshalUsingAttribute(Type nativeType) - :this() + : this() { NativeType = nativeType; } diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs index fae3f7dc1cf99..d7aab5dc9329d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs @@ -290,7 +290,7 @@ public void AnalyzeTypeDefinition(SymbolAnalysisContext context) } else if (nativeMarshallingAttributeData is not null) { - AnalyzeNativeMarshalerType(context, type, nativeMarshallingAttributeData, isNativeMarshallingAttribute:true); + AnalyzeNativeMarshalerType(context, type, nativeMarshallingAttributeData, isNativeMarshallingAttribute: true); } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs index 56c86a4d0f2cb..81e10ff2ae6a8 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs @@ -25,9 +25,9 @@ internal record StubEnvironment( internal sealed class DllImportStubContext : IEquatable { -// We don't need the warnings around not setting the various -// non-nullable fields/properties on this type in the constructor -// since we always use a property initializer. + // We don't need the warnings around not setting the various + // non-nullable fields/properties on this type in the constructor + // since we always use a property initializer. #pragma warning disable 8618 private DllImportStubContext() { diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/LanguageSupport.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/LanguageSupport.cs index 4abeef8a7b1c3..0f983ddc28671 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/LanguageSupport.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/LanguageSupport.cs @@ -7,5 +7,5 @@ namespace System.Runtime.CompilerServices { // Define IsExternalInit type to support records. internal class IsExternalInit - {} + { } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/LanguageSupport.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/LanguageSupport.cs index 4abeef8a7b1c3..0f983ddc28671 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/LanguageSupport.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/LanguageSupport.cs @@ -7,5 +7,5 @@ namespace System.Runtime.CompilerServices { // Define IsExternalInit type to support records. internal class IsExternalInit - {} + { } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManualTypeMarshallingHelper.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManualTypeMarshallingHelper.cs index e3a0406870d58..503cae185ec9d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManualTypeMarshallingHelper.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/ManualTypeMarshallingHelper.cs @@ -127,11 +127,11 @@ public static bool HasSetUnmarshalledCollectionLengthMethod(ITypeSymbol type) return type.GetMembers(SetUnmarshalledCollectionLengthMethodName) .OfType() .Any(m => m is - { - IsStatic: false, - Parameters: { Length: 1 }, - ReturnType: { SpecialType: SpecialType.System_Void } - } && m.Parameters[0].Type.SpecialType == SpecialType.System_Int32); + { + IsStatic: false, + Parameters: { Length: 1 }, + ReturnType: { SpecialType: SpecialType.System_Void } + } && m.Parameters[0].Type.SpecialType == SpecialType.System_Int32); } public static bool HasNativeValueStorageProperty(ITypeSymbol type, ITypeSymbol spanOfByte) @@ -139,7 +139,7 @@ public static bool HasNativeValueStorageProperty(ITypeSymbol type, ITypeSymbol s return type .GetMembers(NativeValueStoragePropertyName) .OfType() - .Any(p => p is {IsStatic: false, GetMethod: not null, ReturnsByRef: false, ReturnsByRefReadonly: false } + .Any(p => p is { IsStatic: false, GetMethod: not null, ReturnsByRef: false, ReturnsByRefReadonly: false } && SymbolEqualityComparer.Default.Equals(p.Type, spanOfByte)); } } diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs index 30cea9d1bfd94..d2c7d7923898d 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs @@ -28,7 +28,7 @@ public abstract record MarshallingInfo // Add a constructor that can only be called by derived types in the same assembly // to enforce that this type cannot be extended by users of this library. private protected MarshallingInfo() - {} + { } } public sealed record NoMarshallingInfo : MarshallingInfo @@ -87,7 +87,7 @@ public enum CustomMarshallingFeatures public abstract record CountInfo { - private protected CountInfo() {} + private protected CountInfo() { } } public sealed record NoCountInfo : CountInfo diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs index 37eb22079edca..051c65e837283 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs @@ -56,23 +56,23 @@ private static bool HasOnlyBlittableFields(this ITypeSymbol type, ImmutableHashS } private static bool IsSpecialTypeBlittable(SpecialType specialType) - => specialType switch - { - SpecialType.System_Void - or SpecialType.System_SByte - or SpecialType.System_Byte - or SpecialType.System_Int16 - or SpecialType.System_UInt16 - or SpecialType.System_Int32 - or SpecialType.System_UInt32 - or SpecialType.System_Int64 - or SpecialType.System_UInt64 - or SpecialType.System_Single - or SpecialType.System_Double - or SpecialType.System_IntPtr - or SpecialType.System_UIntPtr => true, - _ => false - }; + => specialType switch + { + SpecialType.System_Void + or SpecialType.System_SByte + or SpecialType.System_Byte + or SpecialType.System_Int16 + or SpecialType.System_UInt16 + or SpecialType.System_Int32 + or SpecialType.System_UInt32 + or SpecialType.System_Int64 + or SpecialType.System_UInt64 + or SpecialType.System_Single + or SpecialType.System_Double + or SpecialType.System_IntPtr + or SpecialType.System_UIntPtr => true, + _ => false + }; public static bool IsConsideredBlittable(this ITypeSymbol type) => IsConsideredBlittable(type, ImmutableHashSet.Create(SymbolEqualityComparer.Default)); From 8a89d1937cb33c990b68827c96532f61432ec07c Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 28 Sep 2021 17:56:15 -0700 Subject: [PATCH 4/7] Inline variable declaration (IDE0018) --- .../Analyzers/ConvertToGeneratedDllImportFixer.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ConvertToGeneratedDllImportFixer.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ConvertToGeneratedDllImportFixer.cs index e29fae5f12beb..e61f3b6aa9caa 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ConvertToGeneratedDllImportFixer.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ConvertToGeneratedDllImportFixer.cs @@ -55,8 +55,7 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) return; // Make sure the method has the DllImportAttribute - AttributeData? dllImportAttr; - if (!TryGetAttribute(methodSymbol, dllImportAttrType, out dllImportAttr)) + if (!TryGetAttribute(methodSymbol, dllImportAttrType, out AttributeData? dllImportAttr)) return; // Register code fixes with two options for the fix - using preprocessor or not. From 30843f9a0f1738ed3a42eb5d3f98d4d28e9e5c7f Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 28 Sep 2021 17:57:24 -0700 Subject: [PATCH 5/7] Pattern matching for is+cast (IDE0020) --- .../MarshallingAttributeInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs index d2c7d7923898d..139e7abe11487 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs @@ -449,8 +449,8 @@ private MarshallingInfo CreateInfoFromMarshalAs( ref int maxIndirectionLevelUsed) { object unmanagedTypeObj = attrData.ConstructorArguments[0].Value!; - UnmanagedType unmanagedType = unmanagedTypeObj is short - ? (UnmanagedType)(short)unmanagedTypeObj + UnmanagedType unmanagedType = unmanagedTypeObj is short unmanagedTypeAsShort + ? (UnmanagedType)unmanagedTypeAsShort : (UnmanagedType)unmanagedTypeObj; if (!Enum.IsDefined(typeof(UnmanagedType), unmanagedType) || unmanagedType == UnmanagedType.CustomMarshaler From df1ad8e5194109903ff22ff8df96c6a61c15c1bb Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 28 Sep 2021 17:59:15 -0700 Subject: [PATCH 6/7] Use collection initializer (IDE0028) --- .../Marshalling/Forwarder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs index 4ef59de028a48..fd4ca6a37ae62 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs @@ -41,13 +41,13 @@ private bool TryRehydrateMarshalAsAttribute(TypePositionInfo info, out Attribute && collectionMarshalling.ElementMarshallingInfo is NoMarshallingInfo or MarshalAsInfo { UnmanagedType: not UnmanagedType.CustomMarshaler } && info.ManagedType is IArrayTypeSymbol) { - List marshalAsArguments = new List(); - marshalAsArguments.Add( + List marshalAsArguments = new List + { AttributeArgument( CastExpression(ParseTypeName(TypeNames.System_Runtime_InteropServices_UnmanagedType), LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal((int)UnmanagedType.LPArray)))) - ); + }; if (collectionMarshalling.ElementCountInfo is SizeAndParamIndexInfo countInfo) { From c89d414a2ed480518a026159ced10004efd5786e Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 28 Sep 2021 18:00:51 -0700 Subject: [PATCH 7/7] Make field readonly (IDE0044) --- .../gen/DllImportGenerator/DllImportGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs index 89e321c7623ec..d2f357636456e 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs +++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs @@ -57,7 +57,7 @@ public enum StepName public record ExecutedStepInfo(StepName Step, object Input); - private List _executedSteps = new(); + private readonly List _executedSteps = new(); public IEnumerable ExecutedSteps => _executedSteps; internal void RecordExecutedStep(ExecutedStepInfo step) => _executedSteps.Add(step);