Exemple #1
0
        private void PropertyCode(PropertyUpgradeConfig property, StringBuilder code)
        {
            string fieldName = ToTfWordName(property.Name, "_");
            var    di        = DescriptionCode(property, code);

            FieldCode(property, code, fieldName);

            code.Append($@"

        /// <summary>
        /// {ToRemString(property.Caption)}
        /// </summary>
        /// <remark>
        /// {ToRemString(property.Description)}
        /// </remark>
        [IgnoreDataMember,JsonIgnore]
        [Category(@""{property.Category}""),DisplayName(@""{property.Caption}""),Description({di})]
        public {property.TypeName} {property.Name}
        {{
            get
            {{
                return {fieldName};
            }}
            set
            {{
                if({fieldName} == value)
                    return;
                this.BeforePropertyChanged(nameof({property.Name}), {fieldName},value);
                this.{fieldName} = value;
                this.OnPropertyChanged(nameof({property.Name}));
            }}
        }}");
        }
Exemple #2
0
        private static void FieldCode(PropertyUpgradeConfig property, StringBuilder code, string fieldName)
        {
            code.Append($@"

        /// <summary>
        /// {ToRemString(property.Caption)}
        /// </summary>
        [");
            code.Append(property.IsDataAttribute ? "DataMember" : "IgnoreDataMember");
            code.Append(property.IsJsonAttribute
                ? $@",JsonProperty(""{property.JsonName}"", NullValueHandling = NullValueHandling.Ignore)"
                : ",JsonIgnore");

            code.Append($@"]
        internal {property.TypeName} {fieldName};");
        }
Exemple #3
0
        private void PropertyByCode(PropertyUpgradeConfig property, StringBuilder code)
        {
            var di = DescriptionCode(property, code);

            code.Append($@"

        /// <summary>
        /// {ToRemString(property.Caption)}
        /// </summary>
        /// <remark>
        /// {ToRemString(property.Description)}
        /// </remark>
        [IgnoreDataMember,JsonIgnore]
        [Category(@""{property.Category}""),DisplayName(@""{property.Caption}""),Description({di})]
        {property.Code}");
        }
Exemple #4
0
        private static string DescriptionCode(PropertyUpgradeConfig property, StringBuilder code)
        {
            string di;

            if (property.Description != null && (property.Description.Length > 20 || property.Description.Contains("\r")))
            {
                code.Append($@"

        /// <summary>
        /// {property.Caption}的说明文字
        /// </summary>
        const string {property.Name}_Description = @""{property.Description}"";");
                di = $"{property.Name}_Description";
            }
            else
            {
                di = $"\"{property.Description}\"";
            }
            return(di);
        }
Exemple #5
0
        private PropertyUpgradeConfig GetConfig(Type type, PropertyInfo property)
        {
            PropertyUpgradeConfig config = new PropertyUpgradeConfig
            {
                Name            = property.Name,
                ConfigType      = property.PropertyType,
                TypeName        = property.PropertyType.GetTypeName(),
                CanRead         = property.CanRead,
                CanWrite        = property.CanWrite,
                IsDataAttribute = property.GetCustomAttribute(typeof(DataMemberAttribute)) != null,
            };

            config.IsList = config.TypeName.Contains("Collection<");
            var json = property.GetCustomAttribute <JsonPropertyAttribute>();

            if (json != null)
            {
                config.IsJsonAttribute = true;
                config.JsonName        = !string.IsNullOrWhiteSpace(json.PropertyName) ? json.PropertyName : config.Name;
            }
            GetInfo(config, type, property);
            return(config);
        }