[Generator] Move CustomAttributeDataExtensions to its own file and enable nullability. (#17526)
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com>
This commit is contained in:
Родитель
30f5169b46
Коммит
17e8200b30
|
@ -857,26 +857,3 @@ public static class EnumerableExtensions {
|
|||
yield return item;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomAttributeDataExtensions {
|
||||
#if !NET
|
||||
static Type roCustomAttributeDataType;
|
||||
static PropertyInfo attributeTypeProperty;
|
||||
|
||||
static CustomAttributeDataExtensions ()
|
||||
{
|
||||
roCustomAttributeDataType = typeof (MetadataLoadContext).Assembly.GetType ("System.Reflection.TypeLoading.RoCustomAttributeData");
|
||||
attributeTypeProperty = roCustomAttributeDataType.GetProperty ("AttributeType");
|
||||
}
|
||||
|
||||
public static Type GetAttributeType (this CustomAttributeData data)
|
||||
{
|
||||
// Workaround for CustomAttributeData.AttributeType not being declared as virtual in Mono
|
||||
if (data.GetType ().IsSubclassOf (roCustomAttributeDataType))
|
||||
return (Type) attributeTypeProperty.GetValue (data);
|
||||
return data.AttributeType;
|
||||
}
|
||||
#else
|
||||
public static Type GetAttributeType (this CustomAttributeData data) => data.AttributeType;
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
#nullable enable
|
||||
|
||||
public static class CustomAttributeDataExtensions {
|
||||
#if !NET
|
||||
static readonly Type roCustomAttributeDataType;
|
||||
static readonly PropertyInfo attributeTypeProperty;
|
||||
|
||||
static CustomAttributeDataExtensions ()
|
||||
{
|
||||
roCustomAttributeDataType = typeof (MetadataLoadContext).Assembly.GetType ("System.Reflection.TypeLoading.RoCustomAttributeData");
|
||||
attributeTypeProperty = roCustomAttributeDataType.GetProperty ("AttributeType")
|
||||
?? throw new InvalidOperationException ("Could not retrieve property 'AttributeType'.");
|
||||
}
|
||||
|
||||
public static Type GetAttributeType (this CustomAttributeData data)
|
||||
{
|
||||
// Workaround for CustomAttributeData.AttributeType not being declared as virtual in Mono
|
||||
if (data.GetType ().IsSubclassOf (roCustomAttributeDataType))
|
||||
return (Type) attributeTypeProperty.GetValue (data);
|
||||
return data.AttributeType;
|
||||
}
|
||||
#else
|
||||
public static Type GetAttributeType (this CustomAttributeData data) => data.AttributeType;
|
||||
#endif
|
||||
}
|
|
@ -97,6 +97,7 @@
|
|||
<Compile Include="..\src\bgen\AttributeManager.cs" />
|
||||
<Compile Include="..\src\bgen\Attributes.cs" />
|
||||
<Compile Include="..\src\bgen\BindingTouch.cs" />
|
||||
<Compile Include="..\src\bgen\CustomAttributeDataExtensions.cs" />
|
||||
<Compile Include="..\src\bgen\Enums.cs" />
|
||||
<Compile Include="..\src\bgen\ExtensionMethods.cs" />
|
||||
<Compile Include="..\src\bgen\Frameworks.cs" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче