public CodeDOMDocumentServiceAHK(ProjectItemCodeDocument document) : base(document) { #region Create Language Master Root _root = new CodeTypeDeclarationEx(null, "Global") { CodeDocumentItem = document }; #region Create auto exec method for AHK Scripts _root.Members.Add(_autoexec = new CodeMemberMethodExAHK(true) { Name = "AutoExec", Attributes = MemberAttributes.Public | MemberAttributes.Static, DefiningType = _languageRoot, ReturnType = new CodeTypeReference(typeof(void)), LinePragma = new CodeLinePragma("all", 0), IsHidden = true, CodeDocumentItem = document }); #endregion #region Setup Base Object var baseobj = new CodeTypeDeclarationEx(null, "Object") { CodeDocumentItem = document, IsClass = true, IsBuildInType = true }; baseobj.Comments.Add(new CodeCommentStatement("Base Object of all other Custom Objects", true)); CodeMemberMethodExAHK method; #region Object.Insert method = new CodeMemberMethodExAHK(true) { Name = "Insert", CodeDocumentItem = document, IsDefaultMethodInvoke = true, IsTraditionalCommand = false, }; method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(object)), "key")); method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(object)), "value")); method.Comments.Add(new CodeCommentStatement("Inserts key-value pairs into the object, automatically adjusting existing keys if appropriate.", true)); method.ReturnType = new CodeTypeReference(typeof(bool)); baseobj.Members.Add(method); #endregion #region Object.Remove method = new CodeMemberMethodExAHK(true) { Name = "Remove", Project = document.Project, IsDefaultMethodInvoke = true, IsTraditionalCommand = false }; method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(object)), "key")); method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(object)), "value")); method.Comments.Add(new CodeCommentStatement("Removes key-value pairs from an object.", true)); method.ReturnType = new CodeTypeReference(typeof(bool)); baseobj.Members.Add(method); #endregion #region Object.Clone method = new CodeMemberMethodExAHK(true) { Name = "Clone", CodeDocumentItem = document, IsDefaultMethodInvoke = true, IsTraditionalCommand = false }; method.Comments.Add(new CodeCommentStatement("Returns a shallow copy of the object.", true)); method.ReturnType = new CodeTypeReference(typeof(object)); baseobj.Members.Add(method); #endregion #region Object.MinIndex method = new CodeMemberMethodExAHK(true) { Name = "MinIndex", CodeDocumentItem = document, IsDefaultMethodInvoke = true, IsTraditionalCommand = false }; method.Comments.Add(new CodeCommentStatement("If any integer keys are present, MinIndex returns the lowest and MaxIndex returns the highest. Otherwise an empty string is returned.", true)); method.ReturnType = new CodeTypeReference(typeof(int)); baseobj.Members.Add(method); #endregion #region Object.MaxIndex method = new CodeMemberMethodExAHK(true) { Name = "MaxIndex", CodeDocumentItem = document, IsDefaultMethodInvoke = true, IsTraditionalCommand = false }; method.Comments.Add(new CodeCommentStatement("If any integer keys are present, MinIndex returns the lowest and MaxIndex returns the highest. Otherwise an empty string is returned.", true)); method.ReturnType = new CodeTypeReference(typeof(int)); baseobj.Members.Add(method); #endregion #region Object.SetCapacity method = new CodeMemberMethodExAHK(true) { Name = "SetCapacity", CodeDocumentItem = document, IsDefaultMethodInvoke = true, IsTraditionalCommand = false }; method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(int)), "MaxItemsOrKey")); method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(int)), "ByteSize")); method.Comments.Add(new CodeCommentStatement("If any integer keys are present, MinIndex returns the lowest and MaxIndex returns the highest. Otherwise an empty string is returned.", true)); method.ReturnType = new CodeTypeReference(typeof(int)); baseobj.Members.Add(method); #endregion #region Object.GetCapacity method = new CodeMemberMethodExAHK(true) { Name = "GetCapacity", CodeDocumentItem = document, IsDefaultMethodInvoke = true, IsTraditionalCommand = false }; method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(int)), "Key")); method.Comments.Add(new CodeCommentStatement("Returns the current capacity of an object or one of its fields.", true)); method.ReturnType = new CodeTypeReference(typeof(int)); baseobj.Members.Add(method); #endregion #region Object.HasKey method = new CodeMemberMethodExAHK(true) { Name = "HasKey", CodeDocumentItem = document, IsDefaultMethodInvoke = true, IsTraditionalCommand = false }; method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(int)), "Key")); method.Comments.Add(new CodeCommentStatement("Returns true if Key is associated with a value (even '') within Object, otherwise false.", true)); method.ReturnType = new CodeTypeReference(typeof(bool)); baseobj.Members.Add(method); #endregion #region Object._NewEnum method = new CodeMemberMethodExAHK(true) { Name = "_NewEnum", CodeDocumentItem = document, IsDefaultMethodInvoke = true, IsTraditionalCommand = false }; method.Comments.Add(new CodeCommentStatement("Returns a new enumerator to enumerate this object's key-value pairs.", true)); method.ReturnType = new CodeTypeReference(typeof(IEnumerator)); baseobj.Members.Add(method); #endregion _root.Members.Add(baseobj); #endregion // Import build-in members foreach(var m in document.CodeLanguage.BuildInMembers) { var codeobj = m as ICodeMemberEx; if(codeobj != null) { codeobj.Project = document.Project; } _root.Members.Add(m); } #endregion _rootLanguageSnapshot = _root; }
public virtual CodeMemberMethodEx ResolveMethodDeclarationCache() { var lang = Language; if(_methodDeclaration == null && EnclosingType != null) { CodeTypeDeclarationEx typedecl = EnclosingType; var members = from m in typedecl.GetInheritedMembers() let memberMethod = m as CodeMemberMethodEx where memberMethod != null && memberMethod.Name.Equals(this.MethodName, lang.NameComparisation) select memberMethod; if(members.Any()) _methodDeclaration = members.First(); } if(_methodDeclaration == null) { var doc = CodeDocumentItem; if(doc != null && !(EnclosingType is CodeTypeDeclarationRoot)) { var members = from member in doc.AST.RootTypeUnSave.Members.Cast<CodeTypeMember>() let methodMember = member as CodeMemberMethodEx where methodMember != null && methodMember.Name.Equals(this.MethodName, lang.NameComparisation) select methodMember; if(members.Any()) _methodDeclaration = members.First(); } } return _methodDeclaration; }
public CodeMethodReferenceExpressionExAHK(ProjectItemCodeDocument codeDocumentItem, CodeMemberMethodEx resolvedCommand) : base(codeDocumentItem, null, resolvedCommand.Name, null) { _methodDeclaration = resolvedCommand; }