60 lines
1.4 KiB
C#
Executable File
60 lines
1.4 KiB
C#
Executable File
using System.Reflection;
|
|
|
|
namespace Siggingway;
|
|
|
|
internal interface IFieldOrPropertyInfo {
|
|
string Name { get; }
|
|
|
|
Type ActualType { get; }
|
|
|
|
bool IsNullable { get; }
|
|
|
|
void SetValue(object? self, object? value);
|
|
|
|
T? GetCustomAttribute<T>() where T : Attribute;
|
|
}
|
|
|
|
internal sealed class FieldInfoWrapper : IFieldOrPropertyInfo {
|
|
private FieldInfo Info { get; }
|
|
|
|
public FieldInfoWrapper(FieldInfo info) {
|
|
this.Info = info;
|
|
}
|
|
|
|
public string Name => this.Info.Name;
|
|
|
|
public Type ActualType => this.Info.FieldType;
|
|
|
|
public bool IsNullable => NullabilityUtil.IsNullable(this.Info);
|
|
|
|
public void SetValue(object? self, object? value) {
|
|
this.Info.SetValue(self, value);
|
|
}
|
|
|
|
public T? GetCustomAttribute<T>() where T : Attribute {
|
|
return this.Info.GetCustomAttribute<T>();
|
|
}
|
|
}
|
|
|
|
internal sealed class PropertyInfoWrapper : IFieldOrPropertyInfo {
|
|
private PropertyInfo Info { get; }
|
|
|
|
public PropertyInfoWrapper(PropertyInfo info) {
|
|
this.Info = info;
|
|
}
|
|
|
|
public string Name => this.Info.Name;
|
|
|
|
public Type ActualType => this.Info.PropertyType;
|
|
|
|
public bool IsNullable => NullabilityUtil.IsNullable(this.Info);
|
|
|
|
public void SetValue(object? self, object? value) {
|
|
this.Info.SetValue(self, value);
|
|
}
|
|
|
|
public T? GetCustomAttribute<T>() where T : Attribute {
|
|
return this.Info.GetCustomAttribute<T>();
|
|
}
|
|
}
|