private ValueProperty ConvertToValueProperty(IManagedProperty property) { var valueProperty = new ValueProperty(); valueProperty.Name = property.Name; var propertyType = property.PropertyType; //处理可空类型 if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>)) { propertyType = propertyType.GetGenericArguments()[0]; valueProperty.Nullable = true; } if (propertyType == typeof(string)) { valueProperty.PropertyType = ValuePropertyType.String; } else if (propertyType == typeof(bool)) { valueProperty.PropertyType = ValuePropertyType.Boolean; } else if (propertyType == typeof(int)) { valueProperty.PropertyType = ValuePropertyType.Int; } else if (propertyType == typeof(double)) { valueProperty.PropertyType = ValuePropertyType.Double; } else if (propertyType == typeof(DateTime)) { valueProperty.PropertyType = ValuePropertyType.DateTime; } else if (propertyType == typeof(byte[])) { valueProperty.PropertyType = ValuePropertyType.Bytes; } else if (propertyType.IsEnum) { valueProperty.PropertyType = ValuePropertyType.Enum; valueProperty.EnumType = AddEnumIf(propertyType); } else { valueProperty.PropertyType = ValuePropertyType.Unknown; } return valueProperty; }
private void ParseValueProperty(CodeVariable codeVariable, string propertyName, string typeFullName) { //如果匹配以下格式,说明此属性是一个一般属性。 //例如:Rafy.Domain.Property<System.Nullable<System.Double>> var match = Regex.Match(typeFullName, @"Property<(?<name>.+)>"); var propertyType = match.Groups["name"].Value; var property = new ValueProperty(); property.CodeElement = codeVariable; property.Name = propertyName; //System.Nullable<System.Double> if (propertyType.Contains(NullableTypeToken)) { property.Nullable = true; propertyType = UnwrapGenericType(propertyType);//去除 System.Nullable< 及 > } switch (propertyType) { case "System.String": property.PropertyType = ValuePropertyType.String; break; case "System.Boolean": property.PropertyType = ValuePropertyType.Boolean; break; case "System.Int32": property.PropertyType = ValuePropertyType.Int; break; case "System.Double": property.PropertyType = ValuePropertyType.Double; break; case "System.Decimal": property.PropertyType = ValuePropertyType.Decimal; break; case "System.DateTime": property.PropertyType = ValuePropertyType.DateTime; break; case "System.Byte[]": property.PropertyType = ValuePropertyType.Bytes; break; default: property.PropertyType = ValuePropertyType.Unknown; property[PropertyTypeFullNameProperty] = propertyType; _unknownProperties.Add(property); break; } _currentType.ValueProperties.Add(property); }