From bc6566103b2cba8da5f8203ed418ed45c6b857ff Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 9 Mar 2022 20:58:47 -0800 Subject: [PATCH 1/7] Expose LibraryImportAttribute --- eng/generators.targets | 8 ++- .../InteropServices/LibraryImportAttribute.cs | 53 ++++++++++++++----- .../InteropServices/StringMarshalling.cs | 2 +- .../System.Private.CoreLib.Shared.projitems | 6 +++ .../ref/System.Runtime.InteropServices.cs | 16 ++++++ .../Ancillary.Interop.csproj | 2 - .../TestUtils.cs | 2 +- 7 files changed, 71 insertions(+), 18 deletions(-) diff --git a/eng/generators.targets b/eng/generators.targets index 9ca826c5cc759..0d294625736f0 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -44,8 +44,12 @@ - - + + + + diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs b/src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs index 0bacf3efad5d5..622460303145c 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs +++ b/src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs @@ -3,32 +3,61 @@ #nullable enable -// -// Types in this file are used for generated p/invokes (docs/design/features/source-generator-pinvokes.md). -// namespace System.Runtime.InteropServices { /// - /// Indicates that method will be generated at compile time and invoke into an unmanaged library entry point + /// Attribute used to indicate a Source Generator should create a function for marshaling + /// arguments instead of relying on the CLR to generate an IL Stub at runtime. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -#if LIBRARYIMPORT_GENERATOR_TEST +#if NET7_0_OR_GREATER public #else internal #endif sealed class LibraryImportAttribute : Attribute { - public string? EntryPoint { get; set; } - public bool SetLastError { get; set; } - public StringMarshalling StringMarshalling { get; set; } - public Type? StringMarshallingCustomType { get; set; } - - public LibraryImportAttribute(string dllName) + /// + /// Initializes a new instance of the . + /// + /// Name of the library containing the import + public LibraryImportAttribute(string libraryName) { - LibraryName = dllName; + LibraryName = libraryName; } + /// + /// Library to load. + /// public string LibraryName { get; private set; } + + /// + /// Indicates the name of the entry point to be called. + /// + public string? EntryPoint { get; set; } + + /// + /// Indicates how to marshal string parameters to the method. + /// + /// + /// If this field is set to a value other than , + /// must not be specified. + /// + public StringMarshalling StringMarshalling { get; set; } + + /// + /// Indicates how to marshal string parameters to the method. + /// + /// + /// If this field is specified, must not be specified + /// or must be set to . + /// + public Type? StringMarshallingCustomType { get; set; } + + /// + /// Indicates whether the callee sents an error (SetLastError on Windows or errorno + /// on other platforms) before returning from the attributed method. + /// + public bool SetLastError { get; set; } } } diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/StringMarshalling.cs b/src/libraries/Common/src/System/Runtime/InteropServices/StringMarshalling.cs index 36c6adfb44197..f0274b3e9c1f2 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/StringMarshalling.cs +++ b/src/libraries/Common/src/System/Runtime/InteropServices/StringMarshalling.cs @@ -9,7 +9,7 @@ namespace System.Runtime.InteropServices /// /// Specifies how strings should be marshalled for generated p/invokes /// -#if LIBRARYIMPORT_GENERATOR_TEST +#if NET7_0_OR_GREATER public #else internal diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 8bf268cecd003..eafa6d603abf8 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1248,6 +1248,12 @@ Common\System\Runtime\CompilerServices\IsExternalInit.cs + + Common\System\Runtime\InteropServices\LibraryImportAttribute.cs + + + Common\System\Runtime\InteropServices\StringMarshalling.cs + Common\System\Runtime\Versioning\NonVersionableAttribute.cs diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index eac47acf63d96..b16cd4b6b65ad 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -484,6 +484,16 @@ public sealed partial class LCIDConversionAttribute : System.Attribute public LCIDConversionAttribute(int lcid) { } public int Value { get { throw null; } } } + [System.AttributeUsageAttribute(System.AttributeTargets.Method, AllowMultiple = false, Inherited=false)] + public sealed partial class LibraryImportAttribute : System.Attribute + { + public LibraryImportAttribute(string libraryName) { } + public string LibraryName { get { throw null; } } + public string? EntryPoint { get { throw null; } set { } } + public bool SetLastError { get { throw null; } set { }} + public StringMarshalling StringMarshalling { get { throw null; } set { } } + public Type? StringMarshallingCustomType { get { throw null; } set { } } + } [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false, AllowMultiple=false)] public sealed partial class ManagedToNativeComInteropStubAttribute : System.Attribute { @@ -994,6 +1004,12 @@ public partial class StandardOleMarshalObject : System.MarshalByRefObject { protected StandardOleMarshalObject() { } } + public enum StringMarshalling + { + Custom = 0, + Utf8 = 1, + Utf16 = 2, + } [System.AttributeUsageAttribute(System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Interface | System.AttributeTargets.Struct, AllowMultiple=false, Inherited=false)] public sealed partial class TypeIdentifierAttribute : System.Attribute { diff --git a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Ancillary.Interop.csproj b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Ancillary.Interop.csproj index 60e536023fbb3..710d935b82f00 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Ancillary.Interop.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/Ancillary.Interop/Ancillary.Interop.csproj @@ -11,9 +11,7 @@ - - diff --git a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/TestUtils.cs b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/TestUtils.cs index cabfb327be427..f1d835ce585f9 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/TestUtils.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/TestUtils.cs @@ -183,7 +183,7 @@ internal static MetadataReference GetAncillaryReference() { // Include the assembly containing the new attribute and all of its references. // [TODO] Remove once the attribute has been added to the BCL - var attrAssem = typeof(LibraryImportAttribute).GetTypeInfo().Assembly; + var attrAssem = typeof(MarshalUsingAttribute).GetTypeInfo().Assembly; return MetadataReference.CreateFromFile(attrAssem.Location); } From 569b855a95c411cff8d60907b1b43372ca84950e Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 9 Mar 2022 21:40:04 -0800 Subject: [PATCH 2/7] Move under CoreLib and use #if SYSTEM_PRIVATE_CORELIB --- eng/generators.targets | 4 ++-- .../src/System.Private.CoreLib.Shared.projitems | 16 ++++++---------- .../InteropServices/LibraryImportAttribute.cs | 2 +- .../Runtime/InteropServices/StringMarshalling.cs | 2 +- .../LibraryImportGenerator.csproj | 2 +- 5 files changed, 11 insertions(+), 15 deletions(-) rename src/libraries/{Common => System.Private.CoreLib}/src/System/Runtime/InteropServices/LibraryImportAttribute.cs (98%) rename src/libraries/{Common => System.Private.CoreLib}/src/System/Runtime/InteropServices/StringMarshalling.cs (95%) diff --git a/eng/generators.targets b/eng/generators.targets index 0d294625736f0..24c5c2db8d8ac 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -47,9 +47,9 @@ + Include="$(CoreLibSharedDir)System\Runtime\InteropServices\LibraryImportAttribute.cs" /> + Include="$(CoreLibSharedDir)System\Runtime\InteropServices\StringMarshalling.cs" /> diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index eafa6d603abf8..eca235469d854 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -845,17 +845,16 @@ + - - - - + + @@ -869,10 +868,13 @@ + + + @@ -1248,12 +1250,6 @@ Common\System\Runtime\CompilerServices\IsExternalInit.cs - - Common\System\Runtime\InteropServices\LibraryImportAttribute.cs - - - Common\System\Runtime\InteropServices\StringMarshalling.cs - Common\System\Runtime\Versioning\NonVersionableAttribute.cs diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs similarity index 98% rename from src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs index 622460303145c..b242d52bcd280 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/LibraryImportAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs @@ -10,7 +10,7 @@ namespace System.Runtime.InteropServices /// arguments instead of relying on the CLR to generate an IL Stub at runtime. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -#if NET7_0_OR_GREATER +#if SYSTEM_PRIVATE_CORELIB public #else internal diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/StringMarshalling.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs similarity index 95% rename from src/libraries/Common/src/System/Runtime/InteropServices/StringMarshalling.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs index f0274b3e9c1f2..50a099b41d38d 100644 --- a/src/libraries/Common/src/System/Runtime/InteropServices/StringMarshalling.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs @@ -9,7 +9,7 @@ namespace System.Runtime.InteropServices /// /// Specifies how strings should be marshalled for generated p/invokes /// -#if NET7_0_OR_GREATER +#if SYSTEM_PRIVATE_CORELIB public #else internal diff --git a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj index f2f1c273e5d43..467bf762702b2 100644 --- a/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj +++ b/src/libraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.csproj @@ -27,7 +27,7 @@ - + From 3085ad2ca8383209cdf4e125c5b33f39909c2094 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Wed, 9 Mar 2022 22:01:15 -0800 Subject: [PATCH 3/7] Move IsExternalInit, ExcludeFromCodeCoverageAttribute, and ReferenceEqualityComparer under CoreLib --- .../tests/Microsoft.CSharp.Tests.csproj | 4 ++-- .../tests/Microsoft.VisualBasic.Core.Tests.csproj | 2 +- .../ref/System.Diagnostics.DiagnosticSource.csproj | 2 +- .../src/System.Diagnostics.DiagnosticSource.csproj | 2 +- .../src/System.Private.CoreLib.Shared.projitems | 12 +++--------- .../Collections/Generic/ReferenceEqualityComparer.cs | 0 .../CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs | 7 +------ .../Runtime/CompilerServices/IsExternalInit.cs | 0 ...tem.Runtime.Serialization.Formatters.Tests.csproj | 2 +- .../gen/System.Text.Json.SourceGeneration.targets | 2 +- .../System.Text.Json/ref/System.Text.Json.csproj | 2 +- .../System.Text.Json/src/System.Text.Json.csproj | 4 ++-- .../System.Text.Json.Tests.csproj | 2 +- .../System.Text.RegularExpressions.Generator.csproj | 2 +- 14 files changed, 16 insertions(+), 27 deletions(-) rename src/libraries/{Common => System.Private.CoreLib}/src/System/Collections/Generic/ReferenceEqualityComparer.cs (100%) rename src/libraries/{Common => System.Private.CoreLib}/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs (84%) rename src/libraries/{Common => System.Private.CoreLib}/src/System/Runtime/CompilerServices/IsExternalInit.cs (100%) diff --git a/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj b/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj index fd58dca4e44f6..9e53ca9054a44 100644 --- a/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj +++ b/src/libraries/Microsoft.CSharp/tests/Microsoft.CSharp.Tests.csproj @@ -2,7 +2,7 @@ true $(NetCoreAppCurrent);net48 - @@ -11,7 +11,7 @@ true - + diff --git a/src/libraries/Microsoft.VisualBasic.Core/tests/Microsoft.VisualBasic.Core.Tests.csproj b/src/libraries/Microsoft.VisualBasic.Core/tests/Microsoft.VisualBasic.Core.Tests.csproj index d1664887f0648..89daad4c67319 100644 --- a/src/libraries/Microsoft.VisualBasic.Core/tests/Microsoft.VisualBasic.Core.Tests.csproj +++ b/src/libraries/Microsoft.VisualBasic.Core/tests/Microsoft.VisualBasic.Core.Tests.csproj @@ -4,7 +4,7 @@ $(NetCoreAppCurrent);net48 - + diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj index 26879046137d9..ec95328455059 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj +++ b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj @@ -15,7 +15,7 @@ - diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj index 374e595ad5bf5..2202413b9e98f 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj @@ -30,7 +30,7 @@ System.Diagnostics.DiagnosticSource - + diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index eca235469d854..a0f6850e5c790 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -208,6 +208,7 @@ + @@ -256,6 +257,7 @@ + @@ -732,6 +734,7 @@ + @@ -1232,24 +1235,15 @@ Common\System\Collections\Generic\EnumerableHelpers.cs - - Common\System\Collections\Generic\ReferenceEqualityComparer.cs - Common\System\Collections\Generic\BitHelper.cs - - Common\System\Diagnostics\CodeAnalysis\ExcludeFromCodeCoverageAttribute.cs - Common\System\IO\PathInternal.cs Common\System\IO\PathInternal.CaseSensitivity.cs - - Common\System\Runtime\CompilerServices\IsExternalInit.cs - Common\System\Runtime\Versioning\NonVersionableAttribute.cs diff --git a/src/libraries/Common/src/System/Collections/Generic/ReferenceEqualityComparer.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ReferenceEqualityComparer.cs similarity index 100% rename from src/libraries/Common/src/System/Collections/Generic/ReferenceEqualityComparer.cs rename to src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ReferenceEqualityComparer.cs diff --git a/src/libraries/Common/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs similarity index 84% rename from src/libraries/Common/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs index 7104270c2c5f6..fa8730a8eeb62 100644 --- a/src/libraries/Common/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/ExcludeFromCodeCoverageAttribute.cs @@ -4,12 +4,7 @@ namespace System.Diagnostics.CodeAnalysis { [AttributeUsageAttribute(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event, Inherited = false, AllowMultiple = false)] -#if SYSTEM_PRIVATE_CORELIB - public -#else - internal -#endif - sealed class ExcludeFromCodeCoverageAttribute : Attribute + public sealed class ExcludeFromCodeCoverageAttribute : Attribute { public ExcludeFromCodeCoverageAttribute() { } diff --git a/src/libraries/Common/src/System/Runtime/CompilerServices/IsExternalInit.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsExternalInit.cs similarity index 100% rename from src/libraries/Common/src/System/Runtime/CompilerServices/IsExternalInit.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsExternalInit.cs diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj b/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj index bb5a72a9fd280..378b38abb9353 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj +++ b/src/libraries/System.Runtime.Serialization.Formatters/tests/System.Runtime.Serialization.Formatters.Tests.csproj @@ -29,7 +29,7 @@ Link="Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs" /> - diff --git a/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.targets b/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.targets index f9e1d021b674b..511d36441af8d 100644 --- a/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.targets +++ b/src/libraries/System.Text.Json/gen/System.Text.Json.SourceGeneration.targets @@ -25,7 +25,7 @@ - + diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.csproj b/src/libraries/System.Text.Json/ref/System.Text.Json.csproj index a468f99d4e1bc..c24ada67e4cdb 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj index 1b9fbb39d7061..130c0c09289d4 100644 --- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj @@ -309,8 +309,8 @@ System.Text.Json.Nodes.JsonValue - - + + diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj index 546bdf6189e7e..c1a931d439062 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj @@ -206,7 +206,7 @@ - + diff --git a/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj b/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj index 409d24373f5c4..b032ce0529574 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj +++ b/src/libraries/System.Text.RegularExpressions/gen/System.Text.RegularExpressions.Generator.csproj @@ -23,7 +23,7 @@ - + From 76898f86f1337f3f4a23e1ef3e039396ce3d777f Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 10 Mar 2022 09:06:42 -0800 Subject: [PATCH 4/7] Apply suggestions from code review Co-authored-by: Jan Kotas Co-authored-by: Stephen Toub --- .../System.Diagnostics.DiagnosticSource.csproj | 3 +-- .../System.Diagnostics.DiagnosticSource.csproj | 2 +- .../InteropServices/LibraryImportAttribute.cs | 18 +++++++++--------- .../ref/System.Text.Json.csproj | 2 +- .../src/System.Text.Json.csproj | 4 ++-- .../System.Text.Json.Tests.csproj | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj index ec95328455059..1bbb59baf3ead 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj +++ b/src/libraries/System.Diagnostics.DiagnosticSource/ref/System.Diagnostics.DiagnosticSource.csproj @@ -15,8 +15,7 @@ - + diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj index 2202413b9e98f..e16a0b83f2eb1 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System.Diagnostics.DiagnosticSource.csproj @@ -30,7 +30,7 @@ System.Diagnostics.DiagnosticSource - + diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs index b242d52bcd280..3272ab986d989 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs @@ -6,8 +6,8 @@ namespace System.Runtime.InteropServices { /// - /// Attribute used to indicate a Source Generator should create a function for marshaling - /// arguments instead of relying on the CLR to generate an IL Stub at runtime. + /// Attribute used to indicate a source generator should create a function for marshaling + /// arguments instead of relying on the runtime to generate an equivalent marshaling function at run-time. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] #if SYSTEM_PRIVATE_CORELIB @@ -20,24 +20,24 @@ sealed class LibraryImportAttribute : Attribute /// /// Initializes a new instance of the . /// - /// Name of the library containing the import + /// Name of the library containing the import. public LibraryImportAttribute(string libraryName) { LibraryName = libraryName; } /// - /// Library to load. + /// Gets the name of the library containing the import. /// - public string LibraryName { get; private set; } + public string LibraryName { get; } /// - /// Indicates the name of the entry point to be called. + /// Gets or sets the name of the entry point to be called. /// public string? EntryPoint { get; set; } /// - /// Indicates how to marshal string parameters to the method. + /// Gets or sets how to marshal string arguments to the method. /// /// /// If this field is set to a value other than , @@ -46,7 +46,7 @@ public LibraryImportAttribute(string libraryName) public StringMarshalling StringMarshalling { get; set; } /// - /// Indicates how to marshal string parameters to the method. + /// Gets or sets the used to control how string arguments to the method are marshalled. /// /// /// If this field is specified, must not be specified @@ -55,7 +55,7 @@ public LibraryImportAttribute(string libraryName) public Type? StringMarshallingCustomType { get; set; } /// - /// Indicates whether the callee sents an error (SetLastError on Windows or errorno + /// Gets or sets whether the callee sets an error (SetLastError on Windows or errno /// on other platforms) before returning from the attributed method. /// public bool SetLastError { get; set; } diff --git a/src/libraries/System.Text.Json/ref/System.Text.Json.csproj b/src/libraries/System.Text.Json/ref/System.Text.Json.csproj index c24ada67e4cdb..a1c4a020c1619 100644 --- a/src/libraries/System.Text.Json/ref/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/ref/System.Text.Json.csproj @@ -14,7 +14,7 @@ - + diff --git a/src/libraries/System.Text.Json/src/System.Text.Json.csproj b/src/libraries/System.Text.Json/src/System.Text.Json.csproj index 130c0c09289d4..d3cbae4810f6a 100644 --- a/src/libraries/System.Text.Json/src/System.Text.Json.csproj +++ b/src/libraries/System.Text.Json/src/System.Text.Json.csproj @@ -309,8 +309,8 @@ System.Text.Json.Nodes.JsonValue - - + + diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj index c1a931d439062..6e02dce964476 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/System.Text.Json.Tests.csproj @@ -206,7 +206,7 @@ - + From 9b8a55350bd62ad187562576e3ce8c5cddbe5977 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Thu, 10 Mar 2022 09:21:49 -0800 Subject: [PATCH 5/7] Apply suggestions from code review --- .../System/Runtime/InteropServices/LibraryImportAttribute.cs | 5 +++++ .../ref/System.Runtime.InteropServices.cs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs index 3272ab986d989..c047c406afd5e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs @@ -9,6 +9,11 @@ namespace System.Runtime.InteropServices /// Attribute used to indicate a source generator should create a function for marshaling /// arguments instead of relying on the runtime to generate an equivalent marshaling function at run-time. /// + /// + /// This attribute is meaningless if the source generator associated with it is not enabled. + /// The associated source generator only supports C# and only supplies an implementation when + /// applied to static, partial, non-generic methods. + /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] #if SYSTEM_PRIVATE_CORELIB public diff --git a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs index b16cd4b6b65ad..72b9191fd8836 100644 --- a/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs +++ b/src/libraries/System.Runtime.InteropServices/ref/System.Runtime.InteropServices.cs @@ -491,8 +491,8 @@ public LibraryImportAttribute(string libraryName) { } public string LibraryName { get { throw null; } } public string? EntryPoint { get { throw null; } set { } } public bool SetLastError { get { throw null; } set { }} - public StringMarshalling StringMarshalling { get { throw null; } set { } } - public Type? StringMarshallingCustomType { get { throw null; } set { } } + public System.Runtime.InteropServices.StringMarshalling StringMarshalling { get { throw null; } set { } } + public System.Type? StringMarshallingCustomType { get { throw null; } set { } } } [System.AttributeUsageAttribute(System.AttributeTargets.Method, Inherited=false, AllowMultiple=false)] public sealed partial class ManagedToNativeComInteropStubAttribute : System.Attribute From 323a16179ca1ad845ae9d0f64a2004d587e6cf82 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 14 Mar 2022 16:42:07 -0700 Subject: [PATCH 6/7] Apply suggestions from code review Co-authored-by: Aaron Robinson --- .../Runtime/InteropServices/LibraryImportAttribute.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs index c047c406afd5e..7a53ade8da8d7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/LibraryImportAttribute.cs @@ -6,12 +6,12 @@ namespace System.Runtime.InteropServices { /// - /// Attribute used to indicate a source generator should create a function for marshaling - /// arguments instead of relying on the runtime to generate an equivalent marshaling function at run-time. + /// Attribute used to indicate a source generator should create a function for marshalling + /// arguments instead of relying on the runtime to generate an equivalent marshalling function at run-time. /// /// /// This attribute is meaningless if the source generator associated with it is not enabled. - /// The associated source generator only supports C# and only supplies an implementation when + /// The current built-in source generator only supports C# and only supplies an implementation when /// applied to static, partial, non-generic methods. /// [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] From 60d5416a8d76a46d58715503726dfacefab45e50 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 15 Mar 2022 12:51:59 -0700 Subject: [PATCH 7/7] Add test --- ...ystem.Runtime.InteropServices.Tests.csproj | 1 + .../LibraryImportAttributeTests.cs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/LibraryImportAttributeTests.cs diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj index 072080790a255..46d0d5d3a6e87 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System.Runtime.InteropServices.Tests.csproj @@ -48,6 +48,7 @@ + diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/LibraryImportAttributeTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/LibraryImportAttributeTests.cs new file mode 100644 index 0000000000000..1ebda2c88832a --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/LibraryImportAttributeTests.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +namespace System.Runtime.InteropServices.Tests +{ + public class LibraryImportAttributeTests + { + [Theory] + [InlineData(null)] + [InlineData("LibraryName")] + public void Ctor(string libraryName) + { + var attribute = new LibraryImportAttribute(libraryName); + Assert.Equal(libraryName, attribute.LibraryName); + } + } +}