Example #1
0
        /// <summary>
        /// 读取类配置
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ClassUpgradeConfig GetEnumConfig(Type type)
        {
            ClassUpgradeConfig config = new ClassUpgradeConfig
            {
                Name            = type.Name,
                ConfigType      = type,
                TypeName        = type.GetTypeName(),
                BaseType        = type.BaseType.GetTypeName(),
                IsDataAttribute = type.GetCustomAttribute(typeof(DataContractAttribute)) != null,
                IsJsonAttribute = type.GetCustomAttribute(typeof(JsonObjectAttribute)) != null
            };

            GetInfo(config, type);
            foreach (var name in type.GetEnumNames())
            {
                var field = new FieldUpgradeConfig
                {
                    Name = name,
                };
                var member = HelpXml.FirstOrDefault(p => p.Name == type.FullName + "." + name);
                if (member != null)
                {
                    field.Description = member.Summary;
                    field.Caption     = member.DisplayName;
                    field.Description = member.Remark ?? member.Summary;
                }
                config.Fields.Add(name, field);
            }
            return(config);
        }
Example #2
0
                                          BindingFlags.NonPublic;     //指定非公共成员将包括在搜索中。

        /// <summary>
        /// 读取类配置
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public ClassUpgradeConfig GetConfig(Type type)
        {
            bool isArray = false;

            if (type.IsSupperInterface(typeof(System.Collections.IList)))
            {
                isArray = true;
                type    = type.GetGenericArguments()[0];
            }
            ClassUpgradeConfig config = new ClassUpgradeConfig
            {
                Name            = type.Name,
                ConfigType      = type,
                IsArray         = isArray,
                TypeName        = type.GetTypeName(),
                BaseType        = type.BaseType.GetTypeName(),
                IsDataAttribute = type.GetCustomAttribute(typeof(DataContractAttribute)) != null,
                IsJsonAttribute = type.GetCustomAttribute(typeof(JsonObjectAttribute)) != null
            };

            GetInfo(config, type);
            foreach (var field in type.GetFields(flag))
            {
                config.Fields.Add(field.Name.Trim('_'), GetConfig(type, field));
            }
            foreach (var field in type.GetProperties(flag))
            {
                config.Properties.Add(field.Name, GetConfig(type, field));
            }
            foreach (var property in config.Properties)
            {
                FieldUpgradeConfig field;
                if (!config.Fields.TryGetValue(property.Key, out field))
                {
                    continue;
                }
                field.PairProperty       = property.Key;
                property.Value.PairField = field.Name;
                if (field.IsJsonAttribute)
                {
                    property.Value.JsonName = field.JsonName;
                }
            }
            return(config);
        }