Exemple #1
0
 public static PropertyLabelDrawer CreatePropertyLabelDrawer(PropertyLabelAttribute attr)
 {
     if (attrDrawerDic.TryGetValue(attr.GetType(), out Type drawerType))
     {
         return((PropertyLabelDrawer)Activator.CreateInstance(drawerType, attr));
     }
     return(null);
 }
Exemple #2
0
        private string CodeBuilder(Type type, string test)
        {
            StringBuilder sb       = new StringBuilder();
            PropertyInfo  property = type.GetProperty("Config");
            string        emunname = "Test_Enumn_";

            if (property != null)
            {
                Type ptype = property.PropertyType;
                if (ptype.IsEnum)
                {
                    Array values = Enum.GetValues(ptype);
                    Array names  = Enum.GetNames(ptype);

                    sb.AppendLine("public enum Test_Enumn1");
                    sb.AppendLine("{");
                    for (int i = 0; i < names.Length; i++)
                    {
                        if (i > 0)
                        {
                            sb.Append(",\r\n");
                        }
                        sb.AppendFormat("{0}={1}", names.GetValue(i), (int)Enum.Parse(ptype, names.GetValue(i).ToString()));
                    }
                    sb.AppendLine("}");
                    sb.AppendLine("public class " + test + "_Config");
                    sb.AppendLine("{");
                    sb.AppendLine("[System.ComponentModel.Category(\"Case Config\")]");
                    sb.AppendLine(string.Format("public {0} Value {{get;set;}}", "Test_Enumn1"));
                    sb.AppendLine("}");
                }
                else if (ptype.IsValueType || ptype == typeof(string))
                {
                    sb.AppendLine("public class " + test + "_Config");
                    sb.AppendLine("{");
                    sb.AppendLine("[System.ComponentModel.Category(\"Case Config\")]");
                    sb.AppendLine(string.Format("public {0} Value {{get;set;}}", ptype.FullName));
                    sb.AppendLine("}");
                }
                else
                {
                    sb.AppendLine("public class " + test + "_Config");
                    sb.AppendLine("{");
                    foreach (PropertyInfo pp in ptype.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                    {
                        if (pp.PropertyType.IsEnum)
                        {
                            Array values = Enum.GetValues(pp.PropertyType);
                            Array names  = Enum.GetNames(pp.PropertyType);
                            emunname = emunname + "a";

                            sb.AppendLine("public enum " + emunname);
                            sb.AppendLine("{");
                            for (int i = 0; i < names.Length; i++)
                            {
                                if (i > 0)
                                {
                                    sb.Append(",\r\n");
                                }
                                sb.AppendFormat("{0}={1}", names.GetValue(i), (int)Enum.Parse(pp.PropertyType, names.GetValue(i).ToString()));
                            }
                            sb.AppendLine("}");
                        }
                        PropertyLabelAttribute pla = pp.GetCustomAttribute <PropertyLabelAttribute>();
                        if (pla != null)
                        {
                            sb.AppendLine(string.Format("[Beetle.DTCore.PropertyLabel(\"{0}\",\"{1}\")]", pla.Name, pla.Remark));
                        }

                        PropertyAttribute pas = pp.GetCustomAttribute <PropertyAttribute>();
                        if (pas != null && pas.Type == PropertyType.Remark)
                        {
                            sb.AppendLine("[Beetle.DTCore.Property(Type = Beetle.DTCore.PropertyType.Remark)]");
                        }
                        sb.AppendLine("[System.ComponentModel.Category(\"Case Config\")]");
                        if (pp.PropertyType.IsEnum)
                        {
                            sb.AppendLine(string.Format("public {0} {1} {{get;set;}}", emunname, pp.Name));
                        }
                        else if (pp.PropertyType.IsValueType || pp.PropertyType == typeof(string))
                        {
                            sb.AppendLine(string.Format("public {0} {1} {{get;set;}}", pp.PropertyType.FullName, pp.Name));
                        }
                    }
                    sb.AppendLine("}");
                }
            }
            return(sb.ToString());
        }
 protected PropertyLabelDrawer(PropertyLabelAttribute attr) : base(attr)
 {
 }
Exemple #4
0
 public NewLabelDrawer(PropertyLabelAttribute attr) : base(attr)
 {
 }