void ParseClassDelay(string names, AstNode node) { delayClass[names] = node; foreach (var v in node.Children) { if (v is TypeDeclaration) { string fullname = Tools._getClassFullName(v); ParseClassDelay(fullname, v); } } }
void ParseClassSingle(string classname, AstNode node, bool withDepthAdd) { List <TypeInfo> basetype = null; int constructorcount = 0; bool bExport = false; foreach (var v in node.Children) { if (v is Comment) { Append(v.ToString().Replace("\r\n", "")); } else if (v is CSharpModifierToken) { if (v.ToString() == "public") { if (string.IsNullOrEmpty(curNamespace)) { } else { if (string.IsNullOrEmpty(curNamespace) == false) { Append("export "); bExport = true; } } } else if (v.ToString() == "private") { break; } else { logger.LogWarnning("not support modifier,skip it:" + v.ToString() + "|" + v.StartLocation.Line); } } else if (v is CSharpTokenNode) { //export everything if (bExport == false && string.IsNullOrEmpty(curNamespace) == false) { Append("export "); bExport = true; } if (v.ToString() == "class") { Append("class "); } else if (v.ToString() == "struct") { logger.Log("Find a struct:" + classname); Append("class "); } else if (v.ToString() == "interface") { Append("interface "); } else if (v.ToString() == "{") { if (basetype != null) { ParseClassBase(basetype); basetype = null; } Append("{"); curClassName = classname; space += 4; } else if (v.ToString() == "}") { ParseClassEnd(); space -= 4; Append("}"); } else if (v.ToString() == ":")//有继承 { basetype = new List <TypeInfo>(); } } else if (v is SimpleType) { var type = this.proj.FindType((v as SimpleType).Identifier, curNamespace, curClassName, this.listUsing, this.listUsinAlias); basetype.Add(proj.getTypeInfo(type)); } else if (v is Identifier) { //classname = v.Code; Append(classname); } else if (v is NewLineNode) { if (basetype != null) { ParseClassBase(basetype); basetype = null; } AppendLine(); } else if (v is FieldDeclaration) { ParseClassMember_Field(v); } else if (v is MethodDeclaration) { ParseClassMember_Method(v, false); } else if (v is ConstructorDeclaration) { if (constructorcount > 0) { logger.LogError("Can't use more than one Constructor in class. for typescript."); } ParseClassConstructor(v); constructorcount++; } else if (v is PropertyDeclaration) { ParseClassMember_Property(v); } else if (v is TypeDeclaration) { if (withDepthAdd) { string fullname = Tools._getClassFullName(v); ParseClassDelay(fullname, node); } } else { logger.LogError("not support class element:" + v.GetType().Name + "|" + v.NodeType + "|" + v.StartLocation.Line); } } }