Added dynamic method builder for member values

このコミットが含まれているのは:
Sergio Pedri committed 2019-09-15 13:48:46 +02:00
1 親 a03133e756
コミット 12e56b8a0f
2ファイル変更
+74 -15

検索条件に一致するファイルはありません

+7 -15
ファイルの表示
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics.Contracts;
using System.Reflection;
namespace ComputeSharp.Shaders.Translation.Models
@@ -7,8 +6,13 @@ namespace ComputeSharp.Shaders.Translation.Models
/// <summary>
/// A <see langword="class"/> that wraps a readable member of another <see langword="class"/> and provides access to it
/// </summary>
internal sealed class ReadableMember
internal sealed partial class ReadableMember
{
/// <summary>
/// The id of the current member
/// </summary>
private readonly string Id;
/// <summary>
/// The <see cref="FieldInfo"/> object wrapped by the current instance, if present
/// </summary>
@@ -28,6 +32,7 @@ namespace ComputeSharp.Shaders.Translation.Models
{
Field = field;
Property = property;
Id = $"{DeclaringType.FullName}{Type.Delimiter}{Name}".Replace(Type.Delimiter, '_');
}
/// <summary>
@@ -63,19 +68,6 @@ namespace ComputeSharp.Shaders.Translation.Models
/// </summary>
public string Name => (Field?.Name ?? Property?.Name) ?? throw new InvalidOperationException("Field and property can't both be null at the same time");
/// <summary>
/// Returns the value of the wrapped member for the current instance
/// </summary>
/// <param name="instance">The target instance to use to read the value from</param>
[Pure]
public object GetValue(object? instance)
{
if (Field != null) return Field.GetValue(instance);
if (Property != null) return Property.GetValue(instance);
throw new InvalidOperationException("Field and property can't both be null at the same time");
}
/// <summary>
/// Converts a <see cref="FieldInfo"/> object into a <see cref="ReadableMember"/> instance
/// </summary>