[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class TypeConditionAttribute<TValue> : Attribute
{
/// <summary>
/// The field name of type field
/// </summary>
public string TypeField { get; set; }
public TValue Value { get; set; }
public TypeConditionAttribute(string typeField, TValue value)
{
TypeField = typeField;
Value = value;
}
public bool Evaluate(object record)
{
FieldInfo fieldInfo = record.GetType().GetField(TypeField);
object value = fieldInfo.GetValue(record);
return this.Value.Equals((TValue)value);
}
}