Minor optimizations to the ReadableMember class
このコミットが含まれているのは:
1 親
7e2274219a
コミット
871b748723
2ファイル変更
+30
-42
検索条件に一致するファイルはありません
@@ -42,7 +42,7 @@ namespace ComputeSharp.Shaders.Translation.Models
|
||||
private Getter BuildDynamicGetter()
|
||||
{
|
||||
// Create a new dynamic method for the current member
|
||||
DynamicMethod method = new DynamicMethod($"Get{Id}", typeof(object), new[] { typeof(object) }, DeclaringType);
|
||||
DynamicMethod method = new DynamicMethod($"Get{Name}", typeof(object), new[] { typeof(object) }, DeclaringType);
|
||||
ILGenerator il = method.GetILGenerator();
|
||||
|
||||
// Load the argument (the object instance) and cast it to the right type, if needed
|
||||
|
||||
@@ -26,72 +26,60 @@ namespace ComputeSharp.Shaders.Translation.Models
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ReadableMember"/> instance with the given parameters
|
||||
/// </summary>
|
||||
/// <param name="field">The optional <see cref="FieldInfo"/> object wrapped by the current instance</param>
|
||||
/// <param name="property">The optional <see cref="PropertyInfo"/> object wrapped by the current instance</param>
|
||||
private ReadableMember(FieldInfo? field, PropertyInfo? property)
|
||||
/// <param name="memberInfo">The target <see cref="MemberInfo"/> object wrapped by the current instance</param>
|
||||
private ReadableMember(MemberInfo memberInfo)
|
||||
{
|
||||
Field = field;
|
||||
Property = property;
|
||||
Id = $"{DeclaringType.FullName}{Type.Delimiter}{Name}".Replace(Type.Delimiter, '_');
|
||||
}
|
||||
// General properties
|
||||
Name = memberInfo.Name;
|
||||
Id = $"{memberInfo.DeclaringType.FullName}{Type.Delimiter}{Name}";
|
||||
DeclaringType = memberInfo.DeclaringType;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Type"/> where the current member is declared in
|
||||
/// </summary>
|
||||
public Type DeclaringType
|
||||
{
|
||||
get
|
||||
// Type specific properties
|
||||
if (memberInfo is FieldInfo fieldInfo)
|
||||
{
|
||||
if (Field != null) return Field.DeclaringType;
|
||||
if (Property != null) return Property.DeclaringType;
|
||||
|
||||
throw new InvalidOperationException("Field and property can't both be null at the same time");
|
||||
Field = fieldInfo;
|
||||
IsStatic = Field.IsStatic;
|
||||
MemberType = Field.FieldType;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Type"/> of the wrapped member for the current instance
|
||||
/// </summary>
|
||||
public Type MemberType
|
||||
{
|
||||
get
|
||||
else if (memberInfo is PropertyInfo propertyInfo)
|
||||
{
|
||||
if (Field != null) return Field.FieldType;
|
||||
if (Property != null) return Property.PropertyType;
|
||||
|
||||
throw new InvalidOperationException("Field and property can't both be null at the same time");
|
||||
Property = propertyInfo;
|
||||
IsStatic = Property.GetMethod.IsStatic;
|
||||
MemberType = Property.PropertyType;
|
||||
}
|
||||
else throw new InvalidOperationException("Field and property can't both be null at the same time");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the wrapped member for the current instance
|
||||
/// </summary>
|
||||
public string Name => (Field?.Name ?? Property?.Name) ?? throw new InvalidOperationException("Field and property can't both be null at the same time");
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the current member is not an instance member
|
||||
/// </summary>
|
||||
public bool IsStatic
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Field != null) return Field.IsStatic;
|
||||
if (Property != null) return Property.GetMethod.IsStatic;
|
||||
public bool IsStatic { get; }
|
||||
|
||||
throw new InvalidOperationException("Field and property can't both be null at the same time");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Type"/> where the current member is declared in
|
||||
/// </summary>
|
||||
public Type DeclaringType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Type"/> of the wrapped member for the current instance
|
||||
/// </summary>
|
||||
public Type MemberType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="FieldInfo"/> object into a <see cref="ReadableMember"/> instance
|
||||
/// </summary>
|
||||
/// <param name="field">The input <see cref="FieldInfo"/> object to wrap</param>
|
||||
public static implicit operator ReadableMember(FieldInfo field) => new ReadableMember(field, null);
|
||||
public static implicit operator ReadableMember(FieldInfo field) => new ReadableMember(field);
|
||||
|
||||
/// <summary>
|
||||
/// Converts a <see cref="PropertyInfo"/> object into a <see cref="ReadableMember"/> instance
|
||||
/// </summary>
|
||||
/// <param name="property">The input <see cref="PropertyInfo"/> object to wrap</param>
|
||||
public static implicit operator ReadableMember(PropertyInfo property) => new ReadableMember(null, property);
|
||||
public static implicit operator ReadableMember(PropertyInfo property) => new ReadableMember(property);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする