Beispiel #1
0
        public CodeCommentStatementCollection GenerateCommentCodeDom(ICodeDOMTranslationOptions options)
        {
            CodeCommentStatementCollection ccsc = new CodeCommentStatementCollection();

            if (this.Count == 0)
            {
                return(ccsc);
            }
            CodeCommentStatement[] typeParamComments = new CodeCommentStatement[this.Count];
            for (int i = 0; i < this.Count; i++)
            {
                IDelegateTypeParameterMember param = this[i];
                if (param.DocumentationComment != null && param.DocumentationComment != string.Empty)
                {
                    string paramName = "";
                    if (options.NameHandler.HandlesName(param))
                    {
                        paramName = options.NameHandler.HandleName(param);
                    }
                    else
                    {
                        paramName = param.Name;
                    }
                    ccsc.Add(new CodeCommentStatement(new CodeComment(string.Format("<param name=\"{0}\">{1}</param>", paramName, param.DocumentationComment), true)));
                }
            }
            return(ccsc);
        }
Beispiel #2
0
        public CodeCommentStatementCollection GenerateCodeDom(ICodeDOMTranslationOptions options)
        {
            List <IComment> nonDocCom           = new List <IComment>();
            List <IDocumentationComment> docCom = new List <IDocumentationComment>();

            foreach (IComment ic in this)
            {
                if (ic is IDocumentationComment)
                {
                    docCom.Add((IDocumentationComment)ic);
                }
                else
                {
                    nonDocCom.Add(ic);
                }
            }
            CodeCommentStatementCollection ccsc = new CodeCommentStatementCollection();

            nonDocCom.AddRange(docCom.ToArray());
            docCom.Clear();
            docCom = null;

            foreach (IComment ic in nonDocCom)
            {
                ccsc.Add(new CodeCommentStatement(ic.GenerateCodeDom(options)));
            }
            return(ccsc);
        }
Beispiel #3
0
 private void ValidateCommentStatements(CodeCommentStatementCollection e)
 {
     foreach (CodeCommentStatement statement in e)
     {
         this.ValidateCommentStatement(statement);
     }
 }
 private static void DropDefaultAttribute(Accessor accessor, CodeCommentStatementCollection comments, string type)
 {
     if (!accessor.IsFixed && accessor.IsOptional)
     {
         CodeExporter.AddWarningComment(comments, Res.GetString("XmlDropDefaultAttribute", new object[] { type }));
     }
 }
Beispiel #5
0
        /// <summary>
        /// Emit the summary comments
        /// </summary>
        /// <param name="summaryComments"></param>
        /// <param name="commentCollection">the comment collection of the CodeDom object to be commented</param>
        private static void EmitSummaryComments(string[] summaryComments, CodeCommentStatementCollection commentCollection)
        {
            Debug.Assert(summaryComments != null);
            Debug.Assert(commentCollection != null);

            EmitXmlComments("summary", summaryComments, commentCollection);
        }
Beispiel #6
0
        private CodeCommentStatementCollection AddFileBanner(string sInFile, string sOutFile)
        {
            CodeCommentStatementCollection coll = new CodeCommentStatementCollection();

            coll.Add(new CodeCommentStatement("--------------------------------------------------------------------------------------------"));
            coll.Add(new CodeCommentStatement("Version: MPL 1.1/GPL 2.0/LGPL 2.1"));
            coll.Add(new CodeCommentStatement(""));
            coll.Add(new CodeCommentStatement("The contents of this file are subject to the Mozilla Public License Version"));
            coll.Add(new CodeCommentStatement("1.1 (the \"License\"); you may not use this file except in compliance with"));
            coll.Add(new CodeCommentStatement("the License. You may obtain a copy of the License at"));
            coll.Add(new CodeCommentStatement("http://www.mozilla.org/MPL/"));
            coll.Add(new CodeCommentStatement(""));
            coll.Add(new CodeCommentStatement("Software distributed under the License is distributed on an \"AS IS\" basis,"));
            coll.Add(new CodeCommentStatement("WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License"));
            coll.Add(new CodeCommentStatement("for the specific language governing rights and limitations under the"));
            coll.Add(new CodeCommentStatement("License."));
            coll.Add(new CodeCommentStatement(""));
            coll.Add(new CodeCommentStatement("<remarks>"));
            coll.Add(new CodeCommentStatement("Generated by IDLImporter from file " + Path.GetFileName(sInFile)));
            coll.Add(new CodeCommentStatement(""));
            coll.Add(new CodeCommentStatement("You should use these interfaces when you access the COM objects defined in the mentioned"));
            coll.Add(new CodeCommentStatement("IDL/IDH file."));
            coll.Add(new CodeCommentStatement("</remarks>"));
            coll.Add(new CodeCommentStatement("--------------------------------------------------------------------------------------------"));
            return(coll);
        }
Beispiel #7
0
        public void AddRange()
        {
            CodeCommentStatement ccs1 = new CodeCommentStatement();
            CodeCommentStatement ccs2 = new CodeCommentStatement();
            CodeCommentStatement ccs3 = new CodeCommentStatement();

            CodeCommentStatementCollection coll1 = new CodeCommentStatementCollection();

            coll1.Add(ccs1);
            coll1.Add(ccs2);

            CodeCommentStatementCollection coll2 = new CodeCommentStatementCollection();

            coll2.Add(ccs3);
            coll2.AddRange(coll1);
            Assert.AreEqual(3, coll2.Count, "#1");
            Assert.AreEqual(1, coll2.IndexOf(ccs1), "#2");
            Assert.AreEqual(2, coll2.IndexOf(ccs2), "#3");
            Assert.AreEqual(0, coll2.IndexOf(ccs3), "#4");

            CodeCommentStatementCollection coll3 = new CodeCommentStatementCollection();

            coll3.Add(ccs3);
            coll3.AddRange(new CodeCommentStatement[] { ccs1, ccs2 });
            Assert.AreEqual(3, coll2.Count, "#5");
            Assert.AreEqual(1, coll2.IndexOf(ccs1), "#6");
            Assert.AreEqual(2, coll2.IndexOf(ccs2), "#7");
            Assert.AreEqual(0, coll2.IndexOf(ccs3), "#8");
        }
Beispiel #8
0
 private void GenerateCommentStatements(CodeCommentStatementCollection e)
 {
     foreach (CodeCommentStatement comment in e)
     {
         GenerateCommentStatement(comment);
     }
 }
Beispiel #9
0
 private static void DropDefaultAttribute(Accessor accessor, CodeCommentStatementCollection comments, string type)
 {
     if (!accessor.IsFixed && accessor.IsOptional)
     {
         AddWarningComment(comments, string.Format(ResXml.XmlDropDefaultAttribute, type));
     }
 }
Beispiel #10
0
 public void ToCodeDom(CodeCommentStatementCollection comments)
 {
     // comments
     foreach (XmlElement el in this.doc.Root.ChildNodes)
     {
         StringWriter  sw = new StringWriter();
         XmlTextWriter w  = new XmlTextWriter(sw);
         w.Formatting = Formatting.Indented;
         el.WriteTo(w);
         w.Flush();
         foreach (String s in sw.ToString().Split('\r'))
         {
             if (s.Length <= 1)
             {
                 continue;
             }
             if (s[0] == '\n')
             {
                 comments.Add(new CodeCommentStatement(
                                  s.Substring(1, s.Length - 1), true)
                              );
             }
             else
             {
                 comments.Add(new CodeCommentStatement(
                                  s, true)
                              );
             }
         }
     }
 }
        static CodeCommentStatement[] _ToArray(CodeCommentStatementCollection refs)
        {
            var result = new CodeCommentStatement[refs.Count];

            refs.CopyTo(result, 0);
            return(result);
        }
Beispiel #12
0
 private static IEnumerable <CodeCommentStatement> SafeToEnumerable(CodeCommentStatementCollection collection)
 {
     foreach (CodeCommentStatement codeCommentStatement in collection)
     {
         yield return(codeCommentStatement);
     }
 }
Beispiel #13
0
 public static void AddRange(this CodeCommentStatementCollection self, params object[] comments)
 {
     foreach (var comment in Sequence.Expand(comments))
     {
         self.Add(new CodeCommentStatement(comment.ToString()));
     }
 }
Beispiel #14
0
 public static void AddRange(this CodeCommentStatementCollection self, IEnumerable <CodeCommentStatement> comments)
 {
     foreach (var c in comments)
     {
         self.Add(c);
     }
 }
Beispiel #15
0
 private void ValidateCommentStatements(CodeCommentStatementCollection e)
 {
     foreach (CodeCommentStatement comment in e)
     {
         ValidateCommentStatement(comment);
     }
 }
Beispiel #16
0
        public CodeCommentStatementCollection GenerateCommentCodeDom(ICodeDOMTranslationOptions options)
        {
            CodeCommentStatementCollection ccsc = new CodeCommentStatementCollection();

            if (this.Count == 0)
            {
                return(ccsc);
            }
            CodeCommentStatement[] typeParamComments = new CodeCommentStatement[this.Count];
            for (int i = 0; i < this.Count; i++)
            {
                TItem itpm = this[i];
                if (itpm.DocumentationComment != null && itpm.DocumentationComment != string.Empty)
                {
                    string itpmName = "";
                    if (options.NameHandler.HandlesName(itpm))
                    {
                        itpmName = options.NameHandler.HandleName(itpm);
                    }
                    else
                    {
                        itpmName = itpm.Name;
                    }
                    ccsc.Add(new CodeCommentStatement(new CodeComment(string.Format("<typeparam name=\"{0}\">{1}</typeparam>", itpmName, itpm.DocumentationComment), true)));
                }
            }
            return(ccsc);
        }
Beispiel #17
0
 protected virtual void GenerateCommentStatements(CodeCommentStatementCollection statements)
 {
     foreach (CodeCommentStatement comment in statements)
     {
         GenerateCommentStatement(comment);
     }
 }
Beispiel #18
0
        static void AddDocComments(docMember dm, CodeCommentStatementCollection comments, string[] extra = null)
        {
            if (dm != null && dm.summary != null)
            {
                comments.Add(new CodeCommentStatement("<summary>", true));
                var noIndent = StringFunctions.TrimTrimIndentsOfArray(dm.summary.Text);
                if (noIndent != null)
                {
                    foreach (var item in noIndent)
                    {
                        comments.Add(new CodeCommentStatement(item, true));
                    }
                }

                if (extra != null && extra.Length > 0)
                {
                    foreach (var c in extra)
                    {
                        comments.Add(new CodeCommentStatement(c, true));
                    }
                }

                comments.Add(new CodeCommentStatement("</summary>", true));
            }
            else if (extra != null && extra.Length > 0)
            {
                comments.Add(new CodeCommentStatement("<summary>", true));
                foreach (var c in extra)
                {
                    comments.Add(new CodeCommentStatement(c, true));
                }
                comments.Add(new CodeCommentStatement("</summary>", true));
            }
        }
 public void ToCodeDom(CodeCommentStatementCollection comments)
 {
     // comments
     foreach (XmlElement el in this.doc.Root.ChildNodes)
     {
         comments.Add(new CodeCommentStatement(el.OuterXml, true));
     }
 }
Beispiel #20
0
        private static CodeCommentStatementCollection SplitCommentLines(string comment)
        {
            var lines  = Regex.Split(comment, "[\r\n]+");
            var result = new CodeCommentStatementCollection();

            lines.ToList <String>().ConvertAll(c => new CodeCommentStatement(c, true)).ForEach(c => result.Add(c));
            return(result);
        }
Beispiel #21
0
        /// <summary>
        /// emit all the documentation comments for an element's documentation child
        /// (if the element does not have a documentation child emit some standard "missing comments" comment
        /// </summary>
        /// <param name="element">the element whose documentation is to be displayed</param>
        /// <param name="commentCollection">the comment collection of the CodeDom object to be commented</param>
        public static void EmitSummaryComments(MetadataItem item, CodeCommentStatementCollection commentCollection)
        {
            Debug.Assert(item != null, "item parameter is null");
            Debug.Assert(commentCollection != null, "commentCollection parameter is null");

            Documentation documentation = GetDocumentation(item);

            string [] summaryComments = null;
            if (documentation != null && !MetadataUtil.IsNullOrEmptyOrWhiteSpace(documentation.Summary))
            {
                // we have documentation to emit
                summaryComments = GetFormattedLines(documentation.Summary, true);
            }
            else
            {
                string summaryComment;
                // no summary content, so use a default
                switch (item.BuiltInTypeKind)
                {
                case BuiltInTypeKind.EdmProperty:
                    summaryComment = Strings.MissingPropertyDocumentation(((EdmProperty)item).Name);
                    break;

                case BuiltInTypeKind.ComplexType:
                    summaryComment = Strings.MissingComplexTypeDocumentation(((ComplexType)item).FullName);
                    break;

                default:
                {
                    PropertyInfo pi = item.GetType().GetProperty("FullName");
                    if (pi == null)
                    {
                        pi = item.GetType().GetProperty("Name");
                    }

                    object value = null;
                    if (pi != null)
                    {
                        value = pi.GetValue(item, null);
                    }


                    if (value != null)
                    {
                        summaryComment = Strings.MissingDocumentation(value.ToString());
                    }
                    else
                    {
                        summaryComment = Strings.MissingDocumentationNoName;
                    }
                }
                break;
                }
                summaryComments = new string[] { summaryComment };
            }
            EmitSummaryComments(summaryComments, commentCollection);
            EmitOtherDocumentationComments(documentation, commentCollection);
        }
 static void AddDocComments(List <string> ss, CodeCommentStatementCollection comments)
 {
     if (ss != null && ss.Count > 0 && comments != null)
     {
         comments.Add(new CodeCommentStatement("<summary>", true));
         ss.ForEach(s => comments.Add(new CodeCommentStatement(s, true)));
         comments.Add(new CodeCommentStatement("</summary>", true));
     }
 }
 static void AddDocComments(string description, CodeCommentStatementCollection comments)
 {
     if (description != null && comments != null)
     {
         comments.Add(new CodeCommentStatement("<summary>", true));
         comments.Add(new CodeCommentStatement(description, true));
         comments.Add(new CodeCommentStatement("</summary>", true));
     }
 }
Beispiel #24
0
        public static void Add(this CodeCommentStatementCollection comments, string name, DateTime value)
        {
            if (value == DateTime.MinValue)
            {
                return;
            }

            comments.Add(new CodeCommentStatement(string.Format("{0}: {1}", name, value)));
        }
Beispiel #25
0
        protected CodeStatement[] GetCommentHeader(string sectionTitle)
        {
            CodeCommentStatementCollection comments = new CodeCommentStatementCollection(_headercomment);

            comments.Insert(2, new CodeCommentStatement(sectionTitle));
            CodeCommentStatement[] statements = new CodeCommentStatement[comments.Count];
            comments.CopyTo(statements, 0);
            return(statements);
        }
Beispiel #26
0
        public static void Add(this CodeCommentStatementCollection comments, string name, object value)
        {
            if (value == null || string.IsNullOrEmpty(value.ToString()) == true)
            {
                return;
            }

            comments.Add(new CodeCommentStatement(string.Format("{0}: {1}", name, value)));
        }
Beispiel #27
0
        public void AddRange_Self()
        {
            CodeCommentStatementCollection coll = new CodeCommentStatementCollection();

            coll.Add(new CodeCommentStatement());
            Assert.AreEqual(1, coll.Count, "#1");
            coll.AddRange(coll);
            Assert.AreEqual(2, coll.Count, "#2");
        }
        public void Constructor1_NullItem()
        {
            CodeCommentStatement[] statements = new CodeCommentStatement[] {
                new CodeCommentStatement(), null
            };

            CodeCommentStatementCollection coll = new CodeCommentStatementCollection(
                statements);
        }
Beispiel #29
0
        /// <summary>
        /// Creates a collection of Xml comments surrounded by start end end tags for the named section
        /// </summary>
        /// <param name="section">Section such as "Summary"</param>
        /// <param name="body">The body of the comment</param>
        /// <returns>A collection of Xml comments that can be added to some member.</returns>
        public static CodeCommentStatementCollection GenerateXmlComments(string section, string body)
        {
            CodeCommentStatementCollection result = new CodeCommentStatementCollection();

            result.Add(new CodeCommentStatement(@"<" + section + ">", true));
            result.Add(new CodeCommentStatement(body, true));
            result.Add(new CodeCommentStatement(@"</" + section + ">", true));
            return(result);
        }
Beispiel #30
0
 /// <summary>
 /// 添加注释
 /// </summary>
 static void AddDocumentComment(CodeCommentStatementCollection comments, string commentContent)
 {
     if (!string.IsNullOrEmpty(commentContent))
     {
         comments.Add(new CodeCommentStatement(new CodeComment("<summary>", true)));
         comments.Add(new CodeCommentStatement(new CodeComment(commentContent, true)));
         comments.Add(new CodeCommentStatement(new CodeComment("</summary>", true)));
     }
 }
	public CodeCommentStatementCollection(CodeCommentStatementCollection value) {}
 private void GenerateCommentStatements(CodeCommentStatementCollection comments, CodeTypeMember member = null)
 {
     if (comments.Count > 0)
     {
         Output.WriteLine("/**");
     }
     foreach (CodeCommentStatement comment in comments)
     {
         GenerateCommentStatement(comment);
     }
     if (member != null)
     {
         foreach (CodeCommentStatement reference in (CodeCommentStatementCollection)member.UserData["references"])
         {
             GenerateCommentStatement(reference);
         }
     }
     if (member is CodeMemberMethod)
     {
         CodeParameterDeclarationExpressionCollection parameters = ((CodeMemberMethod)member).Parameters;
         foreach (CodeParameterDeclarationExpression param in parameters)
         {
             foreach (CodeCommentStatement comment in (CodeCommentStatementCollection)param.UserData["comments"])
             {
                 GenerateParamCommentStatement(param.Name, comment);
             }
         }
     }
     if (comments.Count > 0)
     {
         Output.WriteLine(" */");
     }
 }
Beispiel #33
0
    public void PostMembersHook(Smoke* smoke, Smoke.Class* klass, CodeTypeDeclaration type)
    {
        if (Util.IsQObject(klass))
        {
            CodeMemberProperty emit = new CodeMemberProperty();
            emit.Name = "Emit";
            emit.Attributes = MemberAttributes.Family | MemberAttributes.New | MemberAttributes.Final;
            emit.HasGet = true;
            emit.HasSet = false;

            string signalsIfaceName = "I" + type.Name + "Signals";
            CodeTypeReference returnType = new CodeTypeReference(signalsIfaceName);
            emit.Type = returnType;

            emit.GetStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(
                returnType,
                new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "Q_EMIT")
            )));

            type.Members.Add(emit);

            string className = ByteArrayManager.GetString(klass->className);
            int colon = className.LastIndexOf("::", StringComparison.Ordinal);
            string prefix = (colon != -1) ? className.Substring(0, colon) : string.Empty;

            IList typeCollection = Data.GetTypeCollection(prefix);
            CodeTypeDeclaration ifaceDecl = new CodeTypeDeclaration(signalsIfaceName);
            ifaceDecl.IsInterface = true;

            if (className != "QObject")
            {
                string parentClassName = ByteArrayManager.GetString(smoke->classes[smoke->inheritanceList[klass->parents]].className);
                colon = parentClassName.LastIndexOf("::", StringComparison.Ordinal);
                prefix = (colon != -1) ? parentClassName.Substring(0, colon) : string.Empty;
                if (colon != -1)
                {
                    parentClassName = parentClassName.Substring(colon + 2);
                }

                string parentInterface = (prefix != string.Empty) ? prefix.Replace("::", ".") + "." : string.Empty;
                parentInterface += "I" + parentClassName + "Signals";

                ifaceDecl.BaseTypes.Add(new CodeTypeReference(parentInterface));
            }
            Dictionary<CodeSnippetTypeMember, CodeMemberMethod> signalEvents = new Dictionary<CodeSnippetTypeMember, CodeMemberMethod>();
            GetSignals(smoke, klass, delegate(string signature, string name, string typeName, IntPtr metaMethod)
            {
                CodeMemberMethod signal = new CodeMemberMethod();
                signal.Attributes = MemberAttributes.Abstract;

                // capitalize the first letter
                StringBuilder builder = new StringBuilder(name);
                builder[0] = char.ToUpper(builder[0]);
                string tmp = builder.ToString();

                signal.Name = tmp;
                bool isRef;
                try
                {
                    if (typeName == string.Empty)
                        signal.ReturnType = new CodeTypeReference(typeof(void));
                    else
                        signal.ReturnType = Translator.CppToCSharp(typeName, out isRef);
                }
                catch (NotSupportedException)
                {
                    Debug.Print("  |--Won't wrap signal {0}::{1}", className, signature);
                    return;
                }

                CodeAttributeDeclaration attr = new CodeAttributeDeclaration("Q_SIGNAL",
                    new CodeAttributeArgument(new CodePrimitiveExpression(signature)));
                signal.CustomAttributes.Add(attr);

                int argNum = 1;
                StringBuilder fullNameBuilder = new StringBuilder("Slot");
                GetMetaMethodParameters(metaMethod, delegate(string paramType, string paramName)
                {
                    if (paramName == string.Empty)
                    {
                        paramName = "arg" + argNum.ToString();
                    }
                    argNum++;

                    CodeParameterDeclarationExpression param;
                    try
                    {
                        short id = smoke->IDType(paramType);
                        CodeTypeReference paramTypeRef;
                        if (id > 0)
                        {
                            paramTypeRef = Translator.CppToCSharp(smoke->types + id, out isRef);
                        }
                        else
                        {
                            if (!paramType.Contains("::"))
                            {
                                id = smoke->IDType(className + "::" + paramType);
                                if (id > 0)
                                {
                                    paramTypeRef = Translator.CppToCSharp(smoke->types + id, out isRef);
                                }
                                else
                                {
                                    paramTypeRef = Translator.CppToCSharp(paramType, out isRef);
                                }
                            }
                            else
                            {
                                paramTypeRef = Translator.CppToCSharp(paramType, out isRef);
                            }
                        }
                        param = new CodeParameterDeclarationExpression(paramTypeRef, paramName);
                    }
                    catch (NotSupportedException)
                    {
                        Debug.Print("  |--Won't wrap signal {0}::{1}", className, signature);
                        return;
                    }
                    if (isRef)
                    {
                        param.Direction = FieldDirection.Ref;
                    }
                    signal.Parameters.Add(param);
                    if (argNum == 2)
                    {
                        fullNameBuilder.Append('<');
                    }
                    fullNameBuilder.Append(param.Type.BaseType);
                    fullNameBuilder.Append(',');
                });
                if (fullNameBuilder[fullNameBuilder.Length - 1] == ',')
                {
                    fullNameBuilder[fullNameBuilder.Length - 1] = '>';
                }
                ifaceDecl.Members.Add(signal);
                CodeSnippetTypeMember signalEvent = new CodeSnippetTypeMember();
                signalEvent.Name = signal.Name;
                CodeSnippetTypeMember existing = signalEvents.Keys.FirstOrDefault(m => m.Name == signal.Name);
                if (existing != null)
                {
                    CodeSnippetTypeMember signalEventToUse;
                    CodeMemberMethod signalToUse;
                    if (signal.Parameters.Count == 0)
                    {
                        signalEventToUse = existing;
                        signalToUse = signalEvents[existing];
                    }
                    else
                    {
                        signalEventToUse = signalEvent;
                        signalToUse = signal;
                    }
                    string suffix = signalToUse.Parameters.Cast<CodeParameterDeclarationExpression>().Last().Name;
                    if (suffix.StartsWith("arg") && suffix.Length > 3 && char.IsDigit(suffix[3]))
                    {
                        string lastType = signalToUse.Parameters.Cast<CodeParameterDeclarationExpression>().Last().Type.BaseType;
                        suffix = lastType.Substring(lastType.LastIndexOf('.') + 1);
                    }
                    else
                    {
                        StringBuilder lastParamBuilder = new StringBuilder(suffix);
                        lastParamBuilder[0] = char.ToUpper(lastParamBuilder[0]);
                        suffix = lastParamBuilder.ToString();
                    }
                    signalEventToUse.Text = signalEventToUse.Text.Replace(signalEventToUse.Name, signalEventToUse.Name += suffix);
                }
                signalEvent.Text = string.Format(@"
        public event {0} {1}
        {{
            add
            {{
                QObject.Connect(this, Qt.SIGNAL(""{2}""), (QObject) value.Target, Qt.SLOT(value.Method.Name + ""{3}""));
            }}
            remove
            {{
                QObject.Disconnect(this, Qt.SIGNAL(""{2}""), (QObject) value.Target, Qt.SLOT(value.Method.Name + ""{3}""));
            }}
        }}", fullNameBuilder, signalEvent.Name, signature, signature.Substring(signature.IndexOf('(')));
                signalEvents.Add(signalEvent, signal);
            });

            typeCollection.Add(ifaceDecl);
            foreach (KeyValuePair<CodeSnippetTypeMember, CodeMemberMethod> signalEvent in signalEvents)
            {
                CodeSnippetTypeMember implementation = signalEvent.Key;
                CodeCommentStatementCollection comments = new CodeCommentStatementCollection();
                foreach (CodeTypeMember current in from CodeTypeMember member in type.Members
                                                   where member.Name == implementation.Name
                                                   select member)
                {
                    if (comments.Count == 0)
                    {
                        comments.AddRange(current.Comments);
                    }
                    current.Name = "On" + current.Name;
                }
                signalEvent.Value.Comments.AddRange(comments);
                signalEvent.Key.Comments.AddRange(comments);
                type.Members.Add(signalEvent.Key);
            }
        }
    }
	public void AddRange(CodeCommentStatementCollection value) {}
Beispiel #35
0
 private void GenerateProperties(ICollection<CodeMemberMethod> methods, IEnumerable<CodeMemberMethod> settersToUse, bool readOnly)
 {
     foreach (CodeMemberMethod setter in settersToUse)
     {
         if (!this.type.Members.Contains(setter))
         {
             continue;
         }
         string afterSet = setter.Name.Substring(3);
         for (int i = this.nonSetters.Count - 1; i >= 0; i--)
         {
             CodeMemberMethod getter = this.nonSetters[i];
             if (!this.type.Members.Contains(getter))
             {
                 continue;
             }
             if (string.Compare(getter.Name, afterSet, StringComparison.OrdinalIgnoreCase) == 0 &&
                 getter.ReturnType.BaseType == setter.Parameters[0].Type.BaseType &&
                 !methods.Any(m => m != getter && string.Compare(getter.Name, m.Name, StringComparison.OrdinalIgnoreCase) == 0))
             {
                 methods.Remove(getter);
                 if (this.type.IsInterface)
                 {
                     CodeSnippetTypeMember property = new CodeSnippetTypeMember();
                     property.Name = getter.Name;
                     string template = readOnly ? "        {0} {1} {{ get; }}" : "        {0} {1} {{ get; set; }}";
                     property.Text = string.Format(template, getter.ReturnType.BaseType, getter.Name);
                     CodeCommentStatementCollection comments = new CodeCommentStatementCollection(getter.Comments);
                     if (!readOnly)
                     {
                         comments.AddRange(setter.Comments);
                     }
                     AddComments(property, comments, readOnly);
                     this.type.Members.Add(property);
                     this.type.Members.Remove(getter);
                     if (!readOnly)
                     {
                         this.type.Members.Remove(setter);
                     }
                 }
                 else
                 {
                     this.GenerateProperty(getter, readOnly ? null : setter);
                 }
                 goto next;
             }
         }
         CodeTypeMember baseVirtualProperty = this.GetBaseVirtualProperty(this.type, afterSet);
         if (!this.type.IsInterface && baseVirtualProperty != null)
         {
             CodeMemberMethod getter = new CodeMemberMethod { Name = baseVirtualProperty.Name };
             getter.ReturnType = setter.Parameters[0].Type;
             getter.Statements.Add(new CodeSnippetStatement(string.Format("            return base.{0};", afterSet)));
             this.GenerateProperty(getter, readOnly ? null : setter);
         }
         next:
         ;
     }
     foreach (CodeMemberMethod nonSetter in this.nonSetters)
     {
         CodeTypeMember baseVirtualProperty = this.GetBaseVirtualProperty(this.type, nonSetter.Name);
         if (!this.type.IsInterface && baseVirtualProperty != null)
         {
             bool isReadOnly = (baseVirtualProperty is CodeMemberProperty && !((CodeMemberProperty) baseVirtualProperty).HasSet) ||
                               !regexPropertySetter.IsMatch(((CodeSnippetTypeMember) baseVirtualProperty).Text);
             if (readOnly == isReadOnly)
             {
                 CodeMemberMethod setter = new CodeMemberMethod { Name = baseVirtualProperty.Name };
                 setter.Statements.Add(new CodeSnippetStatement(string.Format("            base.{0} = value;", nonSetter.Name)));
                 this.GenerateProperty(nonSetter, readOnly ? null : setter);
             }
         }
     }
 }
Beispiel #36
0
 private void ValidateCommentStatements(CodeCommentStatementCollection e)
 {
     foreach (CodeCommentStatement comment in e)
     {
         ValidateCommentStatement(comment);
     }
 }
Beispiel #37
0
 protected virtual void GenerateCommentStatements(CodeCommentStatementCollection e)
 {
     foreach (CodeCommentStatement comment in e)
     {
         GenerateCommentStatement(comment);
     }
 }
Beispiel #38
0
 private static void AddComments(CodeTypeMember completeProperty, CodeCommentStatementCollection comments, bool readOnly)
 {
     if (!readOnly)
     {
         for (int i = comments.Count - 2; i >= 1; i--)
         {
             string comment = comments[i].Comment.Text;
             if (comment == "<summary>" || comment == "</summary>" || comment.StartsWith("<para>See also "))
             {
                 comments.RemoveAt(i);
             }
         }
     }
     completeProperty.Comments.AddRange(comments);
 }
Beispiel #39
0
 private void GenerateProperty(CodeMemberMethod getter, CodeMemberMethod setter = null)
 {
     CodeCommentStatementCollection comments = new CodeCommentStatementCollection();
     comments.AddRange(getter.Comments);
     getter.Comments.Clear();
     if (setter != null)
     {
         comments.AddRange(setter.Comments);
         setter.Comments.Clear();
     }
     if (this.type.Members.OfType<CodeSnippetTypeMember>().All(
         p => string.Compare(getter.Name, p.Name, StringComparison.OrdinalIgnoreCase) != 0 ||
              p.UserData["interface"] != getter.PrivateImplementationType) &&
         this.type.Members.OfType<CodeMemberProperty>().All(
             p => string.Compare(getter.Name, p.Name, StringComparison.OrdinalIgnoreCase) != 0 ||
                  p.PrivateImplementationType != getter.PrivateImplementationType))
     {
         CodeMemberProperty property = new CodeMemberProperty();
         property.Name = getter.Name;
         property.Type = getter.ReturnType;
         property.Attributes = MemberAttributes.Public;
         if ((getter.Attributes & MemberAttributes.Static) == MemberAttributes.Static)
         {
             property.Attributes |= MemberAttributes.Static;
         }
         if ((getter.Attributes & MemberAttributes.Final) == MemberAttributes.Final &&
             (setter == null || (setter.Attributes & MemberAttributes.Final) == MemberAttributes.Final))
         {
             property.Attributes |= MemberAttributes.Final;
         }
         if ((getter.Attributes & MemberAttributes.Override) == MemberAttributes.Override ||
             (setter != null && (setter.Attributes & MemberAttributes.Override) == MemberAttributes.Override))
         {
             property.Attributes |= MemberAttributes.Override;
         }
         property.GetStatements.AddRange(getter.Statements);
         if (setter != null)
         {
             CodeVariableDeclarationStatement variableStatement =
                 setter.Statements.OfType<CodeVariableDeclarationStatement>().First();
             CodeArrayCreateExpression arrayExpression = (CodeArrayCreateExpression) variableStatement.InitExpression;
             CodeArgumentReferenceExpression argExpression =
                 arrayExpression.Initializers.OfType<CodeArgumentReferenceExpression>().First();
             argExpression.ParameterName = "value";
             property.SetStatements.AddRange(setter.Statements);
         }
         property.PrivateImplementationType = getter.PrivateImplementationType;
         if (property.PrivateImplementationType == null && setter != null)
         {
             property.PrivateImplementationType = setter.PrivateImplementationType;
         }
         CodeSnippetTypeMember completeProperty = AddAttributes(getter, setter, property);
         AddComments(completeProperty, comments, setter == null);
         type.Members.Add(completeProperty);
         if (type.Members.Contains(getter))
         {
             type.Members.Remove(getter);
         }
         if (setter != null && this.type.Members.Contains(setter))
         {
             type.Members.Remove(setter);
         }
     }
 }