Exemplo n.º 1
0
        public void SetValue(XmlAttributeCollection inValue)
        {
            constructList.Add(new ConstructItem());

            // 构造函数
            ConstructItem construct = new ConstructItem(new List <string>()
            {
                "System.String"
            });

            construct.Struct.Statements.Add(Line("string[] ss", "inArg0.Split(\'^\')"));

            classer.CustomAttributes.Add(new CodeAttributeDeclaration("ProtoContract"));
            for (int i = 0; i < inValue.Count; i++)
            {
                fieldList.Add(new FieldItem(inValue[i].Name, inValue[i].Value, MemberAttributes.Private));

                PropertyItem item = new PropertyItem(inValue[i].Name);
                item.SetGetName();
                item.SetSetName();
                item.SetValueType(inValue[i].Value);
                item.SetModifier(MemberAttributes.Public | MemberAttributes.Final);
                item.SetField("ProtoMember", (i + 1).ToString());
                propertyList.Add(item);

                Type t = (Type)Assist.stringToType(inValue[i].Value);

                string right = t == typeof(System.String) ? "ss[" + i + "]" :
                               t == typeof(System.UInt32) ? "uint.Parse(ss[" + i + "])" :
                               t == typeof(System.Single) ? "float.Parse(ss[" + i + "])" : "new " + t.ToString() + "(inValues[" + i + "])";
                construct.Struct.Statements.Add(Line("_" + Assist.FirstLetterLower(inValue[i].Name), right));
            }
            constructList.Add(construct);
            Create();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 字段
        /// </summary>
        /// <param name="inName">字段名</param>
        /// <param name="inType">字段类型</param>
        /// <param name="inAtt">访问修饰符</param>
        public FieldItem(string inName, string inType, MemberAttributes inAtt)
        {
            object objType = Assist.stringToType(inType);

            if (objType is string)
            {
                field = new CodeMemberField((string)objType, "m_" + Assist.FirstLetterLower(inName));
            }
            else
            {
                field = new CodeMemberField((Type)objType, "m_" + Assist.FirstLetterLower(inName));
                if (Assist.isArray(inType))
                {
                    field.Type.BaseType = "List";
                }
            }

            field.Attributes = inAtt;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 属性类型
        /// </summary>
        /// <param name="inValue"></param>
        /// <param name="hasGet"></param>
        /// <param name="hasSet"></param>
        public void SetValueType(string inValueType = "")
        {
            CodeTypeReference typeRef;
            object            objType = Assist.stringToType(inValueType);

            if (objType is string)
            {
                typeRef       = new CodeTypeReference((string)objType);
                property.Type = typeRef;
            }
            else
            {
                typeRef       = new CodeTypeReference((Type)objType);
                property.Type = typeRef;
                if (Assist.isArray(inValueType))
                {
                    //简化包名
                    property.Type.BaseType = "List";
                }
            }
        }