private string BuildArray(string filedName, JArray type, CodeTypeDeclaration parent) { var member = MemberContext.Get(type); string baseName = filedName.Remove(filedName.Length - 1); return(Build(baseName, member, parent) + "[]"); }
/// <summary> /// 返回对象声明 /// </summary> /// <param name="className">编出脚本的类名</param> /// <param name="members">类的成员变量</param> /// <param name="des">注释</param> /// <param name="parent">从属类</param> /// <returns></returns> private CodeTypeDeclaration Build(string className, JObject members, string des, CodeTypeDeclaration parent) { CodeTypeDeclaration codeTypeDeclaration = new CodeTypeDeclaration(className) { TypeAttributes = TypeAttributes.Public, IsClass = true }; bool isRoot = parent == null; if (!isRoot) { parent.Members.Add(codeTypeDeclaration); codeTypeDeclaration.TypeAttributes |= TypeAttributes.Sealed; } codeTypeDeclaration.BaseTypes.Add(new CodeTypeReference(IGenerateObject)); if (!string.IsNullOrEmpty(des)) { codeTypeDeclaration.Comments.Add(new CodeCommentStatement(des)); } CodeStatementCollection statements = new CodeStatementCollection(); foreach (var member in members) { MemberContext context = MemberContext.Get(member.Value as JArray); string typeName = Build(member.Key, context, codeTypeDeclaration); CodeStatement statement = BuildProperty(member.Key, typeName, context.Comment, codeTypeDeclaration); statements.Add(statement); } BuildClassMethods(codeTypeDeclaration, statements, isRoot); return(codeTypeDeclaration); }