public void SetValue(XmlAttributeCollection inValue) { constructList.Add(new ItemConstruct()); // 构造函数 ItemConstruct construct = new ItemConstruct(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 ItemField(inValue[i].Name, inValue[i].Value, MemberAttributes.Private)); ItemProperty item = new ItemProperty(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 = Stringer.ToType(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("_" + Stringer.FirstLetterLower(inValue[i].Name), right)); } constructList.Add(construct); Create(); }
public void SetValue(XmlAttributeCollection inValue) { constructList.Add(new ItemConstruct()); // 构造函数 ItemConstruct construct = new ItemConstruct(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 ItemField(inValue[i].Name, inValue[i].Value, MemberAttributes.Private)); ItemProperty item = new ItemProperty(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 = Stringer.ToType(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("_" + Stringer.FirstLetterLower(inValue[i].Name), right)); } constructList.Add(construct); Create(); }