|
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace CodeSmith.Data.Rules
{
public abstract class PropertyRuleBase : IRule
{
protected PropertyRuleBase(string property)
{
TargetProperty = property;
}
protected PropertyRuleBase(string property, string message)
{
TargetProperty = property;
ErrorMessage = message;
}
public string TargetProperty { get; protected set; }
public string ErrorMessage { get; protected set; }
protected PropertyInfo GetPropertyInfo(object target)
{
return target.GetType().GetProperty(TargetProperty);
}
protected object GetPropertyValue(object target)
{
PropertyInfo propertyInfo = GetPropertyInfo(target);
if (propertyInfo == null)
return null;
return propertyInfo.GetValue(target, null);
}
protected T GetPropertyValue<T>(object target)
{
object value = GetPropertyValue(target);
return (value == null) ? default(T) : (T)value;
}
public abstract void Run(RuleContext context);
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.