private Preference(object rawObj, PropertyInfo property, PreferenceCharacteristicsAttribute entry, PreferenceTypeAttribute type, PreferenceRelationAttribute relation) { _assembly = property.Module.Assembly; _preferenceCharasteristice = entry; _preferenceType = type; _propertyInfo = property; _object = rawObj; }
internal static bool TryInvestigate(PropertyInfo propertyInfo, object rawobj, out Preference itemToAttatch) { PreferenceCharacteristicsAttribute characteristics = null; PreferenceTypeAttribute type = null; PreferenceRelationAttribute relation = null; itemToAttatch = null; //Get the custom prperties of the the property var customAttributes = Attribute.GetCustomAttributes(propertyInfo).ToList(); foreach (Attribute customAttribute in customAttributes) { DetermineAttributeType(ref characteristics, ref type, ref relation, customAttribute); } //If the property has no characteristics it is not to be added. if (characteristics == null) { return(false); } //Try to get the Preference from the PropertyType if (type == null) { type = PreferenceTypeAttribute.TryGetPreferenceType(propertyInfo.PropertyType); } // if (type == null) { throw new PreferenceInvestigationException("There is no PreferenceTypeAttribute given for this Preference.", rawobj, propertyInfo); } if (!PreferenceTypeAttribute.IsSupportedType(propertyInfo.PropertyType)) { throw new PreferenceInvestigationException("The used PreferenceTypeAttribute (" + type.GetType().Name + ") " + "can not be used with with the type (" + propertyInfo.PropertyType + ").", rawobj, propertyInfo); } itemToAttatch = new Preference(rawobj, propertyInfo, characteristics, type, relation); return(true); }
private static void DetermineAttributeType(ref PreferenceCharacteristicsAttribute characteristics, ref PreferenceTypeAttribute type, ref PreferenceRelationAttribute relation, Attribute customAttribute) { if (customAttribute is IPreferenceCharacteristics) { if (@characteristics == null) { @characteristics = (PreferenceCharacteristicsAttribute)customAttribute; } else { throw new PreferenceAttributeParseException("Unerlaubter Mehrfach-Eintrag des SettingsEntry-Attributes", @characteristics); } } else if (customAttribute is PreferenceTypeAttribute) { if (@type == null) { @type = (PreferenceTypeAttribute)customAttribute; } else { throw new PreferenceAttributeParseException("Unerlaubter Mehrfach-Eintrag des SettingsType-Attributes", @type); } } else if (customAttribute == null) { if (@relation == null) { @relation = (PreferenceRelationAttribute)customAttribute; } else { throw new PreferenceAttributeParseException("Unerlaubter Mehrfach-Eintrag des SettingsType-Attributes", @relation); } } }
public PreferenceAttributeParseException(string message, PreferenceCharacteristicsAttribute characteristics) : base(message) { }