diff --git a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.GetValue.cs b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.GetValue.cs index 70b97559..f34ec613 100644 --- a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.GetValue.cs +++ b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.GetValue.cs @@ -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 diff --git a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs index 4fbd6b79..9883fd52 100644 --- a/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs +++ b/src/ComputeSharp.Shaders/Translation/Models/ReadableMember.cs @@ -26,72 +26,60 @@ namespace ComputeSharp.Shaders.Translation.Models /// /// Creates a new instance with the given parameters /// - /// The optional object wrapped by the current instance - /// The optional object wrapped by the current instance - private ReadableMember(FieldInfo? field, PropertyInfo? property) + /// The target object wrapped by the current instance + 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; - /// - /// Gets the where the current member is declared in - /// - 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; } - } - - /// - /// Gets the of the wrapped member for the current instance - /// - 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"); } /// /// Gets the name of the wrapped member for the current instance /// - 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; } /// /// Gets whether or not the current member is not an instance member /// - 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"); - } - } + /// + /// Gets the where the current member is declared in + /// + public Type DeclaringType { get; } + + /// + /// Gets the of the wrapped member for the current instance + /// + public Type MemberType { get; } /// /// Converts a object into a instance /// /// The input object to wrap - public static implicit operator ReadableMember(FieldInfo field) => new ReadableMember(field, null); + public static implicit operator ReadableMember(FieldInfo field) => new ReadableMember(field); /// /// Converts a object into a instance /// /// The input object to wrap - public static implicit operator ReadableMember(PropertyInfo property) => new ReadableMember(null, property); + public static implicit operator ReadableMember(PropertyInfo property) => new ReadableMember(property); } }