internal static Type FindTarget(Type consumer) { foreach (object attribute in consumer.GetCustomAttributes(typeof(TargetTypeAttribute), true)) { TargetTypeAttribute targetAttribute = attribute as TargetTypeAttribute; if (targetAttribute != null) { return(targetAttribute.target); } } throw new InvalidOperationException("No constraint Target is defined for the consumer Type :" + consumer); }
public List <Type> CheckConstraints(Type t) { List <Type> types = new List <Type>(); foreach (PropertyDescriptor prop in DiscoverableInputHelper.GetInputProperties(t)) { Trace.WriteLine(String.Format("[ConstraintsTable] Checking Property Constraint {0} on {1}.", prop.Name, t)); Type inputType = prop.PropertyType; if (prop.Attributes.Contains(InputAttribute.CreateFromConstraints)) { ConstrainedDataSource datasource = Get(TargetTypeAttribute.FindTarget(t), prop.Name); if (null == datasource) { throw new InvalidOperationException("Missing constraint entry for" + t + " property: " + prop.Name); } else { datasource.Validate(); } } } return(types); }