Inheritance: CodeObject
		public void Constructor1_Deny_Unrestricted ()
		{
			CodeComment cc = new CodeComment ("mono");
			CodeCommentStatement ccs = new CodeCommentStatement (cc);
			Assert.AreEqual ("mono", ccs.Comment.Text, "Comment.Text");
			Assert.IsFalse (ccs.Comment.DocComment, "Comment.DocComment");
		}
 public static CodeComment Clone(CodeComment codestatementcol)
 {
     return new CodeComment()
     {
         DocComment = codestatementcol.DocComment,
         Text = codestatementcol.Text,
     };
 }
		public void DefaultCodeCommentStatementTest ()
		{
			CodeCommentStatement commentStatement = new CodeCommentStatement ();
			CodeComment comment = new CodeComment ();
			
			commentStatement.Comment = comment;
			statement = commentStatement;
			
			Generate ();
			Assertion.AssertEquals ("// \n", Code);
		}
        /// <summary>
        /// Generates the specified dictionary.
        /// </summary>
        /// <param name="dictionary">The dictionary.</param>
        /// <param name="classType">Type of the class.</param>
        /// <param name="initMethod">The initialize method.</param>
        /// <param name="fieldReference">The field reference.</param>
        public void Generate(ResourceDictionary dictionary, CodeTypeDeclaration classType, CodeMemberMethod initMethod, CodeExpression fieldReference)
        {
            foreach (var mergedDict in dictionary.MergedDictionaries)
            {
                string name = string.Empty;
                if (mergedDict.Source.IsAbsoluteUri)
                {
                    name = Path.GetFileNameWithoutExtension(mergedDict.Source.LocalPath);                    
                }
                else
                {
                    name = Path.GetFileNameWithoutExtension(mergedDict.Source.OriginalString);                    
                }

                if (string.IsNullOrEmpty(name))
                {
                    Console.WriteLine("Dictionary name not found.");
                    continue;
                }

                CodeMethodInvokeExpression addMergedDictionary = new CodeMethodInvokeExpression(
                        fieldReference, "MergedDictionaries.Add", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(name), "Instance"));
                initMethod.Statements.Add(addMergedDictionary);
            }

            ValueGenerator valueGenerator = new ValueGenerator();
            List<object> keys = dictionary.Keys.Cast<object>().OrderBy(k => k.ToString()).ToList();
            foreach (var resourceKey in keys)
            {
                object resourceValue = dictionary[resourceKey];

                CodeComment comment = new CodeComment("Resource - [" + resourceKey.ToString() + "] " + resourceValue.GetType().Name);
                initMethod.Statements.Add(new CodeCommentStatement(comment));

                CodeExpression keyExpression = CodeComHelper.GetResourceKeyExpression(resourceKey);
                CodeExpression valueExpression = valueGenerator.ProcessGenerators(classType, initMethod, resourceValue, "r_" + uniqueId, dictionary);

                if (valueExpression != null)
                {
                    
                    CodeMethodInvokeExpression addResourceMethod = new CodeMethodInvokeExpression(fieldReference, "Add", keyExpression, valueExpression);

                    var check = new CodeConditionStatement(
                        new CodeMethodInvokeExpression(fieldReference, "Contains", keyExpression), 
                        new CodeStatement[] { },
                        new CodeStatement[] { new CodeExpressionStatement(addResourceMethod) });

                    initMethod.Statements.Add(check);
                }

                uniqueId++;
            }
        }
		public void MultiLineCodeCommentStatementTest ()
		{
			CodeCommentStatement commentStatement = new CodeCommentStatement ();
			CodeComment comment = new CodeComment ();
			
			comment.Text = "a\nb";
			commentStatement.Comment = comment;
			statement = commentStatement;
			
			Generate ();
			Assertion.AssertEquals ("// a\n//b\n", Code);
		}
		public static void AddComment(this CodeCommentStatementCollection codeCommentStatementCollection, String commentText)
		{
			if (commentText == null)
			{
				return;
			}

			foreach (String comment in commentText.Split('\n'))
			{
				var codeComment = new CodeComment(comment, false);
				codeCommentStatementCollection.Add(new CodeCommentStatement(codeComment));
			}
		}
 internal static CodeTypeDeclaration EmitDefaultValuesClass(PropertyNameType[] propertiesGenerated, string defaultValuesClassName)
 {
     CodeTypeDeclaration defaultValuesClass = new CodeTypeDeclaration(defaultValuesClassName);
     defaultValuesClass.TypeAttributes = TypeAttributes.NotPublic;
     MemberAttributes fieldAttrs = CodeDomHelperObjects.InternalConstants;
     CodeComment comment = new CodeComment("Please initialize default values to these fields");
     defaultValuesClass.Comments.Add(new CodeCommentStatement(comment));
     for (int i = 0; i < propertiesGenerated.Length; i++)
     {
         CodeMemberField field = new CodeMemberField(
                                     new CodeTypeReference(propertiesGenerated[i].propertyType.Name),
                                     Constants.DefaultPrefix + propertiesGenerated[i].propertyName);
         field.Attributes = fieldAttrs;
         defaultValuesClass.Members.Add(field);
     }
     return defaultValuesClass;
 }
        /// <summary>
        /// Generates control fields
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="classType">Type of the class.</param>
        /// <param name="method">The initialize method.</param>
        /// <param name="generateField">if set to <c>true</c> [generate field].</param>
        /// <returns></returns>
        public virtual CodeExpression Generate(DependencyObject source, CodeTypeDeclaration classType, CodeMemberMethod method, bool generateField)
        {
            SeriesPoint point = source as SeriesPoint;
            string typeName = point.GetType().Name;
            string name = "p_" + ElementGeneratorType.NameUniqueId;
            ElementGeneratorType.NameUniqueId++;

            /*
            if (generateField)
            {
                CodeMemberField field = new CodeMemberField(typeName, name);
                classType.Members.Add(field);
            }
             */

            CodeComment comment = new CodeComment(name + " point");
            method.Statements.Add(new CodeCommentStatement(comment));

            CodeExpression fieldReference = null;

            //if (!generateField)
            {
                fieldReference = new CodeVariableReferenceExpression(name);
                CodeTypeReference variableType = new CodeTypeReference(typeName);
                CodeVariableDeclarationStatement declaration = new CodeVariableDeclarationStatement(variableType, name);
                declaration.InitExpression = new CodeObjectCreateExpression(typeName);
                method.Statements.Add(declaration);
            }
            /*
            else
            {
                fieldReference = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), name);
                method.Statements.Add(new CodeAssignStatement(fieldReference, new CodeObjectCreateExpression(typeName)));
            }
            */

            CodeComHelper.GenerateField<float>(method, fieldReference, source, SeriesPoint.ArgumentProperty);
            CodeComHelper.GenerateField<float>(method, fieldReference, source, SeriesPoint.ValueProperty);

            return fieldReference;
        }
        /// <summary>
        /// Generates the specified dictionary.
        /// </summary>
        /// <param name="dictionary">The dictionary.</param>
        /// <param name="classType">Type of the class.</param>
        /// <param name="initMethod">The initialize method.</param>
        /// <param name="fieldReference">The field reference.</param>
        public void Generate(ResourceDictionary dictionary, CodeTypeDeclaration classType, CodeMemberMethod initMethod, CodeExpression fieldReference)
        {
            foreach (var mergedDict in dictionary.MergedDictionaries)
            {
                if (mergedDict.Source.IsAbsoluteUri)
                {
                    string name = Path.GetFileNameWithoutExtension(mergedDict.Source.LocalPath);
                    CodeMethodInvokeExpression addMergedDictionary = new CodeMethodInvokeExpression(
                        fieldReference, "MergedDictionaries.Add", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(name), "Instance"));
                    initMethod.Statements.Add(addMergedDictionary);
                }
                else
                {
                    Console.WriteLine("Use absolute URI for merged dictionaries.");
                }
            }

            ValueGenerator valueGenerator = new ValueGenerator();
            foreach (var resourceKey in dictionary.Keys)
            {
                object resourceValue = dictionary[resourceKey];

                CodeComment comment = new CodeComment("Resource - [" + resourceKey.ToString() + "] " + resourceValue.GetType().Name);
                initMethod.Statements.Add(new CodeCommentStatement(comment));

                CodeExpression keyExpression = CodeComHelper.GetResourceKeyExpression(resourceKey);
                CodeExpression valueExpression = valueGenerator.ProcessGenerators(classType, initMethod, resourceValue, "r_" + uniqueId, dictionary);

                if (valueExpression != null)
                {
                    CodeMethodInvokeExpression addResourceMethod = new CodeMethodInvokeExpression(fieldReference, "Add", keyExpression, valueExpression);
                    initMethod.Statements.Add(addResourceMethod);
                }

                uniqueId++;
            }
        }
Exemple #10
0
 protected override void GenerateComment(CodeComment e)
 {
     bool fMultiline = false;
     string escapedComment = this.GetEscapedComment(e.Text, ref fMultiline);
     if (e.DocComment)
     {
         base.Output.Write("/** ");
         base.Output.Write(escapedComment);
         base.Output.WriteLine(" */");
     }
     else if (fMultiline)
     {
         base.Output.Write("/* ");
         base.Output.Write(escapedComment);
         base.Output.WriteLine(" */");
     }
     else
     {
         base.Output.Write("// ");
         base.Output.WriteLine(escapedComment);
     }
 }
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of <see cref='System.CodeDom.CodeCommentStatement'/> with the specified text as
 ///       contents.
 ///    </para>
 /// </devdoc>
 public CodeCommentStatement(string text) {
     comment = new CodeComment(text);
 }
		protected override void GenerateComment(CodeComment e)
		{
			Output.WriteLine("[CodeComment: {0}]", e.ToString());
		}
Exemple #13
0
		protected override void GenerateComment (CodeComment e)
		{
		}
 public CodeCommentStatement(CodeComment comment)
 {
     this.comment = comment;
 }
Exemple #15
0
		protected abstract void GenerateComment (CodeComment comment);
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public CodeCommentStatement(CodeComment comment)
 {
     _comment = comment;
 }
        private  void GenerateComment(CodeComment e) {
            String commentLineStart = e.DocComment? "///": "//";
            Output.Write(commentLineStart);
            Output.Write(" ");

            string value = e.Text;
            for (int i=0; i<value.Length; i++) {
                if( value[i] == '\u0000') {
                    continue;
                }
                Output.Write(value[i]);

                if( value[i] == '\r') {
                    if (i < value.Length - 1 && value[i+1] == '\n') { // if next char is '\n', skip it
                        Output.Write('\n');
                        i++;
                    }
                    ((IndentedTextWriter)Output).InternalOutputTabs();
                    Output.Write(commentLineStart);
                }
                else if( value[i] == '\n') {
                    ((IndentedTextWriter)Output).InternalOutputTabs();
                    Output.Write(commentLineStart);
                }
                else if( value[i] == '\u2028' || value[i] == '\u2029' || value[i] == '\u0085') {
                    Output.Write(commentLineStart);
                }
            }
            Output.WriteLine();
        }
 public CodeCommentStatement(CodeComment comment)
 {
 }
		public void CodeCommentStatementTest ()
		{
			CodeCommentStatement commentStatement = new CodeCommentStatement ();
			CodeComment comment = new CodeComment ();
			commentStatement.Comment = comment;
			statement = commentStatement;

			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"// \n", NewLine), Generate (), "#1");

			comment.Text = "a\nb";
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"// a\n//b\n", NewLine), Generate (), "#2");

			comment.Text = "a\r\nb";
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"// a\r\n//b{0}", NewLine), Generate (), "#3");

			comment.Text = "a\rb";
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"// a\r//b{0}", NewLine), Generate (), "#4");
		}
Exemple #20
0
 public CodeCommentStatement(String text)
 {
     this.comment = new CodeComment(text);
 }
 public bool ValidateCodeComment (CodeComment exp){
     return true;
 }
Exemple #22
0
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public CodeCommentStatement(CodeComment comment)
 {
     _comment = comment;
 }
Exemple #23
0
 private void ValidateComment(CodeComment e) {
 }
 protected override void GenerateComment(CodeComment e)
 {
     string[] lines = e.Text.Split('\n');
     foreach (string line in lines) {
         Write("# ");
         WriteLine(line);
     }
 }
Exemple #25
0
 protected override void GenerateComment(CodeComment e) {
     String text = ConvertToCommentEscapeCodes(e.Text);
     if (e.DocComment) {
         Output.Write("/// ");
     } else {
         Output.Write("// ");
     }
     Output.WriteLine(text);
 }
Exemple #26
0
 private void Write(CodeComment e){
   if (e == null) return;
   TextWriter w = this.writer;
   this.WriteIndent();
   if (e.DocComment) w.Write("/// "); else w.Write("// ");
   string str = e.Text;
   int n = str == null ? 0 : str.Length;
   for (int i=0; i < n; i++){
     char ch = str[i];
     if (ch == 0) continue;
     switch (ch){
       case '\r':
         if (i < n-1 && str[i+1] == '\n'){
           w.Write(ch);
           i++; ch = '\n';
         }
         goto case '\n';
       case '\n':
       case '\u2028':
       case '\u2029':
         w.Write(ch);
         w.Write("//"); 
         break;
       default:
         w.Write(ch); 
         break;
     }
   }
 }
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of <see cref='System.CodeDom.CodeCommentStatement'/> with the specified text as
 ///       contents.
 ///    </para>
 /// </devdoc>
 public CodeCommentStatement(string text)
 {
     _comment = new CodeComment(text);
 }
 private void GenerateComment(CodeComment e)
 {
     string str = e.DocComment ? "///" : "//";
     this.Output.Write(str);
     this.Output.Write(" ");
     string text = e.Text;
     for (int i = 0; i < text.Length; i++)
     {
         if (text[i] != '\0')
         {
             this.Output.Write(text[i]);
             if (text[i] == '\r')
             {
                 if ((i < (text.Length - 1)) && (text[i + 1] == '\n'))
                 {
                     this.Output.Write('\n');
                     i++;
                 }
                 ((IndentedTextWriter) this.Output).InternalOutputTabs();
                 this.Output.Write(str);
             }
             else if (text[i] == '\n')
             {
                 ((IndentedTextWriter) this.Output).InternalOutputTabs();
                 this.Output.Write(str);
             }
             else if (((text[i] == '\u2028') || (text[i] == '\u2029')) || (text[i] == '\x0085'))
             {
                 this.Output.Write(str);
             }
         }
     }
     this.Output.WriteLine();
 }
Exemple #29
0
		protected override void GenerateComment (CodeComment comment)
		{
			TextWriter output = Output;
			string commentChars = null;

			if (comment.DocComment) {
				commentChars = "'''";
			} else {
				commentChars = "'";
			}
	
			output.Write (commentChars);
			string text = comment.Text;

			for (int i = 0; i < text.Length; i++) {
				output.Write (text [i]);
				if (text[i] == '\r') {
					if (i < (text.Length - 1) && text [i + 1] == '\n') {
						continue;
					}
					output.Write (commentChars);
				} else if (text [i] == '\n') {
					output.Write (commentChars);
				}
			}

			output.WriteLine ();
		}
Exemple #30
0
 protected override void GenerateComment(System.CodeDom.CodeComment e)
 {
     Output.WriteLine("// " + e.Text);
 }
 public CodeCommentStatement(string text, bool docComment)
 {
     this.comment = new CodeComment(text, docComment);
 }
 protected override void GenerateComment(CodeComment e) {
   string commentText = e.Text;
   StringBuilder b = new StringBuilder(commentText.Length * 2);
   string commentPrefix = e.DocComment ? "///" : "//";
   // escape the comment text
   b.Append(commentPrefix);
   for (int i=0; i < commentText.Length; i++){
     switch (commentText[i]){
       // suppress '@' to prevent compiler directives in comments
       case '@':
         break;
       case '\r':
         if (i < commentText.Length - 1 && commentText[i+1] == '\n') {
           b.Append("\r\n" + commentPrefix);
           i++;
         }
         else {
           b.Append("\r" + commentPrefix);
         }
         break;
       case '\n':
         b.Append("\n" + commentPrefix);
         break;
       case '\u2028':
         b.Append("\u2028" + commentPrefix);
         break;
       case '\u2029':
         b.Append("\u2029" + commentPrefix);
         break;
       default:
         b.Append(commentText[i]);
         break;
     }
   }
   Output.WriteLine(b.ToString());
 }
 protected override void GenerateComment(CodeComment e)
 {
     string str = e.DocComment ? "'''" : "'";
     base.Output.Write(str);
     string text = e.Text;
     for (int i = 0; i < text.Length; i++)
     {
         base.Output.Write(text[i]);
         if (text[i] == '\r')
         {
             if ((i < (text.Length - 1)) && (text[i + 1] == '\n'))
             {
                 base.Output.Write('\n');
                 i++;
             }
             ((IndentedTextWriter)base.Output).InternalOutputTabs();
             base.Output.Write(str);
         }
         else if (text[i] == '\n')
         {
             ((IndentedTextWriter)base.Output).InternalOutputTabs();
             base.Output.Write(str);
         }
         else if (((text[i] == '\u2028') || (text[i] == '\u2029')) || (text[i] == '\x0085'))
         {
             base.Output.Write(str);
         }
     }
     base.Output.WriteLine();
 }
 private void GenerateComment(CodeComment e)
 {
     string text1 = e.DocComment ? "///" : "//";
     this.Output.Write(text1);
     this.Output.Write(" ");
     string text2 = e.Text;
     for (int num1 = 0; num1 < text2.Length; num1++)
     {
         if (text2[num1] != '\0')
         {
             this.Output.Write(text2[num1]);
             if (text2[num1] == '\r')
             {
                 if ((num1 < (text2.Length - 1)) && (text2[num1 + 1] == '\n'))
                 {
                     this.Output.Write('\n');
                     num1++;
                 }
                 OutputTabs((IndentedTextWriter)this.Output);
                 this.Output.Write(text1);
             }
             else if (text2[num1] == '\n')
             {
                 OutputTabs((IndentedTextWriter)this.Output);
                 this.Output.Write(text1);
             }
             else if (((text2[num1] == '\u2028') || (text2[num1] == '\u2029')) || (text2[num1] == '\x0085'))
             {
                 this.Output.Write(text1);
             }
         }
     }
     this.Output.WriteLine();
 }
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public CodeCommentStatement(CodeComment comment) {
     this.comment = comment;
 }
Exemple #36
0
 public CodeCommentStatement(CodeComment comment)
 {
     throw new NotImplementedException();
 }
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public CodeCommentStatement(string text, bool docComment) {
     comment = new CodeComment(text, docComment);
 }
Exemple #38
0
        /// <summary>
        /// Generates code for the specified comment.
        /// </summary>
        /// <remarks><c>// TEXT</c> or <c>/** TEST */</c></remarks>
        protected override void GenerateComment(CodeComment e)
        {
            string[] lines = e.Text.Split('\n');

            if (e.DocComment) Output.WriteLine(Tokens.DocCommentLeft);

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i].TrimEnd(' ', '\t', '\r');

                if (e.DocComment)
                {
                    Output.Write(Tokens.DocCommentMiddle);
                    line = line.Replace(Tokens.CommentRight, "*_/");
                }
                else Output.Write(Tokens.Comment);

                Output.Write(WhiteSpace.Space);
                Output.WriteLine(line);
            }

            if (e.DocComment) Output.WriteLine(Tokens.DocCommentRight);
        }