private static void GenCSCode(CSObject data) { StringBuilder sb = new StringBuilder(); sb.Append(codeHeader); sb.Append("\r\n"); sb.Append(string.Format("using {0};\r\n", CSHelper.GetUseNameSpace())); string nameSpace = Define.UserDefine.global.nameSpace; if (data.HadCollections) { sb.Append("using System.Collections.Generic;\r\n"); } if (data.HadExtends && nameSpace != Define.ConstDefine.EXTENDS_NAMESPACE) { sb.Append(Define.ConstDefine.EXTENDS_NAMESPACE + ";\r\n"); } sb.Append("\r\n"); if (hadnsName) { sb.Append("namespace "); sb.Append(nameSpace); sb.Append("\r\n{"); sb.Append("\r\n"); } sb.Append(tab); sb.Append(CSHelper.ClassAttribute()); sb.Append("\r\n"); if (data.HadExtends) { int index = 1; if (data.HadVector2) { sb.Append(tab); sb.Append(string.Format("[ProtoInclude({0}, typeof(DataTable.Vector2))]\r\n", index)); index++; } if (data.HadVector3) { sb.Append(tab); sb.Append(string.Format("[ProtoInclude({0}, typeof(DataTable.Vector3))]\r\n", index)); index++; } if (data.HadColor) { sb.Append(tab); sb.Append(string.Format("[ProtoInclude({0}, typeof(DataTable.Color))]\r\n", index)); index++; } } sb.Append(tab); sb.Append("public partial class "); sb.Append(data.name); sb.Append("\r\n"); sb.Append(tab); sb.Append("{"); // construction sb.Append("\r\n"); sb.Append(tab); sb.Append("\t"); sb.Append("public "); sb.Append(data.name); sb.Append("() {"); StringBuilder propertyCode = new StringBuilder(); int count = data.typeCount; for (int i = 0; i < count; i++) { TypeDecorator type = data.type.datas[i]; CSObjectPropertyGroup.Data propertry = data.property.datas[i]; if (TypeAdapter.IsContainer(type.typeDecotrator) || TypeAdapter.HadExtends(type)) { sb.Append("\r\n"); sb.Append(tab); sb.Append("\t\t"); sb.Append(propertry.name); sb.Append(" = new "); sb.Append(type.GetName()); sb.Append("();"); } propertyCode.Append("\r\n"); propertyCode.Append(tab); propertyCode.Append("\t"); propertyCode.Append("/// <summary>\r\n"); propertyCode.Append(tab); propertyCode.Append("\t/// "); propertyCode.Append(propertry.summary); propertyCode.Append("\r\n"); propertyCode.Append(tab); propertyCode.Append("\t/// </summary>\r\n"); propertyCode.Append(tab); propertyCode.Append("\t"); int index = i + 1; propertyCode.Append(CSHelper.Attribute(index)); propertyCode.Append("\r\n"); propertyCode.Append(tab); propertyCode.Append("\t"); propertyCode.Append("public "); propertyCode.Append(type.GetName()); propertyCode.Append(" "); propertyCode.Append(propertry.name); propertyCode.Append(" { private set; get; }"); propertyCode.Append("\r\n"); } sb.Append("\r\n"); sb.Append("\t"); sb.Append(tab); sb.Append("}"); sb.Append("\r\n"); sb.Append(propertyCode.ToString()); sb.Append(tab); sb.Append("}"); if (hadnsName) { sb.Append("\r\n"); sb.Append("}"); } CSHelper.Write(data.name, sb.ToString()); }