/// <summary> /// 完善类名 /// </summary> /// <param name="tree"></param> /// <param name="prefab"></param> /// <param name="rule"></param> /// <returns></returns> private static TypeDeclaration CompleteClass(BridgeUI.NRefactory.CSharp.SyntaxTree tree, string className, GenCodeRule rule) { TypeDeclaration classNode = null; if (tree.Descendants.OfType <TypeDeclaration>().Where(x => x.Name == className).Count() == 0) { classNode = new TypeDeclaration(); classNode.Name = className; classNode.Modifiers |= Modifiers.Public; var comment = new Comment("<summary>", CommentType.Documentation); tree.AddChild(comment, Roles.Comment); comment = new Comment("[代码说明信息]", CommentType.Documentation); tree.AddChild(comment, Roles.Comment); comment = new Comment("<summary>", CommentType.Documentation); tree.AddChild(comment, Roles.Comment); tree.AddChild(classNode, Roles.TypeMemberRole); } classNode = tree.Descendants.OfType <TypeDeclaration>().Where(x => x.Name == className).First(); var baseType = GenCodeUtil.supportBaseTypes[rule.baseTypeIndex]; var basePanels = LoadAllBasePanels(); var bs = classNode.BaseTypes.Where(x => Array.Find(basePanels, y => y.Contains(x.ToString())) != null).FirstOrDefault(); if (bs != null) { classNode.BaseTypes.Remove(bs); } classNode.BaseTypes.Add(new SimpleType(baseType)); return(classNode); }
/// <summary> /// 完善命名空间 /// </summary> /// <param name="tree"></param> /// <param name="rule"></param> private static void CompleteNameSpace(BridgeUI.NRefactory.CSharp.SyntaxTree tree, GenCodeRule rule) { string[] usingDeclarations = { "BridgeUI", "UnityEngine", "UnityEngine.UI", "System.Collections", "System.Collections.Generic", }; foreach (var item in usingDeclarations) { if (tree.Descendants.OfType <UsingDeclaration>().Where(x => x.Namespace == item).Count() == 0) { tree.AddChild <AstNode>(new UsingDeclaration(item), Roles.Root); } } }
private AstNode GetClassNode() { CompilerSettings setting = new CompilerSettings(); CSharpParser cpaser = new CSharpParser(setting); BridgeUI.NRefactory.CSharp.SyntaxTree tree = cpaser.Parse(classStr); if (tree.Errors != null && tree.Errors.Count > 0) { foreach (var erro in tree.Errors) { Debug.LogError(erro.Message); Debug.LogError(erro.Region); } return(null); } else { AstNode classNode = tree.Children.First(); return(classNode); } }
public UICoder(string className) { this.className = className; firstCreate = true; tree = new BridgeUI.NRefactory.CSharp.SyntaxTree(); }