[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:
Manuel de la Pena 2023-02-14 10:18:48 -05:00 коммит произвёл GitHub
Родитель 30f5169b46
Коммит 17e8200b30
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 29 добавлений и 23 удалений

Просмотреть файл

@ -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" />