예제 #1
0
        public ClassData ToProtoClass()
        {
            ClassData data = new ClassData();

            data.className = sheetName;
            ProtoGenerator generator = new ProtoGenerator(sheetName);

            for (int i = 0; i < memberNames.Length; i++)
            {
                Type filterType = GetFilterType(fieldTypes[i]);
                generator.AddProperty(memberNames[i], fieldTypes[i]);
                if (filterType != null)
                {
                    MethodInfo usingMethod = filterType.GetMethod("GetUsings");
                    if (usingMethod == null)
                    {
                        continue;
                    }
                    object   filterObj  = Activator.CreateInstance(filterType);
                    string[] usingNames = usingMethod.Invoke(filterObj, null) as string[];
                    if (usingNames == null)
                    {
                        continue;
                    }
                    foreach (string name in usingNames)
                    {
                        generator.AddUsingName(name);
                    }
                }
            }
            data.classContent = generator.ToString();
            return(data);
        }
예제 #2
0
        public static void ToProtoClass(string path)
        {
            ExcelData data      = GetData(path);
            string    directory = Path.GetDirectoryName(path);

            for (int i = 0; i < data.sheetDatas.Count; i++)
            {
                SheetData sheet     = data.sheetDatas[i];
                ClassData classData = sheet.ToProtoClass();
                string    filePath  = directory + "/" + classData.className + ".cs";
                StringToFile(filePath, classData.classContent);
            }
        }
예제 #3
0
        public static ClassData[] GetFieldClass(string path)
        {
            ExcelData data      = GetData(path);
            string    directory = Path.GetDirectoryName(path);
            int       count     = data.sheetDatas.Count;

            if (count == 0)
            {
                return(null);
            }
            ClassData[] result = new ClassData[count];
            for (int i = 0; i < count; i++)
            {
                SheetData sheet = data.sheetDatas[i];
                result[i] = sheet.ToFieldClass();
            }
            return(result);
        }
예제 #4
0
        public ClassData ToFieldClass()
        {
            ClassData data = new ClassData();

            data.className = sheetName;
            ClassGenerator generator = new ClassGenerator(sheetName);

            generator.SetAuthority(AuthorityType.Public);
            for (int i = 0; i < memberNames.Length; i++)
            {
                FieldGenerator field = new FieldGenerator();
                field.SetAnnotation(annotations[i]);
                field.SetFieldName(memberNames[i]);
                field.SetFieldType(fieldTypes[i]);
                field.SetAuthority(AuthorityType.Public);
                generator.AddField(field);
                Type filterType = GetFilterType(fieldTypes[i]);
                if (filterType != null)
                {
                    MethodInfo usingMethod = filterType.GetMethod("GetUsings");
                    if (usingMethod == null)
                    {
                        continue;
                    }
                    object   filterObj  = Activator.CreateInstance(filterType);
                    string[] usingNames = usingMethod.Invoke(filterObj, null) as string[];
                    if (usingNames == null)
                    {
                        continue;
                    }
                    generator.SetUsingName(usingNames);
                }
            }
            data.classContent = generator.ToString();
            return(data);
        }