private static Type GetPropertyDataType(BusinessRuleProperty target, out string assemblyQualifiedName, out string editor) { editor = typeof(UITypeEditor).AssemblyQualifiedName; Type propType; if (target.IsGenericType || target.IsGenericParameter || target.Type == "IComparable" || target.Type.LastIndexOf("[]") == target.Type.Length - 2) { propType = Type.GetType("System.String"); } else { propType = Type.GetType(target.Type); if (propType == null) { propType = Type.GetType("System." + target.Type); } if (propType == null) { propType = Type.GetType("CslaGenerator.Metadata." + target.Type); } } if (propType == null) { assemblyQualifiedName = string.Empty; } else { assemblyQualifiedName = propType.AssemblyQualifiedName; } return(propType); }
public static Type GetDataType(BusinessRuleProperty target, out string assemblyQualifiedName, out string editor) { editor = typeof(UITypeEditor).AssemblyQualifiedName; Type propType; if (target.IsGenericType || target.IsGenericParameter) { propType = Type.GetType("System.String"); } else { propType = Type.GetType(target.Type); if (propType == null) { propType = Type.GetType("System." + target.Type); } if (propType == null) { propType = Type.GetType("CslaGenerator.Metadata." + target.Type); } } if (propType == null) { assemblyQualifiedName = string.Empty; } else { assemblyQualifiedName = propType.AssemblyQualifiedName; } return(propType); }
private void FillSubsidiaryGrids(BusinessRule rule, string stringType) { Type usedType = null; if (stringType != "(None)") { foreach (var baseType in _baseTypes) { if (baseType.TypeName == StripKnownNamespaces(_sizeSortedNamespaces, stringType)) { usedType = baseType.Type; } } } if (usedType == null) { if (rule.BaseRuleProperties.Count > 0) { rule.BaseRuleProperties.RemoveRange(0, rule.BaseRuleProperties.Count); } if (rule.RuleProperties.Count > 0) { rule.RuleProperties.RemoveRange(0, rule.RuleProperties.Count); } if (rule.Constructors.Count > 0) { foreach (BusinessRuleConstructor constructor in rule.Constructors) { if (constructor.ConstructorParameters.Count > 0) { constructor.ConstructorParameters.RemoveRange(0, constructor.ConstructorParameters.Count); } } rule.Constructors.RemoveRange(0, rule.Constructors.Count); } return; } #region Base Rule Properties rule.BaseRuleProperties = new List <string>(); foreach (var baseType in _baseTypes) { if (baseType.Type != usedType) { continue; } foreach (var prop in baseType.BaseType.GetProperties(BindingFlags.Instance | BindingFlags.Public). Where(p => p.CanRead && p.GetSetMethod() != null)) { if (!prop.GetSetMethod().IsPublic) { continue; } rule.BaseRuleProperties.Add(prop.Name); } } // PrimaryProperty always shows in baseType.BaseType.GetProperties() #endregion #region Business Rule Properties rule.RuleProperties = new BusinessRulePropertyCollection(); foreach (var prop in usedType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly). Where(p => p.CanRead && p.GetSetMethod() != null)) { /*if(prop.PropertyType.IsGenericParameter) * { * var a = "IsGenericParameter"; * } * if(prop.PropertyType.IsGenericTypeDefinition) * { * var c = "IsGenericTypeDefinition"; * } * if (prop.PropertyType.Name.IndexOf('`') > 0) * { * var d = "IsGenericTypeDefinition"; * }*/ if (!prop.GetSetMethod().IsPublic) { continue; } if (!rule.BaseRuleProperties.Contains(prop.Name)) { var ruleInfo = new BusinessRuleProperty(); ruleInfo.Name = prop.Name; ruleInfo.Type = prop.PropertyType.Name; ruleInfo.IsGenericType = prop.PropertyType.IsGenericParameter; ruleInfo.IsGenericParameter = prop.PropertyType.IsGenericType; if (ruleInfo.IsGenericParameter) { ruleInfo.Type = prop.PropertyType.Name.Substring(0, prop.PropertyType.Name.LastIndexOf('`')); foreach (var argument in prop.PropertyType.GetGenericArguments()) { ruleInfo.Type += "<" + argument.Name + ">"; } } Type targetType = GetDataType(ruleInfo.Type); if (targetType != null) { if (targetType.IsEnum) { ruleInfo.Value = ConvertStringToEnum(targetType, ""); } else if (targetType == typeof(Int16)) { ruleInfo.Value = (Int16)0; } else if (targetType == typeof(Int32)) { ruleInfo.Value = (Int32)0; } else if (targetType == typeof(Int64)) { ruleInfo.Value = (Int64)0; } } else { ruleInfo.Value = " "; ruleInfo.Value = string.Empty; } rule.RuleProperties.Add(ruleInfo); } } #endregion #region Contructors rule.Constructors = new BusinessRuleConstructorCollection(); var ctor = usedType.GetConstructors(); var ctorCounter = 0; var isSetActive = false; foreach (var info in ctor) { var primaryPropertyFound = false; var ctorInfo = new BusinessRuleConstructor(); var ctorParams = info.GetParameters(); foreach (var param in ctorParams) { var ctorParamInfo = new BusinessRuleConstructorParameter(); ctorParamInfo.Name = param.Name; ctorParamInfo.Type = param.ParameterType.Name; var attributeData = param.GetCustomAttributesData(); foreach (var attribute in attributeData) { if (attribute.ToString() == "[System.ParamArrayAttribute()]") { ctorParamInfo.IsParams = true; } } ctorParamInfo.IsGenericType = param.ParameterType.IsGenericParameter; ctorParamInfo.IsGenericParameter = param.ParameterType.IsGenericType; if (ctorParamInfo.IsGenericParameter) { ctorParamInfo.Type = param.ParameterType.Name.Substring(0, param.ParameterType.Name.LastIndexOf('`')); foreach (var argument in param.ParameterType.GetGenericArguments()) { ctorParamInfo.Type += "<" + argument.Name + ">"; } } if (ctorParamInfo.Type == "IPropertyInfo" && ctorParamInfo.Name == "primaryProperty") { ctorParamInfo.Value = rule.Parent; primaryPropertyFound = true; } else { Type targetType = GetDataType(ctorParamInfo.Type); if (targetType != null) { if (targetType.IsEnum) { ctorParamInfo.Value = ConvertStringToEnum(targetType, ""); } else if (targetType == typeof(Int16)) { ctorParamInfo.Value = (Int16)0; } else if (targetType == typeof(Int32)) { ctorParamInfo.Value = (Int32)0; } else if (targetType == typeof(Int64)) { ctorParamInfo.Value = (Int64)0; } } else { ctorParamInfo.Value = " "; ctorParamInfo.Value = string.Empty; } } ctorInfo.ConstructorParameters.Add(ctorParamInfo); } if (rule.IsPropertyRule && !primaryPropertyFound) { continue; } if (!rule.IsPropertyRule && primaryPropertyFound) { continue; } ctorCounter++; ctorInfo.Name = "Constructor #" + ctorCounter; if (!isSetActive) { ctorInfo.IsActive = true; ctorInfo.Name += " (Active)"; isSetActive = true; } rule.Constructors.Add(ctorInfo); } #endregion }
private void InitPropertyBag() { PropertyInfo pi; Type t = typeof(BusinessRuleProperty); // _selectedObject.GetType(); PropertyInfo[] props = t.GetProperties(); // Display information for all properties. for (int i = 0; i < props.Length; i++) { pi = props[i]; object[] myAttributes = pi.GetCustomAttributes(true); string category = ""; string description = ""; bool isreadonly = false; bool isbrowsable = true; object defaultvalue = null; string userfriendlyname = ""; string typeconverter = ""; string designertypename = ""; string helptopic = ""; bool bindable = true; string editor = ""; string assemblyQualifiedName = ""; for (int n = 0; n < myAttributes.Length; n++) { var a = (Attribute)myAttributes[n]; switch (a.GetType().ToString()) { case "System.ComponentModel.CategoryAttribute": category = ((CategoryAttribute)a).Category; break; case "System.ComponentModel.DescriptionAttribute": description = ((DescriptionAttribute)a).Description; break; case "System.ComponentModel.ReadOnlyAttribute": isreadonly = ((ReadOnlyAttribute)a).IsReadOnly; break; case "System.ComponentModel.BrowsableAttribute": isbrowsable = ((BrowsableAttribute)a).Browsable; break; case "System.ComponentModel.DefaultValueAttribute": defaultvalue = ((DefaultValueAttribute)a).Value; break; case "CslaGenerator.Attributes.UserFriendlyNameAttribute": userfriendlyname = ((UserFriendlyNameAttribute)a).UserFriendlyName; break; case "CslaGenerator.Attributes.HelpTopicAttribute": helptopic = ((HelpTopicAttribute)a).HelpTopic; break; case "System.ComponentModel.TypeConverterAttribute": typeconverter = ((TypeConverterAttribute)a).ConverterTypeName; break; case "System.ComponentModel.DesignerAttribute": designertypename = ((DesignerAttribute)a).DesignerTypeName; break; case "System.ComponentModel.BindableAttribute": bindable = ((BindableAttribute)a).Bindable; break; case "System.ComponentModel.EditorAttribute": editor = ((EditorAttribute)a).EditorTypeName; break; } } BusinessRuleProperty target = SelectedObject[0]; if (pi.Name != "Value") { isbrowsable = false; } else { userfriendlyname = target.Name; description = (target.IsGenericType ? "Generic " : "") + "Property " + userfriendlyname + " of " + (target.IsGenericType ? "<" : "") + target.Type + (target.IsGenericType ? ">" : "") + " type."; if (target.Name == "PrimaryProperty") { isreadonly = true; } switch (target.Type) { case "IPropertyInfo": break; default: GetDataType(target, out assemblyQualifiedName, out editor); break; } } userfriendlyname = userfriendlyname.Length > 0 ? userfriendlyname : pi.Name; var types = new List <string>(); foreach (var obj in _selectedObject) { if (!types.Contains(obj.Name)) { types.Add(obj.Name); } } // here get rid of ComponentName and Parent bool isValidProperty = (pi.Name != "Properties" && pi.Name != "ComponentName" && pi.Name != "Parent"); if (isValidProperty && IsBrowsable(types.ToArray(), pi.Name)) { if (assemblyQualifiedName == string.Empty) { assemblyQualifiedName = pi.PropertyType.AssemblyQualifiedName; } // CR added missing parameters //this.Properties.Add(new PropertySpec(userfriendlyname,pi.PropertyType.AssemblyQualifiedName,category,description,defaultvalue, editor, typeconverter, _selectedObject, pi.Name,helptopic)); Properties.Add(new PropertySpec(userfriendlyname, assemblyQualifiedName, category, description, defaultvalue, editor, typeconverter, _selectedObject, pi.Name, helptopic, isreadonly, isbrowsable, designertypename, bindable)); } } }
public BusinessRulePropertyBag(BusinessRuleProperty obj) : this(new[] { obj }) { }