/// <summary> /// Set the metadata of hide. /// </summary> /// <param name="hide"></param> protected virtual void SetHide(HideAttribute hide) { if (hide == null) { throw new ArgumentNullException("hide"); } IsHiddenOnCreate = hide.IsHiddenOnCreate; IsHiddenOnDetail = hide.IsHiddenOnDetail; IsHiddenOnEdit = hide.IsHiddenOnEdit; IsHiddenOnView = hide.IsHiddenOnView; }
/// <summary> /// Initialize property metadata. /// </summary> /// <param name="propertyInfo">Property info.</param> public ClrPropertyMetadata(PropertyInfo propertyInfo) : base(propertyInfo.Name, propertyInfo.PropertyType) { Property = propertyInfo; CanGet = propertyInfo.GetGetMethod() != null; CanSet = propertyInfo.GetSetMethod() != null; if (CanGet) { _GetValue = propertyInfo.GetGetMethodDelegate(); } if (CanSet) { _SetValue = propertyInfo.GetSetMethodDelegate(); } SetMetadata(); HideAttribute hide = propertyInfo.GetCustomAttribute <HideAttribute>(); if (hide == null) { if (propertyInfo.PropertyType.IsGenericType) { IsHiddenOnView = true; } } string customType; bool isFileUpload; Type = propertyInfo.GetCustomDataType(out customType, out isFileUpload); CustomType = customType; IsFileUpload = isFileUpload; if (Type != CustomDataType.Image && Type != CustomDataType.Password && Type != CustomDataType.Time) { if (CustomType == null || CustomType == "Entity" || CustomType == "Enum") { SearchableAttribute searchable = propertyInfo.GetCustomAttribute <SearchableAttribute>(); Searchable = searchable != null; } } }
public void SetDescription(object _parent, PropertyInfo _pi) { De de = Attribute.GetCustomAttribute(_pi, typeof(De)) as De; if (de == null) { return; } HideAttribute hide = Attribute.GetCustomAttribute(_pi, typeof(HideAttribute)) as HideAttribute; if (hide != null) { return; } if (descs == null) { return; } PropertyDescriptor pd = TypeDescriptor.GetProperties(_pi.DeclaringType)[_pi.Name]; de = (De)pd.Attributes[typeof(De)]; string ckey = _parent.GetType().Name + "." + _pi.Name; Desc desc = descs[_parent.GetType().Name + "." + _pi.Name]; if (desc == null) { desc = new Desc(); } de.Acc = desc.accsess; de.Description = desc.description; BrowsableAttribute ba = (BrowsableAttribute)pd.Attributes[typeof(BrowsableAttribute)]; if (ba != null) { FieldInfo isBrowsable = ba.GetType().GetField("Browsable", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance); if (de.Browsable) { isBrowsable.SetValue(ba, desc.accsess.CheckUser(User.current)); } } return; }
/// <summary> /// Initialize property metadata. /// </summary> /// <param name="propertyInfo">Property info.</param> public ClrPropertyMetadata(PropertyInfo propertyInfo) : base(propertyInfo.Name, propertyInfo.PropertyType) { Property = propertyInfo; CanGet = propertyInfo.GetGetMethod() != null; CanSet = propertyInfo.GetSetMethod() != null; if (CanGet) { _GetValue = propertyInfo.GetGetMethodDelegate(); } if (CanSet) { _SetValue = propertyInfo.GetSetMethodDelegate(); } SetMetadata(); HideAttribute hide = propertyInfo.GetCustomAttribute <HideAttribute>(); if (hide == null) { if (!propertyInfo.PropertyType.GetTypeInfo().IsValueType&& propertyInfo.PropertyType.GetTypeInfo().IsGenericType) { IsHiddenOnView = true; } } string customType; bool isFileUpload; Type = propertyInfo.GetCustomDataType(out customType, out isFileUpload); CustomType = customType; IsFileUpload = isFileUpload; Converter = TypeDescriptor.GetConverter(ClrType); SearchableAttribute searchable = propertyInfo.GetCustomAttribute <SearchableAttribute>(); Searchable = searchable != null; }
/// <summary> /// Initialize property metadata. /// </summary> /// <param name="propertyInfo">Property info.</param> public PropertyMetadata(PropertyInfo propertyInfo) { Property = propertyInfo; DisplayAttribute display = propertyInfo.GetCustomAttribute <DisplayAttribute>(); if (display != null) { Name = display.Name == null ? propertyInfo.Name : display.Name; if (display.Description != null) { Description = display.Description; } Order = display.GetOrder().HasValue ? display.Order : 0; ShortName = display.ShortName == null ? Name : display.ShortName; } else { Name = propertyInfo.Name; } RequiredAttribute required = propertyInfo.GetCustomAttribute <RequiredAttribute>(); IsRequired = required != null; HideAttribute hide = propertyInfo.GetCustomAttribute <HideAttribute>(); if (hide != null) { IsHiddenOnEdit = hide.IsHiddenOnEdit; IsHiddenOnView = hide.IsHiddenOnView; IsHiddenOnDetail = hide.IsHiddenOnDetail; } else { if (propertyInfo.PropertyType.IsGenericType) { IsHiddenOnView = true; } } var customDataType = propertyInfo.GetCustomAttribute <CustomDataTypeAttribute>(); if (customDataType != null) { Type = customDataType.Type; CustomType = customDataType.Custom; } else { Type type = propertyInfo.PropertyType; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { type = type.GetGenericArguments()[0]; } if (type == typeof(DateTime)) { Type = CustomDataType.Date; } if (type == typeof(TimeSpan)) { Type = CustomDataType.Time; } else if (type == typeof(bool)) { Type = CustomDataType.Boolean; } else if (type == typeof(short) || type == typeof(int) || type == typeof(long)) { Type = CustomDataType.Integer; } else if (type == typeof(float) || type == typeof(double)) { Type = CustomDataType.Number; } else if (type == typeof(decimal)) { Type = CustomDataType.Currency; } else if (type == typeof(byte[])) { Type = CustomDataType.File; } else if (type.IsEnum) { Type = CustomDataType.Other; CustomType = "Enum"; } else if (type.IsGenericType) { Type = CustomDataType.Other; CustomType = "Collection"; } else if (typeof(IEntity).IsAssignableFrom(type)) { Type = CustomDataType.Other; CustomType = "Entity"; } } if (Type != CustomDataType.Image && Type != CustomDataType.Password && Type != CustomDataType.Time) { if (CustomType == null || CustomType == "Entity" || CustomType == "Enum") { SearchableAttribute searchable = propertyInfo.GetCustomAttribute <SearchableAttribute>(); Searchable = searchable != null; } } IsDistinct = propertyInfo.GetCustomAttribute <DistinctAttribute>() != null; }
public ComInterfaceDescription LoadAssemblyDescription(string path, ref string assemblyName, ref string version) { Exception = null; ErrorCode = 0; Assembly assembly; if (!_assemblies.ContainsKey(assemblyName)) { if (!File.Exists(path)) { this.ErrorCode = ModuleErrorCode.LibraryNotFound; return(null); } try { assembly = Assembly.LoadFrom(path); } catch (Exception ex) { this.Exception = ex; this.ErrorCode = ModuleErrorCode.LibraryLoadError; return(null); } if (string.IsNullOrWhiteSpace(assemblyName)) { assemblyName = assembly.GetName().Name; version = assembly.GetName().Version.ToString(); } else { if (!CheckVersion(version, assembly)) { return(null); } } if (!_assemblies.ContainsKey(assemblyName)) { _assemblies.Add(assemblyName, assembly); } } else { assembly = _assemblies[assemblyName]; } try { ComInterfaceDescription descriptionData = new ComInterfaceDescription() { Category = string.Empty, Signature = assembly.FullName, Name = assembly.GetName().Name }; // descriptionData.Assembly = assemblyInfo; // TODO 加载xml文件注释 foreach (Type typeInfo in assembly.GetExportedTypes()) { HideAttribute hideAttribute = typeInfo.GetCustomAttribute <HideAttribute>(); //如果隐藏属性为true,则隐藏该类型。如果是屏蔽类型,则跳过 if ((null != hideAttribute && hideAttribute.Hide) || _ignoreClass.Any(item => typeInfo.Name.EndsWith(item))) { continue; } VariableType classKind = GetKindOfType(typeInfo); if (classKind == VariableType.Enumeration || classKind == VariableType.Value) { AddDataTypeDescription(descriptionData, typeInfo, assemblyName, classKind); } else if (classKind == VariableType.Class || classKind == VariableType.Struct) { AddClassDescription(descriptionData, typeInfo, assemblyName, classKind); } } return(descriptionData); } catch (Exception ex) { Exception = ex; this.ErrorCode = ModuleErrorCode.LibraryLoadError; return(null); } }