Example #1
0
        private CodeGenUtil()
        {
            NamespaceImports = new CodeNamespaceImport[] {
                new CodeNamespaceImport("System"),
                new CodeNamespaceImport("System.Collections.Generic"),
                new CodeNamespaceImport("System.Text"),
                new CodeNamespaceImport("Avro"),
                new CodeNamespaceImport("Avro.Specific") };

            FileComment = new CodeCommentStatement(
            @"------------------------------------------------------------------------------
             <auto-generated>
            Generated by " + System.AppDomain.CurrentDomain.FriendlyName + ", version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version + @"
            Changes to this file may cause incorrect behavior and will be lost if code
            is regenerated
             </auto-generated>
             ------------------------------------------------------------------------------");

            // Visual Studio 2010 http://msdn.microsoft.com/en-us/library/x53a06bb.aspx
            ReservedKeywords = new HashSet<string>() {
                "abstract","as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class",
                "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event",
                "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if",
                "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new",
                "null", "object", "operator", "out", "override", "params", "private", "protected", "public",
                "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static",
                "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong",
                "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while", "value", "partial" };
        }
Example #2
0
		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");
		}
 /// <devdoc>
 /// <para>Copies the elements of an array to the end of the <see cref='System.CodeDom.CodeCommentStatementCollection'/>.</para>
 /// </devdoc>
 public void AddRange(CodeCommentStatement[] value) {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) {
         this.Add(value[i]);
     }
 }
		public void Constructor1_NullItem ()
		{
			CodeCommentStatement[] statements = new CodeCommentStatement[] { 
				new CodeCommentStatement (), null };

			CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
				statements);
		}
Example #5
0
        public static CodeCommentStatement Clone(CodeCommentStatement codestatementcol)
        {
            return new CodeCommentStatement()
            {
                Comment = Clone(codestatementcol.Comment)
                //EndDirectives =

            };
        }
 public TypescriptCommentStatement(
     IExpressionFactory expressionFactory,
     CodeCommentStatement statement,
     CodeGeneratorOptions options)
 {
     _expressionFactory = expressionFactory;
     _statement = statement;
     _options = options;
 }
Example #7
0
        private void EmitComment(CodeCommentStatement comment)
        {
            if (string.IsNullOrEmpty(comment.Comment.Text))
                return;

            writer.Write(Parser.SingleSpace);
            writer.Write(Parser.DefaultComment);
            writer.Write(Parser.SingleSpace);
            writer.Write(comment.Comment.Text);
        }
		public void AddRange (CodeCommentStatement [] value )
		{
			if (value == null) {
				throw new ArgumentNullException ("value");
			}

			for (int i = 0; i < value.Length; i++) {
				Add (value[i]);
			}
		}
		public void DefaultCodeCommentStatementTest ()
		{
			CodeCommentStatement commentStatement = new CodeCommentStatement ();
			CodeComment comment = new CodeComment ();
			
			commentStatement.Comment = comment;
			statement = commentStatement;
			
			Generate ();
			Assertion.AssertEquals ("// \n", Code);
		}
		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 void Constructor1 ()
		{
			CodeCommentStatement ccs1 = new CodeCommentStatement ();
			CodeCommentStatement ccs2 = new CodeCommentStatement ();

			CodeCommentStatement[] statements = new CodeCommentStatement[] { ccs1, ccs2 };
			CodeCommentStatementCollection coll = new CodeCommentStatementCollection (
				statements);

			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
		}
		public void Constructor2 ()
		{
			CodeCommentStatement ccs1 = new CodeCommentStatement ();
			CodeCommentStatement ccs2 = new CodeCommentStatement ();

			CodeCommentStatementCollection c = new CodeCommentStatementCollection ();
			c.Add (ccs1);
			c.Add (ccs2);

			CodeCommentStatementCollection coll = new CodeCommentStatementCollection (c);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="member"></param>
        /// <param name="inner"></param>
        /// <param name="attrs"></param>
        /// <returns></returns>
        public CodeTypeMember CreateMember(MemberInfo member, CodeFieldReferenceExpression inner, MemberAttributes attrs)
        {
            Debug.Assert(member is MethodInfo);
            MethodInfo method = member as MethodInfo;
            CodeMemberMethod codeMethod = new CodeMemberMethod();

            codeMethod.Name = method.Name;
            codeMethod.ReturnType = new CodeTypeReference(method.ReturnType);
            codeMethod.Attributes = attrs;

            // try
            CodeTryCatchFinallyStatement tryCode = new CodeTryCatchFinallyStatement();

            // decleare parameters
            List<CodeArgumentReferenceExpression> codeParamiteRefrs = new List<CodeArgumentReferenceExpression>();

            foreach (ParameterInfo codeParameter in method.GetParameters()) {
                CodeParameterDeclarationExpression codeParameterDeclare = new CodeParameterDeclarationExpression(codeParameter.ParameterType, codeParameter.Name);
                codeMethod.Parameters.Add(codeParameterDeclare);
                codeParamiteRefrs.Add(new CodeArgumentReferenceExpression(codeParameter.Name));
            }

            // invoke
            CodeMethodInvokeExpression invokeMethod = new CodeMethodInvokeExpression(
                inner, method.Name, codeParamiteRefrs.ToArray());
            if (method.ReturnType.Name.ToLower() == "void") {
                tryCode.TryStatements.Add(invokeMethod);
            } else {
                CodeVariableDeclarationStatement var = new CodeVariableDeclarationStatement(method.ReturnType, "returnObject", invokeMethod);
                //CodeAssignStatement assign = new CodeAssignStatement(var, invokeMethod);
                tryCode.TryStatements.Add(var);

                CodeCommentStatement todo = new CodeCommentStatement("TODO: your code", false);
                tryCode.TryStatements.Add(todo);

                CodeVariableReferenceExpression varRef = new CodeVariableReferenceExpression("returnObject");
                CodeMethodReturnStatement codeReturn = new CodeMethodReturnStatement(varRef);
                tryCode.TryStatements.Add(codeReturn);
            }

            // catch
            CodeTypeReference codeTypeRef = new CodeTypeReference(typeof(Exception));
            CodeCatchClause catchClause = new CodeCatchClause("ex", codeTypeRef);
            catchClause.Statements.Add(new CodeThrowExceptionStatement());
            tryCode.CatchClauses.Add(catchClause);

            codeMethod.Statements.Add(tryCode);
            return codeMethod;
        }
Example #14
0
        public static void IgnoreDateTimeSerializeAsString(CodeTypeDeclaration codeDeclTimeType)
        {
            // Remove "time" member codeattributes and add XmlIgnore
            var valueMember = codeDeclTimeType.Members.Cast<CodeTypeMember>().Where(m => m.Name == "Value").Single();
            valueMember.CustomAttributes.Clear();
            valueMember.CustomAttributes.Add(new CodeAttributeDeclaration("System.Xml.Serialization.XmlIgnore"));

            string commentLine = "New serialized string type is declared in file UBL-UnqualifiedDataTypes-2.1.partial.cs";
            CodeCommentStatement memberCommentStatement = new CodeCommentStatement(commentLine, false);
            valueMember.Comments.Add(memberCommentStatement);

            // Modify class attributes. Make it possible to step into partial class with debugger
            var debuggerStepThroughAttribute = codeDeclTimeType.CustomAttributes.OfType<CodeAttributeDeclaration>()
                .Where(a => a.Name == "System.Diagnostics.DebuggerStepThroughAttribute").SingleOrDefault();
            if (debuggerStepThroughAttribute != null)
            {
                codeDeclTimeType.CustomAttributes.Remove(debuggerStepThroughAttribute);
            }
        }
Example #15
0
        /// <summary>
        /// Tests this instance.
        /// </summary>
        /// <returns>the dumped object </returns>
        public string Test()
        {
            //var element = "My String".ToCharArray().AsQueryable();
            var element = "My String".ToCharArray().Select(e => new { e, Depp = (uint)e }).AsQueryable();
            element.Dump(2);

            /*ConstantExpression blockExpr = Expression.Constant(

                Expression.Constant(42)
            );

            blockExpr.Dump(2);*/

            // TestXmlSeria();
            var testObject = new CodeTypeDeclaration("DeclClass");
            var method = new CodeMemberMethod { Name = "MyMethod" };
            testObject.Members.Add(method);
            var method2 = new CodeMemberMethod { Name = "OtherMethod" };
            testObject.Members.Add(method2);
            var comment = new CodeCommentStatement("This is a comment");
            method.Statements.Add(comment);
            var prop = new CodeMemberProperty { Name = "MyProperty", Type = new CodeTypeReference(typeof(string)) };
            testObject.Members.Add(prop);

            testObject.Dump("The description", 5);

            // var res = Extensions.Text;
            return string.Empty;

            /* var ms = new MemoryStream();
            var writer = new StreamWriter(ms);
            var swriter = new StringWriter();
            ObjectDumper.Write(testObject, int.MaxValue, swriter);
            //var xx = ms.ToString();
            var result = swriter.ToString();*/
        }
Example #16
0
			public void Visit (CodeCommentStatement o)
			{
				g.GenerateCommentStatement (o);
			}
 private static void PrintCommentStatement(TextWriter output, CodeCommentStatement statement)
 {
     output.Write("comment '{0}'", statement.Comment.Text.Replace("'", "\\'"));
 }
Example #18
0
 public int Add(CodeCommentStatement value) => List.Add(value);
Example #19
0
 public bool Contains(CodeCommentStatement value) => List.Contains(value);
Example #20
0
 public int IndexOf(CodeCommentStatement value) => List.IndexOf(value);
 /// <devdoc>
 /// <para>Inserts a <see cref='System.CodeDom.CodeCommentStatement'/> into the <see cref='System.CodeDom.CodeCommentStatementCollection'/> at the specified index.</para>
 /// </devdoc>
 public void Insert(int index, CodeCommentStatement value)
 {
     List.Insert(index, value);
 }
Example #22
0
        private void AddPropertyJava(CodeTypeDeclaration ctd, CodeTypeReference ctrfield, CodeCommentStatement propertyComment, string mangledName,
            CodeFieldReferenceExpression fieldRef, bool isInterface)
        {
            var property = new CodeMemberMethod();
            mangledName = ToLangCase(mangledName, true);
            property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            property.Name = "get" + mangledName;
            property.ReturnType = ctrfield;
            if (!isInterface) property.Statements.Add(new CodeMethodReturnStatement(fieldRef));
            if (null != propertyComment)
                property.Comments.Add(propertyComment);
            // Add field property to class
            ctd.Members.Add(property);
            
            if (isInterface) return;

            property = new CodeMemberMethod();
            property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            property.Name = "set" + mangledName;
            property.Parameters.Add(new CodeParameterDeclarationExpression(ctrfield, "value"));
            property.Statements.Add(new CodeAssignStatement(fieldRef,
                                                            new CodePropertySetValueReferenceExpression()));
            if (null != propertyComment)
                property.Comments.Add(propertyComment);
            // Add field property to class
            ctd.Members.Add(property);
        }
Example #23
0
 private bool IsDocComment(CodeCommentStatement comment)
 {
     return (((comment != null) && (comment.Comment != null)) && comment.Comment.DocComment);
 }
Example #24
0
 /// <summary>
 /// Get return CodeCommentStatement comment
 /// </summary>
 /// <param name="text">Return text comment</param>
 /// <returns>return return comment statment</returns>
 internal static CodeCommentStatement GetReturnComment(string text)
 {
     var comments = new CodeCommentStatement(string.Format("<returns>{0}</returns>", text), true);
     return comments;
 }
 /// <devdoc>
 ///    <para>Adds a <see cref='System.CodeDom.CodeCommentStatement'/> with the specified value to the
 ///    <see cref='System.CodeDom.CodeCommentStatementCollection'/> .</para>
 /// </devdoc>
 public int Add(CodeCommentStatement value)
 {
     return(List.Add(value));
 }
 /// <devdoc>
 ///    <para> Removes a specific <see cref='System.CodeDom.CodeCommentStatement'/> from the
 ///    <see cref='System.CodeDom.CodeCommentStatementCollection'/> .</para>
 /// </devdoc>
 public void Remove(CodeCommentStatement value)
 {
     List.Remove(value);
 }
Example #27
0
		protected virtual void GenerateCommentStatement (CodeCommentStatement statement)
		{
			GenerateComment (statement.Comment);
		}
 /// <devdoc>
 /// <para>Gets a value indicating whether the
 ///    <see cref='System.CodeDom.CodeCommentStatementCollection'/> contains the specified <see cref='System.CodeDom.CodeCommentStatement'/>.</para>
 /// </devdoc>
 public bool Contains(CodeCommentStatement value)
 {
     return(List.Contains(value));
 }
Example #29
0
        private void AddProperty(CodeTypeDeclaration ctd, CodeTypeReference ctrfield, CodeCommentStatement propertyComment, string mangledName,
            CodeFieldReferenceExpression fieldRef, bool isInterface)
        {

            if (DoJava)
            {
                AddPropertyJava(ctd, ctrfield, propertyComment, mangledName, fieldRef, isInterface);
                return;
            }
            var property = new CodeMemberProperty();
            if (!isInterface) property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            property.Name = mangledName;
            property.Type = ctrfield;
            property.HasGet = true;
            if (isInterface)
            {
                property.HasSet = false;
            }
            else
            {
                property.GetStatements.Add(new CodeMethodReturnStatement(fieldRef));
                property.SetStatements.Add(new CodeAssignStatement(fieldRef,
                                                                   new CodePropertySetValueReferenceExpression()));
            }
            if (null != propertyComment)
                property.Comments.Add(propertyComment);
            // Add field property to class
            ctd.Members.Add(property);
        }
		public void Remove ()
		{
			CodeCommentStatement ccs1 = new CodeCommentStatement ();
			CodeCommentStatement ccs2 = new CodeCommentStatement ();

			CodeCommentStatementCollection coll = new CodeCommentStatementCollection ();
			coll.Add (ccs1);
			coll.Add (ccs2);
			Assert.AreEqual (2, coll.Count, "#1");
			Assert.AreEqual (0, coll.IndexOf (ccs1), "#2");
			Assert.AreEqual (1, coll.IndexOf (ccs2), "#3");
			coll.Remove (ccs1);
			Assert.AreEqual (1, coll.Count, "#4");
			Assert.AreEqual (-1, coll.IndexOf (ccs1), "#5");
			Assert.AreEqual (0, coll.IndexOf (ccs2), "#6");
		}
		private void Comment(CodeTypeMember member, string comment)
		{
			CodeCommentStatement statement;

			if (comment != null)
				statement = new CodeCommentStatement(string.Format("<summary>{0}</summary>", comment), true);
			else
				statement = new CodeCommentStatement("<summary/>", true);

			if (member is CodeMemberMethod)
			{
				foreach (CodeParameterDeclarationExpression param in (member as CodeMemberMethod).Parameters)
					statement.Comment.Text += string.Format("<param name=\"{0}\"/>", param.Name);
			}
			member.Comments.Add(statement);
		}
 /// <devdoc>
 ///    <para>Returns the index of a <see cref='System.CodeDom.CodeCommentStatement'/> in
 ///       the <see cref='System.CodeDom.CodeCommentStatementCollection'/> .</para>
 /// </devdoc>
 public int IndexOf(CodeCommentStatement value)
 {
     return(List.IndexOf(value));
 }
        internal static void GenerateXmlComments(CodeTypeMember ctm, string comment)
        {
            // generate xml comments

            // /// <summary>
            // /// </summary>
            CodeCommentStatement ccs = new CodeCommentStatement(SummaryStartTag, true);
            ctm.Comments.Add(ccs);
            ccs = new CodeCommentStatement(comment, true);
            ctm.Comments.Add(ccs);
            ccs = new CodeCommentStatement(SummaryEndTag, true);
            ctm.Comments.Add(ccs);
        }
Example #34
0
        private static void PopulateNamespace(ICodeGenerator itfCG, TextWriter w)
        {
            // Add a code comment.
            CodeCommentStatement c = new CodeCommentStatement("This is the wicked cool Hello class");
            itfCG.GenerateCodeFromStatement(c, w, null);

            // Build root namespace.
            CodeNamespace cnamespace = new CodeNamespace("SimpleCodeDOMHelloClass");

            // Reference other namespaces.
            cnamespace.Imports.Add(new CodeNamespaceImport ("System") );
            cnamespace.Imports.Add(new CodeNamespaceImport ("System.Windows.Forms") );

            // Insert the HelloClass.
            CodeTypeDeclaration co = new CodeTypeDeclaration ("HelloClass");
            co.IsClass = true;
            cnamespace.Types.Add(co);
            co.BaseTypes.Add (typeof (System.Object) );
            co.TypeAttributes  = TypeAttributes.Public;

            // Make a custom construcor.
            CodeConstructor ctor = new CodeConstructor();
            ctor.Attributes = MemberAttributes.Public;
            ctor.Parameters.Add(new CodeParameterDeclarationExpression
                (new CodeTypeReference(typeof(string)), "msg"));
            ctor.Statements.Add((new CodeAssignStatement(new CodeArgumentReferenceExpression("mMsg"),
                new CodeArgumentReferenceExpression("msg"))));
            co.Members.Add(ctor);

            // Add the default construcor.
            ctor = new CodeConstructor();
            ctor.Attributes = MemberAttributes.Public;
            co.Members.Add(ctor);

            // Insert a String field (mMsg).
            CodeMemberField cf = new CodeMemberField("System.String", "mMsg");
            cf.Comments.Add(new CodeCommentStatement("The state data..."));
            cf.Attributes = MemberAttributes.Private;
            co.Members.Add(cf);

            // Add the Message property.
            CodeMemberProperty  cp = new CodeMemberProperty();
            cp.Name = "Message";
            cp.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
            cp.Type = new CodeTypeReference("System.String");
            cp.Comments.Add(new CodeCommentStatement("The Message property"));
            // Getter.
            cp.GetStatements.Add(new CodeMethodReturnStatement
                (new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "mMsg")));
            // Setter.
            cp.SetStatements.Add(new CodeAssignStatement(new CodeArgumentReferenceExpression("mMsg"),
                new CodeArgumentReferenceExpression("value")));
            co.Members.Add (cp);

            // Add the Display() message.
            CodeMemberMethod cm = new CodeMemberMethod();
            cm.Name = "Display";
            cm.Attributes = MemberAttributes.Public | MemberAttributes.Final ;
            cm.Comments.Add(new CodeCommentStatement("Show 'em what we got!"));
            cm.Statements.Add (new CodeMethodInvokeExpression
                (new CodeTypeReferenceExpression("MessageBox"), "Show",
                new CodeExpression []
                {new CodeArgumentReferenceExpression  ("mMsg")}));
            co.Members.Add(cm);

            // Generate the code!
            itfCG.GenerateCodeFromNamespace (cnamespace, w, null);
        }
Example #35
0
 /// <summary>
 /// Get param comment statment
 /// </summary>
 /// <param name="paramName">Param Name</param>
 /// <param name="text">param summary</param>
 /// <returns>CodeCommentStatement param</returns>
 internal static CodeCommentStatement GetParamComment(string paramName, string text)
 {
     var comments = new CodeCommentStatement(string.Format("<param name=\"{0}\">{1}</param>", paramName, text), true);
     return comments;
 }
		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");
		}
 private void GenerateCodeFromCommentState(CodeCommentStatement e, TextWriter w, CodeGeneratorOptions o)
 {
     w.WriteLine("#" + e.Comment.Text);
 }
 /// <devdoc>
 ///    <para>
 ///       Generates code for the specified CodeDom based comment statement
 ///       representation.
 ///    </para>
 /// </devdoc>
 private void GenerateCommentStatement(CodeCommentStatement e) {
     GenerateComment(e.Comment);
 }