/// <summary> /// get Property /// https://msdn.microsoft.com/zh-cn/library/system.codedom.codememberproperty?cs-save-lang=1&cs-lang=csharp#code-snippet-1 /// </summary> static void AddProperty(CodeTypeDeclaration codeType, QProperty property) { CodeMemberProperty getProperty = new CodeMemberProperty(); AddDocumentComment(getProperty.Comments, property.Comment); switch (property.AccessLimit) { case QAccessLimit.Public: getProperty.Attributes = MemberAttributes.Public; break; case QAccessLimit.Private: getProperty.Attributes = MemberAttributes.Private; break; } switch (property.CompileType) { case QCompileType.Const: getProperty.Attributes |= MemberAttributes.Const; break; case QCompileType.Static: getProperty.Attributes |= MemberAttributes.Static; break; } getProperty.Name = property.Name; getProperty.Type = property.Type; getProperty.GetStatements.Add(new CodeMethodReturnStatement(new CodeFieldReferenceExpression(null, property.GetReturnCode))); codeType.Members.Add(getProperty); }
public static void GeneratePathScript() { AssetDatabase.SaveAssets(); IOUtils.CreateDirIfNotExists(EditorPathManager.DefaultPathScriptGenerateForder); string[] fullPathFileNames = Directory.GetFiles(EditorPathManager.DefaultPathConfigGenerateForder, "*PathDefine.asset", SearchOption.AllDirectories); foreach (string fullPathFileName in fullPathFileNames) { Debug.Log(fullPathFileName); if (!fullPathFileName.EndsWith(".meta")) { Debug.Log("gen: " + fullPathFileName); PathConfig config = AssetDatabase.LoadAssetAtPath <PathConfig> (fullPathFileName); QNamespaceDefine nameSpace = new QNamespaceDefine(); nameSpace.Name = string.IsNullOrEmpty(config.NameSpace) ? "QFramework" : config.NameSpace; nameSpace.FileName = config.name + ".cs"; nameSpace.GenerateDir = string.IsNullOrEmpty(config.ScriptGeneratePath) ? EditorPathManager.DefaultPathScriptGenerateForder : IOUtils.CreateDirIfNotExists("Assets/" + config.ScriptGeneratePath); var classDefine = new QClassDefine(); classDefine.Comment = config.Description; classDefine.Name = config.name; nameSpace.Classes.Add(classDefine); Debug.Log(nameSpace.GenerateDir); foreach (var pathItem in config.List) { if (!string.IsNullOrEmpty(pathItem.Name)) { var variable = new QVariable(QAccessLimit.Private, QCompileType.Const, QTypeDefine.String, "m_" + pathItem.Name, pathItem.Path); classDefine.Variables.Add(variable); var property = new QProperty(QAccessLimit.Public, QCompileType.Static, QTypeDefine.String, pathItem.Name, pathItem.PropertyGetCode, pathItem.Description); classDefine.Properties.Add(property); } } QCodeGenerator.Generate(nameSpace); EditorUtility.SetDirty(config); Resources.UnloadAsset(config); } } AssetDatabase.SaveAssets(); }