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); }
public Preferences(IStorageHandler storageHandler, params object[] rawpreferences) { _storageHandler = storageHandler; foreach (object rawPreference in rawpreferences) { PropertyInfo[] properties = rawPreference.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (PropertyInfo propertyInfo in properties) { if (!propertyInfo.CanRead || !propertyInfo.CanWrite) { continue; } else if (Preference.TryInvestigate(propertyInfo, rawPreference, out var itemToAttatch)) { _preferences.Add(itemToAttatch.Name, itemToAttatch); } } } }