예제 #1
0
    //入口,读取翻译的列表
    public static void ReadAllowFieldList(string filename)
    {
        _AllowFieldList.Clear();

        string[] lines = File.ReadAllLines(filename);
        if (lines != null)
        {
            foreach (string line in lines)
            {
                STranslateField field = new STranslateField();
                int             len   = line.Length;
                for (int i = 0; i < len; ++i)
                {
                    char cc = line[i];
                    if (cc == '.')
                    {
                        field.parentMemberName = line.Substring(0, i);
                        if (i + 1 < len)
                        {
                            field.propName = line.Substring(i + 1);
                        }
                    }
                }

                _AllowFieldList.Add(field);
            }
        }
    }
예제 #2
0
    private static List <STransEntry> ParseParentMemberNameList(STranslateField transfield)      //解析如 [[[ExecutionUnit][Event]][AddFightSpeciality]]
    {
        List <STransEntry> valList = new List <STransEntry>();

        int start = -1;
        int len   = transfield.parentMemberName.Length;

        for (int i = 0; i < len; ++i)
        {
            char cc = transfield.parentMemberName[i];
            if (cc == '[')
            {
                start = i + 1;
            }
            else if (cc == ']')
            {
                if (i > start)
                {
                    string v = transfield.parentMemberName.Substring(start, i - start);
                    valList.Add(new STransEntry()
                    {
                        name = v, isList = false
                    });
                }
                start = i + 1;
            }
            else if (cc == '<')
            {
                start = i + 1;
            }
            else if (cc == '>')
            {
                if (i > start)
                {
                    string v = transfield.parentMemberName.Substring(start, i - start);
                    valList.Add(new STransEntry()
                    {
                        name = v, isList = true
                    });
                }
                start = i + 1;
            }
        }

        return(valList);
    }
예제 #3
0
    private static void GetFieldInfo(List <STranslateField> transFields, string fieldName, TemplateFieldTranslator.CStringFieldInfo info, bool ignoreTranslateTxt)
    {
        string typeName;

        if (fieldName[fieldName.Length - 1] == '>')
        {
            typeName = fieldName;
        }
        else
        {
            typeName = '[' + fieldName + ']';
        }

        //结构中的string字段
        foreach (var prop in info.Fields)
        {
            //Console.WriteLine("{0}   {1}", typeName, prop.Name);
            STranslateField field = new STranslateField()
            {
                parentMemberName = STranslateField.fixParentMemberName(typeName), propName = prop.Name
            };

            if (USE_FORBID)
            {
                if (!field.IsForbid(_ForbidFieldList))
                {
                    transFields.Add(field);
                }
            }
            else
            {
                if (ignoreTranslateTxt || field.IsAllow(_AllowFieldList))
                {
                    transFields.Add(field);
                }
            }
        }

        //结构中的list字段item中的string字段
        foreach (var listkv in info.ListFields)
        {
            /*
             * string listFieldName = listkv.Key;
             * List<PropertyInfo> props = listkv.Value;
             * foreach (var prop in props)
             * {
             *  //string parentMemberName = string.Format("{0}{1}", typeName, listFieldName);
             *  //Console.WriteLine("{0}  {1}", parentMemberName, prop.Name);
             *  STranslateField field = new STranslateField() { parentMemberName = STranslateField.fixParentMemberName(typeName), listName = listFieldName, propName = prop.Name };
             *  if (!field.IsForbid(_ForbidFieldList))
             *      transFields.Add(field);
             * }
             * */
            string memberFieldName = '<' + listkv.Key + '>';
            TemplateFieldTranslator.CStringFieldInfo fieldInfo = listkv.Value;
            GetFieldInfo(transFields, typeName + memberFieldName, fieldInfo, ignoreTranslateTxt);
        }

        //结构中的子结构中的string字段
        foreach (var mkv in info.MemberFields)
        {
            string memberFieldName = '[' + mkv.Key + ']';
            TemplateFieldTranslator.CStringFieldInfo fieldInfo = mkv.Value;
            GetFieldInfo(transFields, typeName + memberFieldName, fieldInfo, ignoreTranslateTxt);
        }
    }