/// <summary> /// Analyse class and save analyse into dictionary /// </summary> /// <param name="analysedClass">Type of class to by analysed</param> private void DoAnalysis(Type analysedClass) { Dictionary <string, PropertyAnalyze> analysedClassDictionary = new Dictionary <string, PropertyAnalyze>(); List <Type> linkedTablesRelations = new List <Type>(); foreach (var prop in analysedClass.GetProperties()) { var attributes = prop.GetCustomAttributes(true).ToList(); if (attributes.Contains(typeof(DbIgnoreAttribute)) && attributes.Contains(typeof(LinkedTableAttribute))) { throw new NotSupportedAttributeCombinationException("Linked tables properties can't be ignored in DB."); } LinkedTableAttribute linkedTableInfo = attributes.FirstOrDefault(x => x.GetType() == typeof(LinkedTableAttribute)) as LinkedTableAttribute; if (linkedTableInfo != null) { if ((linkedTableInfo.LinkedTableRelation == Enum.LinkedTableRelation.Many && prop.PropertyType != typeof(List <int>)) || (linkedTableInfo.LinkedTableRelation == Enum.LinkedTableRelation.One && prop.PropertyType != typeof(int))) { throw new NotSupportedAttributeCombinationException("Property type can't be used with this type of Linked Table attribute"); } if (linkedTablesRelations.Contains(linkedTableInfo.LinkedTableType)) { throw new NotSupportedAttributeCombinationException("Only one linked table relation for linked table."); } else { linkedTablesRelations.Add(linkedTableInfo.LinkedTableType); } } UIParamsAttribute uiParams = attributes.FirstOrDefault(x => x.GetType() == typeof(UIParamsAttribute)) as UIParamsAttribute; if (uiParams != null && string.IsNullOrEmpty(uiParams.LabelDescription) && uiParams.UseLabelDescription) { throw new NotSupportedAttributeCombinationException("UIParams attribute must specify LabelDescription if UseLabelDescription is true."); } var analyze = new PropertyAnalyze(prop.Name, prop.PropertyType, attributes); analysedClassDictionary.Add(prop.Name, analyze); } analysedClassesDictionary.Add(analysedClass, analysedClassDictionary); }
/// <summary> /// Init Linked table selector for multi values /// </summary> /// <param name="controlName">Control name</param> /// <param name="controlData">Control data</param> /// <param name="linkedTableAttribute">Attributes of property</param> public LinkedTableMultiSelectorControl(string controlName, PropertyAnalyze controlData, LinkedTableAttribute linkedTableAttribute) { this.controlData = controlData; LinkedTableType = linkedTableAttribute.LinkedTableType; CreateUI(controlName, controlData); }
/// <summary> /// Create linked table control /// </summary> /// <param name="controlName">Control name</param> /// <param name="controlData">Control data</param> /// <param name="controlType">Control type</param> /// <param name="linkedTableAttribute">Linked table attributes</param> /// <returns>Created control</returns> public static UIElement CreateLinkedTableControl(string controlName, PropertyAnalyze controlData, PropertyType controlType, LinkedTableAttribute linkedTableAttribute) { if (controlData is null) { throw new Base.Exceptions.ArgumentNullException(nameof(controlData)); } if (controlType != PropertyType.Int && controlType != PropertyType.Int32) { throw new Base.Exceptions.ArgumentOutOfRangeException(nameof(controlData), "Type of linked table presenter property must be integer."); } if (!(controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(UIParamsAttribute)) is UIParamsAttribute customization)) { throw new MissingRequiredAdditionalDataException("Linked table property require UIParams attribute for specificating design."); } var control = new LinkedTableMultiSelectorControl(controlName, controlData, linkedTableAttribute) { Name = controlName + Constants.DATA_CONTROL_IDENTIFIER, Margin = new Thickness(10) }; return(control); }
/// <summary> /// Init linked table selector /// </summary> /// <param name="controlData">Control data</param> public LinkedTableSelector(PropertyAnalyze controlData) { linkedTableAttribute = controlData.PropertyAttributes.FirstOrDefault(x => x.GetType() == typeof(LinkedTableAttribute)) as LinkedTableAttribute; }