예제 #1
0
        /// <summary>
        /// Add the classes.
        /// </summary>
        private void AddClasses()
        {
            // Create the class and add base inheritance type.
            _targetClass                = new CodeTypeDeclaration(_className);
            _targetClass.IsClass        = true;
            _targetClass.IsPartial      = true;
            _targetClass.TypeAttributes = TypeAttributes.Public;
            _targetClass.BaseTypes.Add(new CodeTypeReference(_inheritanceCodeTypeReference));
            _targetClass.BaseTypes.Add(new CodeTypeReference("IDisposable"));

            // Create a custom region.
            CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, _className + " Data Extension Type");

            _targetClass.StartDirectives.Add(startRegion);

            // Create the comments on the class.
            _targetClass.Comments.Add(new CodeCommentStatement("<summary>", true));
            _targetClass.Comments.Add(new CodeCommentStatement("The " + _className.ToLower() + " replica object class.", true));
            _targetClass.Comments.Add(new CodeCommentStatement("</summary>", true));

            // Add the class members.
            AddMembers();

            // Create a custom endregion.
            CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");

            _targetClass.EndDirectives.Add(endRegion);

            // Add the class to the namespace
            // and add the namespace to the unit.
            samples.Types.Add(_targetClass);
        }
예제 #2
0
        /// <summary>
        /// Add the classes.
        /// </summary>
        private void AddClasses()
        {
            // For each type.
            foreach (JsonType classType in _typeList)
            {
                // Create the class and add base inheritance type.
                _targetClass                = new CodeTypeDeclaration(classType.AssignedName);
                _targetClass.IsClass        = true;
                _targetClass.IsPartial      = true;
                _targetClass.TypeAttributes = TypeAttributes.Public;

                // Create a custom region.
                CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, classType.AssignedName + " Data Type");
                _targetClass.StartDirectives.Add(startRegion);

                // Create the comments on the class.
                _targetClass.Comments.Add(new CodeCommentStatement("<summary>", true));
                _targetClass.Comments.Add(new CodeCommentStatement("The " + classType.AssignedName.ToLower() + " data object class.", true));
                _targetClass.Comments.Add(new CodeCommentStatement("</summary>", true));

                // Add the class members.
                AddMembers(classType, classType.Fields);

                // Create a custom endregion.
                CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");
                _targetClass.EndDirectives.Add(endRegion);

                // Add the class to the namespace
                // and add the namespace to the unit.
                _samples.Types.Add(_targetClass);
            }
        }
예제 #3
0
        /// <summary>
        /// Add the classes.
        /// </summary>
        private void AddClasses()
        {
            // Create the class and add base inheritance type.
            _targetClass                = new CodeTypeDeclaration(_className);
            _targetClass.IsClass        = true;
            _targetClass.IsPartial      = true;
            _targetClass.TypeAttributes = TypeAttributes.Public;

            // Create a custom region.
            CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, _className + " LinqToSql Type");

            _targetClass.StartDirectives.Add(startRegion);

            // Create the attributes on the class.
            _targetClass.CustomAttributes.Add(new CodeAttributeDeclaration("DataContractAttribute",
                                                                           new CodeAttributeArgument(new CodeSnippetExpression("Name = \"" + _className + "\", IsReference = true"))));
            _targetClass.CustomAttributes.Add(new CodeAttributeDeclaration("SerializableAttribute"));

            // Create the comments on the class.
            _targetClass.Comments.Add(new CodeCommentStatement("<summary>", true));
            _targetClass.Comments.Add(new CodeCommentStatement("The " + _className.ToLower() + " linqToSql object class.", true));
            _targetClass.Comments.Add(new CodeCommentStatement("</summary>", true));

            // Add the class members.
            AddMembers();

            // Create a custom endregion.
            CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");

            _targetClass.EndDirectives.Add(endRegion);

            // Add the class to the namespace
            // and add the namespace to the unit.
            _samples.Types.Add(_targetClass);
        }
예제 #4
0
        public void Ctor_CodeRegionMode_String(CodeRegionMode regionMode, string regionText)
        {
            var region = new CodeRegionDirective(regionMode, regionText);

            Assert.Equal(regionMode, region.RegionMode);
            Assert.Equal(regionText ?? string.Empty, region.RegionText);
        }
예제 #5
0
        public void RegionText_Set_Get_ReturnsExpected(string value)
        {
            var region = new CodeRegionDirective();

            region.RegionText = value;
            Assert.Equal(value ?? string.Empty, region.RegionText);
        }
예제 #6
0
        /// <summary>
        /// Add the classes.
        /// </summary>
        private void AddClasses()
        {
            // Create the class and add base inheritance type.
            _targetClass                = new CodeTypeDeclaration(_enumName);
            _targetClass.IsEnum         = true;
            _targetClass.TypeAttributes = TypeAttributes.Public;
            _targetClass.CustomAttributes.Add(new CodeAttributeDeclaration("SerializableAttribute"));
            _targetClass.CustomAttributes.Add(new CodeAttributeDeclaration("DataContractAttribute"));

            // Create a custom region.
            CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, _enumName + " Enum Type");

            _targetClass.StartDirectives.Add(startRegion);

            // Create the comments on the class.
            _targetClass.Comments.Add(new CodeCommentStatement("<summary>", true));
            _targetClass.Comments.Add(new CodeCommentStatement("The " + "enumerator " + _enumName.ToLower() + " object.", true));
            _targetClass.Comments.Add(new CodeCommentStatement("</summary>", true));

            // Add the class members.
            AddMembers();

            // Create a custom endregion.
            CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");

            _targetClass.EndDirectives.Add(endRegion);

            // Add the class to the namespace
            // and add the namespace to the unit.
            samples.Types.Add(_targetClass);
        }
예제 #7
0
        public void Ctor_Default()
        {
            var region = new CodeRegionDirective();

            Assert.Equal(CodeRegionMode.None, region.RegionMode);
            Assert.Empty(region.RegionText);
        }
예제 #8
0
 private static void ValidateRegionDirective(CodeRegionDirective e)
 {
     if (e.RegionText.IndexOfAny(s_newLineChars) != -1)
     {
         throw new ArgumentException(SR.Format(SR.InvalidRegion, e.RegionText));
     }
 }
예제 #9
0
 private static void ValidateRegionDirective(CodeRegionDirective e)
 {
     if (e.RegionText.IndexOfAny(newLineChars) != -1)
     {
         throw new ArgumentException(SR.GetString("InvalidRegion", new object[] { e.RegionText }));
     }
 }
예제 #10
0
        /// <summary>
        /// Add the classes.
        /// </summary>
        private void AddMataDataEtensionClasses()
        {
            // Create the class and add base inheritance type.
            _targetClass                = new CodeTypeDeclaration(_className);
            _targetClass.IsClass        = true;
            _targetClass.IsPartial      = true;
            _targetClass.TypeAttributes = TypeAttributes.Public;

            // Create a custom region.
            CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, _className + " Mvc Type");

            _targetClass.StartDirectives.Add(startRegion);

            // Create the attributes on the class.
            _targetClass.CustomAttributes.Add(new CodeAttributeDeclaration("MetadataTypeAttribute",
                                                                           new CodeAttributeArgument(new CodeSnippetExpression("typeof(" + _data.MetadataTypeExtension.FullName + ")"))));

            // Create the comments on the class.
            _targetClass.Comments.Add(new CodeCommentStatement("<summary>", true));
            _targetClass.Comments.Add(new CodeCommentStatement("The " + _className.ToLower() + " data object class.", true));
            _targetClass.Comments.Add(new CodeCommentStatement("</summary>", true));

            // Add the class members.
            AddMataDataEtensionMembers();

            // Create a custom endregion.
            CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");

            _targetClass.EndDirectives.Add(endRegion);

            // Add the class to the namespace
            // and add the namespace to the unit.
            _samples.Types.Add(_targetClass);
        }
예제 #11
0
        public void Value_Set_Get_ReturnsExpected(CodeRegionMode value)
        {
            var region = new CodeRegionDirective();

            region.RegionMode = value;
            Assert.Equal(value, region.RegionMode);
        }
        public void Constructor0_Deny_Unrestricted()
        {
            CodeRegionDirective crd = new CodeRegionDirective();

            Assert.AreEqual(CodeRegionMode.None, crd.RegionMode, "RegionMode");
            crd.RegionMode = CodeRegionMode.Start;
            Assert.AreEqual(String.Empty, crd.RegionText, "RegionText");
            crd.RegionText = "mono";
        }
        public void Constructor1_Deny_Unrestricted()
        {
            CodeRegionDirective crd = new CodeRegionDirective(CodeRegionMode.Start, "mono");

            Assert.AreEqual(CodeRegionMode.Start, crd.RegionMode, "RegionMode");
            crd.RegionMode = CodeRegionMode.End;
            Assert.AreEqual("mono", crd.RegionText, "RegionText");
            crd.RegionText = String.Empty;
        }
예제 #14
0
        public void InvalidRegionMode()
        {
            CodeRegionDirective crd = new CodeRegionDirective(
                (CodeRegionMode)int.MaxValue, "mono");

            Assert.AreEqual(int.MaxValue, (int)crd.RegionMode, "#1");
            crd.RegionMode = (CodeRegionMode)int.MinValue;
            Assert.AreEqual(int.MinValue, (int)crd.RegionMode, "#2");
        }
예제 #15
0
        private static void writeRegionStart(EventType evt, CodeMemberMethod _eventFeederMethod)
        {
            var regionpartialInvokerStart = new CodeRegionDirective( )
            {
                RegionMode = CodeRegionMode.Start,
                RegionText = evt.id
            };

            _eventFeederMethod.StartDirectives.Add(regionpartialInvokerStart);
        }
예제 #16
0
        public void EndDirectives_AddMultiple_ReturnsExpected()
        {
            CodeTypeMember member = new T();

            CodeRegionDirective directive1 = new CodeRegionDirective(CodeRegionMode.None, "Region1");

            member.EndDirectives.Add(directive1);
            Assert.Equal(new CodeRegionDirective[] { directive1 }, member.EndDirectives.Cast <CodeDirective>());

            CodeRegionDirective directive2 = new CodeRegionDirective(CodeRegionMode.None, "Region2");

            member.EndDirectives.Add(directive2);
            Assert.Equal(new CodeRegionDirective[] { directive1, directive2 }, member.EndDirectives.Cast <CodeDirective>());
        }
예제 #17
0
        public void EndDirectives_AddMultiple_ReturnsExpected()
        {
            var compileUnit = new CodeCompileUnit();

            CodeRegionDirective directive1 = new CodeRegionDirective(CodeRegionMode.None, "Region1");

            compileUnit.EndDirectives.Add(directive1);
            Assert.Equal(new CodeRegionDirective[] { directive1 }, compileUnit.EndDirectives.Cast <CodeDirective>());

            CodeRegionDirective directive2 = new CodeRegionDirective(CodeRegionMode.None, "Region2");

            compileUnit.EndDirectives.Add(directive2);
            Assert.Equal(new CodeRegionDirective[] { directive1, directive2 }, compileUnit.EndDirectives.Cast <CodeDirective>());
        }
예제 #18
0
        public void EndDirectives_AddMultiple_ReturnsExpected()
        {
            CodeStatement statement = new T();

            CodeRegionDirective directive1 = new CodeRegionDirective(CodeRegionMode.None, "Region1");

            statement.EndDirectives.Add(directive1);
            Assert.Equal(new CodeRegionDirective[] { directive1 }, statement.EndDirectives.Cast <CodeDirective>());

            CodeRegionDirective directive2 = new CodeRegionDirective(CodeRegionMode.None, "Region2");

            statement.EndDirectives.Add(directive2);
            Assert.Equal(new CodeRegionDirective[] { directive1, directive2 }, statement.EndDirectives.Cast <CodeDirective>());
        }
예제 #19
0
        public void Constructor1()
        {
            string         regionText = "mono";
            CodeRegionMode regionMode = CodeRegionMode.Start;

            CodeRegionDirective crd = new CodeRegionDirective(regionMode,
                                                              regionText);

            Assert.AreEqual(regionMode, crd.RegionMode, "#1");
            Assert.IsNotNull(crd.RegionText, "#2");
            Assert.AreSame(regionText, crd.RegionText, "#3");

            crd = new CodeRegionDirective(regionMode, (string)null);
            Assert.AreEqual(regionMode, crd.RegionMode, "#4");
            Assert.IsNotNull(crd.RegionText, "#5");
            Assert.AreEqual(string.Empty, crd.RegionText, "#6");
        }
예제 #20
0
        public void Constructor0()
        {
            CodeRegionDirective crd = new CodeRegionDirective();

            Assert.AreEqual(CodeRegionMode.None, crd.RegionMode, "#1");
            Assert.IsNotNull(crd.RegionText, "#2");
            Assert.AreEqual(string.Empty, crd.RegionText, "#3");

            crd.RegionText = null;
            Assert.IsNotNull(crd.RegionText, "#4");
            Assert.AreEqual(string.Empty, crd.RegionText, "#5");

            string regionText = "mono";

            crd.RegionText = regionText;
            Assert.AreSame(regionText, crd.RegionText, "#6");
        }
        private bool HandleDynamic(CodeRegionDirective obj, Context ctx)
        {
            bool res = true;

            switch (obj.RegionMode)
            {
            case CodeRegionMode.None:
                break;

            case CodeRegionMode.Start:
                res = WriteIfNotNullOrEmpty(GetRegionStartString(obj.RegionText), ctx);
                break;

            case CodeRegionMode.End:
                res = WriteIfNotNullOrEmpty(GetRegionEndString(), ctx);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(res);
        }
예제 #22
0
        internal void UCodeAddMethodSnippet(string codeSnippet, string methodName, Dictionary <string, string> methodAttribute = null)
        {
            CodeMemberMethod uCodeSnippetMethod = new CodeMemberMethod();

            uCodeSnippetMethod.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            uCodeSnippetMethod.Name       = methodName;
            if (methodAttribute != null)
            {
                CodeAttributeDeclarationCollection collection = new CodeAttributeDeclarationCollection();
                foreach (KeyValuePair <string, string> singleItem in methodAttribute)
                {
                    if (string.IsNullOrEmpty(singleItem.Value))
                    {
                        collection.Add(new CodeAttributeDeclaration(singleItem.Key));
                    }
                    else
                    {
                        collection.Add(new CodeAttributeDeclaration(singleItem.Key,
                                                                    new CodeAttributeArgument(new CodePrimitiveExpression(singleItem.Value))));
                    }
                }
                foreach (CodeAttributeDeclaration singleDeclaration in collection)
                {
                    uCodeSnippetMethod.CustomAttributes.Add(singleDeclaration);
                }
            }
            CodeSnippetStatement uCodeSnippet = new CodeSnippetStatement();

            uCodeSnippet.Value = codeSnippet;
            CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.End, "");

            startRegion.RegionText = "Code Injection";
            startRegion.RegionMode = CodeRegionMode.Start;
            uCodeSnippet.StartDirectives.Add(startRegion);
            uCodeSnippet.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));
            uCodeSnippetMethod.Statements.Add(uCodeSnippet);
            targetClass.Members.Add(uCodeSnippetMethod);
        }
예제 #23
0
        /// <summary>
        /// Add the classes.
        /// </summary>
        private void AddClasses()
        {
            // Create the class and add base inheritance type.
            _targetClass                = new CodeTypeDeclaration(_contextName);
            _targetClass.IsClass        = true;
            _targetClass.IsPartial      = true;
            _targetClass.TypeAttributes = TypeAttributes.Public;
            _targetClass.BaseTypes.Add(new CodeTypeReference("DataContextBase"));

            // Create a custom region.
            CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, _contextName + " Context Ling Type");

            _targetClass.StartDirectives.Add(startRegion);

            // Create the attributes on the class.
            _targetClass.CustomAttributes.Add(new CodeAttributeDeclaration("DatabaseAttribute",
                                                                           new CodeAttributeArgument(new CodeSnippetExpression("\"" + _dataBase + "\""))));

            // Create the comments on the class.
            _targetClass.Comments.Add(new CodeCommentStatement("<summary>", true));
            _targetClass.Comments.Add(new CodeCommentStatement("The " + _contextName.ToLower() + " data context object class.", true));
            _targetClass.Comments.Add(new CodeCommentStatement("</summary>", true));

            AddConstructors();
            AddConstants();
            AddExtensibilityMethods();
            AddMembers();

            // Create a custom endregion.
            CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");

            _targetClass.EndDirectives.Add(endRegion);

            // Add the class to the namespace
            // and add the namespace to the unit.
            samples.Types.Add(_targetClass);
        }
예제 #24
0
 private static void ValidateRegionDirective(CodeRegionDirective e)
 {
     if (e.RegionText.IndexOfAny(s_newLineChars) != -1)
         throw new ArgumentException(SR.Format(SR.InvalidRegion, e.RegionText));
 }
예제 #25
0
		public void Ctor_Default()
		{
			var region = new CodeRegionDirective();
			Assert.Equal(CodeRegionMode.None, region.RegionMode);
			Assert.Empty(region.RegionText);
		}
예제 #26
0
        public void RegionsSnippetsAndLinePragmas()
        {
            CodeCompileUnit cu = new CodeCompileUnit();
            CodeNamespace ns = new CodeNamespace("Namespace1");

            cu.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Compile Unit Region"));
            cu.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            cu.Namespaces.Add(ns);

            CodeTypeDeclaration cd = new CodeTypeDeclaration("Class1");
            ns.Types.Add(cd);

            cd.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Outer Type Region"));
            cd.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            cd.Comments.Add(new CodeCommentStatement("Outer Type Comment"));

            CodeMemberField field1 = new CodeMemberField(typeof(String), "field1");
            CodeMemberField field2 = new CodeMemberField(typeof(String), "field2");
            field1.Comments.Add(new CodeCommentStatement("Field 1 Comment"));
            field2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Field Region"));
            field2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeMemberEvent evt1 = new CodeMemberEvent();
            evt1.Name = "Event1";
            evt1.Type = new CodeTypeReference(typeof(System.EventHandler));
            evt1.Attributes = (evt1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            CodeMemberEvent evt2 = new CodeMemberEvent();
            evt2.Name = "Event2";
            evt2.Type = new CodeTypeReference(typeof(System.EventHandler));
            evt2.Attributes = (evt2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            evt2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Event Region"));
            evt2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeMemberMethod method1 = new CodeMemberMethod();
            method1.Name = "Method1";
            method1.Attributes = (method1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            method1.Statements.Add(
                new CodeDelegateInvokeExpression(
                    new CodeEventReferenceExpression(new CodeThisReferenceExpression(), "Event1"),
                    new CodeExpression[] {
                        new CodeThisReferenceExpression(),
                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
                    }));

            CodeMemberMethod method2 = new CodeMemberMethod();
            method2.Name = "Method2";
            method2.Attributes = (method2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            method2.Statements.Add(
                new CodeDelegateInvokeExpression(
                    new CodeEventReferenceExpression(new CodeThisReferenceExpression(), "Event2"),
                    new CodeExpression[] {
                    new CodeThisReferenceExpression(),
                    new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
                    }));
            method2.LinePragma = new CodeLinePragma("MethodLinePragma.txt", 500);
            method2.Comments.Add(new CodeCommentStatement("Method 2 Comment"));

            method2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Method Region"));
            method2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeMemberProperty property1 = new CodeMemberProperty();
            property1.Name = "Property1";
            property1.Type = new CodeTypeReference(typeof(string));
            property1.Attributes = (property1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            property1.GetStatements.Add(
                new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        "field1")));

            CodeMemberProperty property2 = new CodeMemberProperty();
            property2.Name = "Property2";
            property2.Type = new CodeTypeReference(typeof(string));
            property2.Attributes = (property2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            property2.GetStatements.Add(
                new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        "field2")));

            property2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Property Region"));
            property2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeConstructor constructor1 = new CodeConstructor();
            constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            CodeStatement conState1 = new CodeAssignStatement(
                                        new CodeFieldReferenceExpression(
                                            new CodeThisReferenceExpression(),
                                            "field1"),
                                        new CodePrimitiveExpression("value1"));
            conState1.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Statements Region"));
            constructor1.Statements.Add(conState1);
            CodeStatement conState2 = new CodeAssignStatement(
                                        new CodeFieldReferenceExpression(
                                            new CodeThisReferenceExpression(),
                                            "field2"),
                                        new CodePrimitiveExpression("value2"));
            conState2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));
            constructor1.Statements.Add(conState2);

            constructor1.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Constructor Region"));
            constructor1.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeConstructor constructor2 = new CodeConstructor();
            constructor2.Attributes = (constructor2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            constructor2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "value1"));
            constructor2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "value2"));

            CodeTypeConstructor typeConstructor2 = new CodeTypeConstructor();

            typeConstructor2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Type Constructor Region"));
            typeConstructor2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeEntryPointMethod methodMain = new CodeEntryPointMethod();

            CodeTypeDeclaration nestedClass1 = new CodeTypeDeclaration("NestedClass1");
            CodeTypeDeclaration nestedClass2 = new CodeTypeDeclaration("NestedClass2");
            nestedClass2.LinePragma = new CodeLinePragma("NestedTypeLinePragma.txt", 400);
            nestedClass2.Comments.Add(new CodeCommentStatement("Nested Type Comment"));

            nestedClass2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Nested Type Region"));
            nestedClass2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeTypeDelegate delegate1 = new CodeTypeDelegate();
            delegate1.Name = "nestedDelegate1";
            delegate1.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.Object"), "sender"));
            delegate1.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.EventArgs"), "e"));

            CodeTypeDelegate delegate2 = new CodeTypeDelegate();
            delegate2.Name = "nestedDelegate2";
            delegate2.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.Object"), "sender"));
            delegate2.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.EventArgs"), "e"));

            delegate2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Delegate Region"));
            delegate2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            var snippet1 = new CodeSnippetTypeMember();
            var snippet2 = new CodeSnippetTypeMember();

            CodeRegionDirective regionStart = new CodeRegionDirective(CodeRegionMode.End, "");
            regionStart.RegionText = "Snippet Region";
            regionStart.RegionMode = CodeRegionMode.Start;
            snippet2.StartDirectives.Add(regionStart);
            snippet2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            cd.Members.Add(field1);
            cd.Members.Add(method1);
            cd.Members.Add(constructor1);
            cd.Members.Add(property1);
            cd.Members.Add(methodMain);

            cd.Members.Add(evt1);
            cd.Members.Add(nestedClass1);
            cd.Members.Add(delegate1);

            cd.Members.Add(snippet1);

            cd.Members.Add(field2);
            cd.Members.Add(method2);
            cd.Members.Add(constructor2);
            cd.Members.Add(property2);

            cd.Members.Add(typeConstructor2);
            cd.Members.Add(evt2);
            cd.Members.Add(nestedClass2);
            cd.Members.Add(delegate2);
            cd.Members.Add(snippet2);

            AssertEqual(cu,
                @"#Region ""Compile Unit Region""
                  '------------------------------------------------------------------------------
                  ' <auto-generated>
                  '     This code was generated by a tool.
                  '     Runtime Version:4.0.30319.42000
                  '
                  '     Changes to this file may cause incorrect behavior and will be lost if
                  '     the code is regenerated.
                  ' </auto-generated>
                  '------------------------------------------------------------------------------
                  Option Strict Off
                  Option Explicit On
                  Namespace Namespace1
                      #Region ""Outer Type Region""
                      'Outer Type Comment
                      Public Class Class1
                          'Field 1 Comment
                          Private field1 As String
                          #Region ""Field Region""
                          Private field2 As String
                          #End Region
                          #Region ""Snippet Region""
                          #End Region
                          #Region ""Type Constructor Region""
                          Shared Sub New()
                          End Sub
                          #End Region
                          #Region ""Constructor Region""
                          Public Sub New()
                              MyBase.New
                              Me.field1 = ""value1""
                              Me.field2 = ""value2""
                          End Sub
                          #End Region
                          Public Sub New(ByVal value1 As String, ByVal value2 As String)
                              MyBase.New
                          End Sub
                          Public ReadOnly Property Property1() As String
                              Get
                                  Return Me.field1
                              End Get
                          End Property
                          #Region ""Property Region""
                          Public ReadOnly Property Property2() As String
                              Get
                                  Return Me.field2
                              End Get
                          End Property
                          #End Region
                          Public Event Event1 As System.EventHandler
                          #Region ""Event Region""
                          Public Event Event2 As System.EventHandler
                          #End Region
                          Public Sub Method1()
                              RaiseEvent Event1(Me, System.EventArgs.Empty)
                          End Sub
                          Public Shared Sub Main()
                          End Sub
                          #Region ""Method Region""
                          'Method 2 Comment
                          #ExternalSource(""MethodLinePragma.txt"",500)
                          Public Sub Method2()
                              RaiseEvent Event2(Me, System.EventArgs.Empty)
                          End Sub
                          #End ExternalSource
                          #End Region
                          Public Class NestedClass1
                          End Class
                          Public Delegate Sub nestedDelegate1(ByVal sender As Object, ByVal e As System.EventArgs)
                          #Region ""Nested Type Region""
                          'Nested Type Comment
                          #ExternalSource(""NestedTypeLinePragma.txt"",400)
                          Public Class NestedClass2
                          End Class
                          #End ExternalSource
                          #End Region
                          #Region ""Delegate Region""
                          Public Delegate Sub nestedDelegate2(ByVal sender As Object, ByVal e As System.EventArgs)
                          #End Region
                      End Class
                      #End Region
                  End Namespace
                  #End Region");
        }
예제 #27
0
 protected virtual void Visit(CodeRegionDirective directive)
 {
 }
예제 #28
0
 protected override void Visit(CodeRegionDirective directive)
 {
     base.Visit(directive);
 }
예제 #29
0
        // CodeDirectiveCollection
        public void CodeDirectiveCollectionExample()
        {
            //<Snippet1>
            //<Snippet2>
            // Creates an empty CodeDirectiveCollection.
            CodeDirectiveCollection collection = new CodeDirectiveCollection();

            //</Snippet2>

            //<Snippet3>
            // Adds a CodeDirective to the collection.
            collection.Add(new CodeRegionDirective(CodeRegionMode.Start, "Region1"));
            //</Snippet3>

            //<Snippet4>
            // Adds an array of CodeDirective objects to the collection.
            CodeDirective[] directives =
            {
                new CodeRegionDirective(CodeRegionMode.Start, "Region1"),
                new CodeRegionDirective(CodeRegionMode.End,   "Region1")
            };
            collection.AddRange(directives);

            // Adds a collection of CodeDirective objects to the collection.
            CodeDirectiveCollection directivesCollection = new CodeDirectiveCollection();

            directivesCollection.Add(new CodeRegionDirective(CodeRegionMode.Start, "Region2"));
            directivesCollection.Add(new CodeRegionDirective(CodeRegionMode.End, "Region2"));
            collection.AddRange(directivesCollection);
            //</Snippet4>

            //<Snippet5>
            // Tests for the presence of a CodeDirective in the
            // collection, and retrieves its index if it is found.
            CodeDirective testDirective = new CodeRegionDirective(CodeRegionMode.Start, "Region1");
            int           itemIndex     = -1;

            if (collection.Contains(testDirective))
            {
                itemIndex = collection.IndexOf(testDirective);
            }
            //</Snippet5>

            //<Snippet6>
            // Copies the contents of the collection beginning at index 0 to the specified CodeDirective array.
            // 'directives' is a CodeDirective array.
            collection.CopyTo(directives, 0);
            //</Snippet6>

            //<Snippet7>
            // Retrieves the count of the items in the collection.
            int collectionCount = collection.Count;

            //</Snippet7>

            //<Snippet8>
            // Inserts a CodeDirective at index 0 of the collection.
            collection.Insert(0, new CodeRegionDirective(CodeRegionMode.Start, "Region1"));
            //</Snippet8>

            //<Snippet9>
            // Removes the specified CodeDirective from the collection.
            CodeDirective directive = new CodeRegionDirective(CodeRegionMode.Start, "Region1");

            collection.Remove(directive);
            //</Snippet9>

            //<Snippet10>
            // Removes the CodeDirective at index 0.
            collection.RemoveAt(0);
            //</Snippet10>
            //</Snippet1>
        }
예제 #30
0
        /// <summary>
        /// Add the properties to the class.
        /// </summary>
        private void AddProperties()
        {
            int propertyCount = 0;
            CodeMemberProperty endProperty = null;

            // For each table in the database.
            foreach (var table in _tables)
            {
                if (_data.TableList.Contains(table.TableName.ToUpper(), new ToUpperComparer()) == !_tableListExclusion)
                {
                    // Create a new property member
                    // and the accessor type.
                    CodeMemberProperty tableProperty = new CodeMemberProperty();
                    tableProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;

                    // Add the region directive if at the beginning
                    if (propertyCount == 0)
                    {
                        // Create a custom region.
                        CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, "Public Context Extension Properties");
                        tableProperty.StartDirectives.Add(startRegion);

                        // Increment the count.
                        propertyCount++;
                    }

                    // Assign the name and get and set indictors.
                    tableProperty.Name   = table.TableName;
                    tableProperty.HasGet = true;

                    // Add the comments to the property.
                    tableProperty.Comments.Add(new CodeCommentStatement("<summary>", true));
                    tableProperty.Comments.Add(new CodeCommentStatement("Gets, the " + table.TableName.ToLower() + " replica property for the object.", true));
                    tableProperty.Comments.Add(new CodeCommentStatement("</summary>", true));

                    // Assign the return type.
                    tableProperty.Type = new CodeTypeReference((!String.IsNullOrEmpty(_extendedName) ? "LinqToSql." + _extendedName + "." : "LinqToSql.") + "Replica." + table.TableName);

                    //// Create a new code condition statement.
                    //CodeConditionStatement conditionalStatement = new CodeConditionStatement(
                    //    new CodeVariableReferenceExpression("(String.IsNullOrEmpty(_specificPath))"),
                    //    new CodeStatement[] {
                    //        new CodeExpressionStatement(
                    //            new CodeSnippetExpression("return new " +
                    //                (!String.IsNullOrEmpty(_extendedName) ? "LinqToSql." + _extendedName + "." : "LinqToSql.") + "Replica." + table.TableName + "()")) },
                    //    new CodeStatement[] {
                    //        new CodeExpressionStatement(
                    //            new CodeSnippetExpression("return new " +
                    //                (!String.IsNullOrEmpty(_extendedName) ? "LinqToSql." + _extendedName + "." : "LinqToSql.") + "Replica." + table.TableName + "(_specificPath)")) });

                    CodeExpressionStatement conditionalStatement = new CodeExpressionStatement(
                        new CodeSnippetExpression("return new " +
                                                  (!String.IsNullOrEmpty(_extendedName) ? "LinqToSql." + _extendedName + "." : "LinqToSql.") + "Replica." + table.TableName + "()"));

                    // Add the condition statement.
                    tableProperty.GetStatements.Add(conditionalStatement);

                    // Assign each property until the end.
                    endProperty = tableProperty;

                    // Add the property to the class.
                    _targetClass.Members.Add(tableProperty);
                }
            }

            if (endProperty != null)
            {
                // Create a custom endregion.
                CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");
                endProperty.EndDirectives.Add(endRegion);
            }

            propertyCount = 0;
            endProperty   = null;

            // if a views exist.
            if (GetDatabaseViews())
            {
                // For each table in the database.
                foreach (var view in _views)
                {
                    if (_data.TableList.Contains(view.TableName.ToUpper(), new ToUpperComparer()) == !_tableListExclusion)
                    {
                        // Create a new property member
                        // and the accessor type.
                        CodeMemberProperty tableProperty = new CodeMemberProperty();
                        tableProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;

                        // Add the region directive if at the beginning
                        if (propertyCount == 0)
                        {
                            // Create a custom region.
                            CodeRegionDirective startRegion = new CodeRegionDirective(CodeRegionMode.Start, "Public Context Extension Properties");
                            tableProperty.StartDirectives.Add(startRegion);

                            // Increment the count.
                            propertyCount++;
                        }

                        // Assign the name and get and set indictors.
                        tableProperty.Name   = view.TableName;
                        tableProperty.HasGet = true;

                        // Add the comments to the property.
                        tableProperty.Comments.Add(new CodeCommentStatement("<summary>", true));
                        tableProperty.Comments.Add(new CodeCommentStatement("Gets, the " + view.TableName.ToLower() + " replica property for the object.", true));
                        tableProperty.Comments.Add(new CodeCommentStatement("</summary>", true));

                        // Assign the return type.
                        tableProperty.Type = new CodeTypeReference((!String.IsNullOrEmpty(_extendedName) ? "LinqToSql." + _extendedName + "." : "LinqToSql.") + "Replica." + view.TableName);

                        //// Create a new code condition statement.
                        //CodeConditionStatement conditionalStatement = new CodeConditionStatement(
                        //    new CodeVariableReferenceExpression("(String.IsNullOrEmpty(_specificPath))"),
                        //    new CodeStatement[] {
                        //    new CodeExpressionStatement(
                        //        new CodeSnippetExpression("return new " +
                        //            (!String.IsNullOrEmpty(_extendedName) ? "LinqToSql." + _extendedName + "." : "LinqToSql.") + "Replica." + view.TableName + "()")) },
                        //    new CodeStatement[] {
                        //    new CodeExpressionStatement(
                        //        new CodeSnippetExpression("return new " +
                        //            (!String.IsNullOrEmpty(_extendedName) ? "LinqToSql." + _extendedName + "." : "LinqToSql.") + "Replica." + view.TableName + "(_specificPath)")) });

                        CodeExpressionStatement conditionalStatement = new CodeExpressionStatement(
                            new CodeSnippetExpression("return new " +
                                                      (!String.IsNullOrEmpty(_extendedName) ? "LinqToSql." + _extendedName + "." : "LinqToSql.") + "Replica." + view.TableName + "()"));

                        // Add the condition statement.
                        tableProperty.GetStatements.Add(conditionalStatement);

                        // Assign each property until the end.
                        endProperty = tableProperty;

                        // Add the property to the class.
                        _targetClass.Members.Add(tableProperty);
                    }
                }
            }

            if (endProperty != null)
            {
                // Create a custom endregion.
                CodeRegionDirective endRegion = new CodeRegionDirective(CodeRegionMode.End, "");
                endProperty.EndDirectives.Add(endRegion);
            }
        }
예제 #31
0
		public void Ctor_CodeRegionMode_String(CodeRegionMode regionMode, string regionText)
		{
			var region = new CodeRegionDirective(regionMode, regionText);
			Assert.Equal(regionMode, region.RegionMode);
			Assert.Equal(regionText ?? string.Empty, region.RegionText);
		}
예제 #32
0
        private CodeTypeDeclaration CreateDataContext(XDocument dtmlXml, IEnumerable <DocType> docTypes)
        {
            string methodName = "OnCreated";
            CodeExpressionStatement statement = new CodeExpressionStatement(new CodeMethodInvokeExpression(null, methodName, new CodeExpression[0]));

            string dataContextName = dtmlXml.Root.Attribute("DataContextName").Value;

            //ensure the naming is standard
            if (!dataContextName.ToUpper().Contains("DATACONTEXT"))
            {
                dataContextName += "DataContext";
            }
            CodeTypeDeclaration dataContext = new CodeTypeDeclaration(dataContextName);

            dataContext.BaseTypes.Add("UmbracoDataContext");
            dataContext.IsClass   = true;
            dataContext.IsPartial = true;

            string partialOnCreated = string.Empty;

            if (IsCSharpCodeProvider())
            {
                partialOnCreated = " partial void " + methodName + "();\r\n";
            }
            else
            {
                partialOnCreated = " Partial Private Void " + methodName + "()\r\nEnd Sub\r\n";
            }
            CodeSnippetTypeMember onCreated = new CodeSnippetTypeMember(partialOnCreated);
            CodeRegionDirective   region    = new CodeRegionDirective(CodeRegionMode.Start, "Partials");

            onCreated.StartDirectives.Add(region);
            onCreated.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, "Partials"));
            dataContext.Members.Add(onCreated);

            //constructor with no arguments
            CodeConstructor ctor = new CodeConstructor();

            ctor.Attributes = MemberAttributes.Public;
            ctor.BaseConstructorArgs.Add(new CodePropertyReferenceExpression());
            ctor.Statements.Add(statement);
            dataContext.Members.Add(ctor);

            //constructor that takes an umbracoDataProvider
            ctor            = new CodeConstructor();
            ctor.Attributes = MemberAttributes.Public;
            ctor.Parameters.Add(new CodeParameterDeclarationExpression("UmbracoDataProvider", "provider"));
            ctor.BaseConstructorArgs.Add(new CodePropertyReferenceExpression(null, "provider"));
            ctor.Statements.Add(statement);
            dataContext.Members.Add(ctor);

            //Generate the Tree<TDocType> for each docType
            foreach (var dt in docTypes)
            {
                string name = dt.TypeName;
                if (this.PluralizeCollections)
                {
                    name = PluraliseName(dt.TypeName);
                }
                var t = new CodeTypeReference("Tree");
                t.TypeArguments.Add(dt.TypeName);

                CodeMemberProperty p = new CodeMemberProperty();
                p.Name       = name;
                p.Type       = t;
                p.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                p.HasGet     = true;
                p.HasSet     = false;

                if (!Args.IsInterface)
                {
                    p.GetStatements.Add(
                        new CodeMethodReturnStatement(
                            new CodeMethodInvokeExpression(
                                new CodeMethodReferenceExpression(
                                    new CodeThisReferenceExpression(),
                                    "LoadTree",
                                    new CodeTypeReference[] {
                        new CodeTypeReference(dt.TypeName)
                    }),
                                new CodeExpression[0])
                            )
                        );
                }

                dataContext.Members.Add(p);
            }
            return(dataContext);
        }
예제 #33
0
		public void RegionText_Set_Get_ReturnsExpected(string value)
		{
			var region = new CodeRegionDirective();
			region.RegionText = value;
			Assert.Equal(value ?? string.Empty, region.RegionText);
		}
예제 #34
0
		public void Value_Set_Get_ReturnsExpected(CodeRegionMode value)
		{
			var region = new CodeRegionDirective();
			region.RegionMode = value;
			Assert.Equal(value, region.RegionMode);
		}
 public CodeRegion(string title)
 {
     Start = new CodeRegionDirective(CodeRegionMode.Start, title);
     End   = new CodeRegionDirective(CodeRegionMode.End, title);
 }
예제 #36
0
    public override void BuildTree(CodeDomProvider provider, CodeCompileUnit cu)
    {
#if WHIDBEY
        if (!(provider is JScriptCodeProvider))
        {
            // GENERATES (C#):
            //
            //  #region Compile Unit Region
            //
            //  namespace Namespace1 {
            //
            //
            //      #region Outer Type Region
            //      // Outer Type Comment
            //      public class Class1 {
            //
            //          // Field 1 Comment
            //          private string field1;
            //
            //          public void Method1() {
            //              this.Event1(this, System.EventArgs.Empty);
            //          }
            //
            //          #region Constructor Region
            //          public Class1() {
            //              #region Statements Region
            //              this.field1 = "value1";
            //              this.field2 = "value2";
            //              #endregion
            //          }
            //          #endregion
            //
            //          public string Property1 {
            //              get {
            //                  return this.field1;
            //              }
            //          }
            //
            //          public static void Main() {
            //          }
            //
            //          public event System.EventHandler Event1;
            //
            //          public class NestedClass1 {
            //          }
            //
            //          public delegate void nestedDelegate1(object sender, System.EventArgs e);
            //
            //
            //
            //          #region Field Region
            //          private string field2;
            //          #endregion
            //
            //          #region Method Region
            //          // Method 2 Comment
            //
            //          #line 500 "MethodLinePragma.txt"
            //          public void Method2() {
            //              this.Event2(this, System.EventArgs.Empty);
            //          }
            //
            //          #line default
            //          #line hidden
            //          #endregion
            //
            //          public Class1(string value1, string value2) {
            //          }
            //
            //          #region Property Region
            //          public string Property2 {
            //              get {
            //                  return this.field2;
            //              }
            //          }
            //          #endregion
            //
            //          #region Type Constructor Region
            //          static Class1() {
            //          }
            //          #endregion
            //
            //          #region Event Region
            //          public event System.EventHandler Event2;
            //          #endregion
            //
            //          #region Nested Type Region
            //          // Nested Type Comment
            //
            //          #line 400 "NestedTypeLinePragma.txt"
            //          public class NestedClass2 {
            //          }
            //
            //          #line default
            //          #line hidden
            //          #endregion
            //
            //          #region Delegate Region
            //          public delegate void nestedDelegate2(object sender, System.EventArgs e);
            //          #endregion
            //
            //          #region Snippet Region
            //
            //          #endregion
            //      }
            //      #endregion
            //  }
            //  #endregion

            CodeNamespace ns = new CodeNamespace("Namespace1");

            cu.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Compile Unit Region"));
            cu.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            cu.Namespaces.Add(ns);

            CodeTypeDeclaration cd = new CodeTypeDeclaration("Class1");
            ns.Types.Add(cd);

            cd.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Outer Type Region"));
            cd.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            cd.Comments.Add(new CodeCommentStatement("Outer Type Comment"));

            CodeMemberField field1 = new CodeMemberField(typeof(String), "field1");
            CodeMemberField field2 = new CodeMemberField(typeof(String), "field2");
            field1.Comments.Add(new CodeCommentStatement("Field 1 Comment"));
            field2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Field Region"));
            field2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeMemberEvent evt1 = new CodeMemberEvent();
            evt1.Name       = "Event1";
            evt1.Type       = new CodeTypeReference(typeof(System.EventHandler));
            evt1.Attributes = (evt1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            CodeMemberEvent evt2 = new CodeMemberEvent();
            evt2.Name       = "Event2";
            evt2.Type       = new CodeTypeReference(typeof(System.EventHandler));
            evt2.Attributes = (evt2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            evt2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Event Region"));
            evt2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));


            CodeMemberMethod method1 = new CodeMemberMethod();
            method1.Name       = "Method1";
            method1.Attributes = (method1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            if (provider.Supports(GeneratorSupport.DeclareEvents))
            {
                method1.Statements.Add(
                    new CodeDelegateInvokeExpression(
                        new CodeEventReferenceExpression(new CodeThisReferenceExpression(), "Event1"),
                        new CodeExpression[] {
                    new CodeThisReferenceExpression(),
                    new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
                }));
            }


            CodeMemberMethod method2 = new CodeMemberMethod();
            method2.Name       = "Method2";
            method2.Attributes = (method2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            if (provider.Supports(GeneratorSupport.DeclareEvents))
            {
                method2.Statements.Add(
                    new CodeDelegateInvokeExpression(
                        new CodeEventReferenceExpression(new CodeThisReferenceExpression(), "Event2"),
                        new CodeExpression[] {
                    new CodeThisReferenceExpression(),
                    new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
                }));
            }
            method2.LinePragma = new CodeLinePragma("MethodLinePragma.txt", 500);
            method2.Comments.Add(new CodeCommentStatement("Method 2 Comment"));

            method2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Method Region"));
            method2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));


            CodeMemberProperty property1 = new CodeMemberProperty();
            property1.Name       = "Property1";
            property1.Type       = new CodeTypeReference(typeof(string));
            property1.Attributes = (property1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            property1.GetStatements.Add(
                new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        "field1")));

            CodeMemberProperty property2 = new CodeMemberProperty();
            property2.Name       = "Property2";
            property2.Type       = new CodeTypeReference(typeof(string));
            property2.Attributes = (property2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            property2.GetStatements.Add(
                new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        "field2")));

            property2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Property Region"));
            property2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));


            CodeConstructor constructor1 = new CodeConstructor();
            constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            CodeStatement conState1 = new CodeAssignStatement(
                new CodeFieldReferenceExpression(
                    new CodeThisReferenceExpression(),
                    "field1"),
                new CodePrimitiveExpression("value1"));
            conState1.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Statements Region"));
            constructor1.Statements.Add(conState1);
            CodeStatement conState2 = new CodeAssignStatement(
                new CodeFieldReferenceExpression(
                    new CodeThisReferenceExpression(),
                    "field2"),
                new CodePrimitiveExpression("value2"));
            conState2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));
            constructor1.Statements.Add(conState2);

            constructor1.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Constructor Region"));
            constructor1.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeConstructor constructor2 = new CodeConstructor();
            constructor2.Attributes = (constructor2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            constructor2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "value1"));
            constructor2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "value2"));

            CodeTypeConstructor typeConstructor2 = new CodeTypeConstructor();

            typeConstructor2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Type Constructor Region"));
            typeConstructor2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));


            CodeEntryPointMethod methodMain = new CodeEntryPointMethod();

            CodeTypeDeclaration nestedClass1 = new CodeTypeDeclaration("NestedClass1");
            CodeTypeDeclaration nestedClass2 = new CodeTypeDeclaration("NestedClass2");
            nestedClass2.LinePragma = new CodeLinePragma("NestedTypeLinePragma.txt", 400);
            nestedClass2.Comments.Add(new CodeCommentStatement("Nested Type Comment"));

            nestedClass2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Nested Type Region"));
            nestedClass2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));



            CodeTypeDelegate delegate1 = new CodeTypeDelegate();
            delegate1.Name = "nestedDelegate1";
            delegate1.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.Object"), "sender"));
            delegate1.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.EventArgs"), "e"));

            CodeTypeDelegate delegate2 = new CodeTypeDelegate();
            delegate2.Name = "nestedDelegate2";
            delegate2.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.Object"), "sender"));
            delegate2.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.EventArgs"), "e"));

            delegate2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Delegate Region"));
            delegate2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));


            CodeSnippetTypeMember snippet1 = new CodeSnippetTypeMember();
            CodeSnippetTypeMember snippet2 = new CodeSnippetTypeMember();

            CodeRegionDirective regionStart = new CodeRegionDirective(CodeRegionMode.End, "");
            regionStart.RegionText = "Snippet Region";
            regionStart.RegionMode = CodeRegionMode.Start;
            snippet2.StartDirectives.Add(regionStart);
            snippet2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));


            cd.Members.Add(field1);
            cd.Members.Add(method1);
            cd.Members.Add(constructor1);
            cd.Members.Add(property1);
            cd.Members.Add(methodMain);

            if (Supports(provider, GeneratorSupport.DeclareEvents))
            {
                cd.Members.Add(evt1);
            }

            if (Supports(provider, GeneratorSupport.NestedTypes))
            {
                cd.Members.Add(nestedClass1);
                if (Supports(provider, GeneratorSupport.DeclareDelegates))
                {
                    cd.Members.Add(delegate1);
                }
            }

            cd.Members.Add(snippet1);

            cd.Members.Add(field2);
            cd.Members.Add(method2);
            cd.Members.Add(constructor2);
            cd.Members.Add(property2);


            if (Supports(provider, GeneratorSupport.StaticConstructors))
            {
                cd.Members.Add(typeConstructor2);
            }

            if (Supports(provider, GeneratorSupport.DeclareEvents))
            {
                cd.Members.Add(evt2);
            }
            if (Supports(provider, GeneratorSupport.NestedTypes))
            {
                cd.Members.Add(nestedClass2);
                if (Supports(provider, GeneratorSupport.DeclareDelegates))
                {
                    cd.Members.Add(delegate2);
                }
            }
            cd.Members.Add(snippet2);
        }
#endif
    }
    public override void BuildTree (CodeDomProvider provider, CodeCompileUnit cu) {
#if WHIDBEY
        if (!(provider is JScriptCodeProvider)) {
            // GENERATES (C#):
            //
            //  #region Compile Unit Region
            //  
            //  namespace Namespace1 {
            //      
            //      
            //      #region Outer Type Region
            //      // Outer Type Comment
            //      public class Class1 {
            //          
            //          // Field 1 Comment
            //          private string field1;
            //          
            //          public void Method1() {
            //              this.Event1(this, System.EventArgs.Empty);
            //          }
            //          
            //          #region Constructor Region
            //          public Class1() {
            //              #region Statements Region
            //              this.field1 = "value1";
            //              this.field2 = "value2";
            //              #endregion
            //          }
            //          #endregion
            //          
            //          public string Property1 {
            //              get {
            //                  return this.field1;
            //              }
            //          }
            //          
            //          public static void Main() {
            //          }
            //          
            //          public event System.EventHandler Event1;
            //          
            //          public class NestedClass1 {
            //          }
            //          
            //          public delegate void nestedDelegate1(object sender, System.EventArgs e);
            //          
            //  
            //          
            //          #region Field Region
            //          private string field2;
            //          #endregion
            //          
            //          #region Method Region
            //          // Method 2 Comment
            //          
            //          #line 500 "MethodLinePragma.txt"
            //          public void Method2() {
            //              this.Event2(this, System.EventArgs.Empty);
            //          }
            //          
            //          #line default
            //          #line hidden
            //          #endregion
            //          
            //          public Class1(string value1, string value2) {
            //          }
            //          
            //          #region Property Region
            //          public string Property2 {
            //              get {
            //                  return this.field2;
            //              }
            //          }
            //          #endregion
            //          
            //          #region Type Constructor Region
            //          static Class1() {
            //          }
            //          #endregion
            //          
            //          #region Event Region
            //          public event System.EventHandler Event2;
            //          #endregion
            //          
            //          #region Nested Type Region
            //          // Nested Type Comment
            //          
            //          #line 400 "NestedTypeLinePragma.txt"
            //          public class NestedClass2 {
            //          }
            //          
            //          #line default
            //          #line hidden
            //          #endregion
            //          
            //          #region Delegate Region
            //          public delegate void nestedDelegate2(object sender, System.EventArgs e);
            //          #endregion
            //          
            //          #region Snippet Region
            //  
            //          #endregion
            //      }
            //      #endregion
            //  }
            //  #endregion

            CodeNamespace ns = new CodeNamespace ("Namespace1");

            cu.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Compile Unit Region"));
            cu.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));

            cu.Namespaces.Add (ns);

            CodeTypeDeclaration cd = new CodeTypeDeclaration ("Class1");
            ns.Types.Add (cd);

            cd.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Outer Type Region"));
            cd.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));

            cd.Comments.Add (new CodeCommentStatement ("Outer Type Comment"));

            CodeMemberField field1 = new CodeMemberField (typeof (String), "field1");
            CodeMemberField field2 = new CodeMemberField (typeof (String), "field2");
            field1.Comments.Add (new CodeCommentStatement ("Field 1 Comment"));
            field2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Field Region"));
            field2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));

            CodeMemberEvent evt1 = new CodeMemberEvent ();
            evt1.Name = "Event1";
            evt1.Type = new CodeTypeReference (typeof (System.EventHandler));
            evt1.Attributes = (evt1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            CodeMemberEvent evt2 = new CodeMemberEvent ();
            evt2.Name = "Event2";
            evt2.Type = new CodeTypeReference (typeof (System.EventHandler));
            evt2.Attributes = (evt2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            evt2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Event Region"));
            evt2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));


            CodeMemberMethod method1 = new CodeMemberMethod ();
            method1.Name = "Method1";
            method1.Attributes = (method1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            if (provider.Supports (GeneratorSupport.DeclareEvents)) {
                method1.Statements.Add (
                    new CodeDelegateInvokeExpression (
                        new CodeEventReferenceExpression (new CodeThisReferenceExpression (), "Event1"),
                        new CodeExpression[] {
                        new CodeThisReferenceExpression(),
                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
                    }));
            }


            CodeMemberMethod method2 = new CodeMemberMethod ();
            method2.Name = "Method2";
            method2.Attributes = (method2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            if (provider.Supports (GeneratorSupport.DeclareEvents)) {
                method2.Statements.Add (
                    new CodeDelegateInvokeExpression (
                        new CodeEventReferenceExpression (new CodeThisReferenceExpression (), "Event2"),
                        new CodeExpression[] {
                        new CodeThisReferenceExpression(),
                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
                    }));
            }
            method2.LinePragma = new CodeLinePragma ("MethodLinePragma.txt", 500);
            method2.Comments.Add (new CodeCommentStatement ("Method 2 Comment"));

            method2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Method Region"));
            method2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));


            CodeMemberProperty property1 = new CodeMemberProperty ();
            property1.Name = "Property1";
            property1.Type = new CodeTypeReference (typeof (string));
            property1.Attributes = (property1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            property1.GetStatements.Add (
                new CodeMethodReturnStatement (
                    new CodeFieldReferenceExpression (
                        new CodeThisReferenceExpression (),
                        "field1")));

            CodeMemberProperty property2 = new CodeMemberProperty ();
            property2.Name = "Property2";
            property2.Type = new CodeTypeReference (typeof (string));
            property2.Attributes = (property2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            property2.GetStatements.Add (
                new CodeMethodReturnStatement (
                    new CodeFieldReferenceExpression (
                        new CodeThisReferenceExpression (),
                        "field2")));

            property2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Property Region"));
            property2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));


            CodeConstructor constructor1 = new CodeConstructor ();
            constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            CodeStatement conState1 = new CodeAssignStatement (
                                        new CodeFieldReferenceExpression (
                                            new CodeThisReferenceExpression (),
                                            "field1"),
                                        new CodePrimitiveExpression ("value1"));
            conState1.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Statements Region"));
            constructor1.Statements.Add (conState1);
            CodeStatement conState2 = new CodeAssignStatement (
                                        new CodeFieldReferenceExpression (
                                            new CodeThisReferenceExpression (),
                                            "field2"),
                                        new CodePrimitiveExpression ("value2"));
            conState2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));
            constructor1.Statements.Add (conState2);

            constructor1.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Constructor Region"));
            constructor1.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));

            CodeConstructor constructor2 = new CodeConstructor ();
            constructor2.Attributes = (constructor2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            constructor2.Parameters.Add (new CodeParameterDeclarationExpression (typeof (string), "value1"));
            constructor2.Parameters.Add (new CodeParameterDeclarationExpression (typeof (string), "value2"));

            CodeTypeConstructor typeConstructor2 = new CodeTypeConstructor ();

            typeConstructor2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Type Constructor Region"));
            typeConstructor2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));


            CodeEntryPointMethod methodMain = new CodeEntryPointMethod ();

            CodeTypeDeclaration nestedClass1 = new CodeTypeDeclaration ("NestedClass1");
            CodeTypeDeclaration nestedClass2 = new CodeTypeDeclaration ("NestedClass2");
            nestedClass2.LinePragma = new CodeLinePragma ("NestedTypeLinePragma.txt", 400);
            nestedClass2.Comments.Add (new CodeCommentStatement ("Nested Type Comment"));

            nestedClass2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Nested Type Region"));
            nestedClass2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));



            CodeTypeDelegate delegate1 = new CodeTypeDelegate ();
            delegate1.Name = "nestedDelegate1";
            delegate1.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference ("System.Object"), "sender"));
            delegate1.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference ("System.EventArgs"), "e"));

            CodeTypeDelegate delegate2 = new CodeTypeDelegate ();
            delegate2.Name = "nestedDelegate2";
            delegate2.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference ("System.Object"), "sender"));
            delegate2.Parameters.Add (new CodeParameterDeclarationExpression (new CodeTypeReference ("System.EventArgs"), "e"));

            delegate2.StartDirectives.Add (new CodeRegionDirective (CodeRegionMode.Start, "Delegate Region"));
            delegate2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));


            CodeSnippetTypeMember snippet1 = new CodeSnippetTypeMember ();
            CodeSnippetTypeMember snippet2 = new CodeSnippetTypeMember ();

            CodeRegionDirective regionStart = new CodeRegionDirective (CodeRegionMode.End, "");
            regionStart.RegionText = "Snippet Region";
            regionStart.RegionMode = CodeRegionMode.Start;
            snippet2.StartDirectives.Add (regionStart);
            snippet2.EndDirectives.Add (new CodeRegionDirective (CodeRegionMode.End, string.Empty));


            cd.Members.Add (field1);
            cd.Members.Add (method1);
            cd.Members.Add (constructor1);
            cd.Members.Add (property1);
            cd.Members.Add (methodMain);

            if (Supports (provider, GeneratorSupport.DeclareEvents)) {
                cd.Members.Add (evt1);
            }

            if (Supports (provider, GeneratorSupport.NestedTypes)) {
                cd.Members.Add (nestedClass1);
                if (Supports (provider, GeneratorSupport.DeclareDelegates)) {
                    cd.Members.Add (delegate1);
                }
            }

            cd.Members.Add (snippet1);

            cd.Members.Add (field2);
            cd.Members.Add (method2);
            cd.Members.Add (constructor2);
            cd.Members.Add (property2);


            if (Supports (provider, GeneratorSupport.StaticConstructors)) {
                cd.Members.Add (typeConstructor2);
            }

            if (Supports (provider, GeneratorSupport.DeclareEvents)) {
                cd.Members.Add (evt2);
            }
            if (Supports (provider, GeneratorSupport.NestedTypes)) {
                cd.Members.Add (nestedClass2);
                if (Supports (provider, GeneratorSupport.DeclareDelegates)) {
                    cd.Members.Add (delegate2);
                }
            }
            cd.Members.Add (snippet2);
        }
#endif
    }
예제 #38
0
        public void RegionsSnippetsAndLinePragmas()
        {
            var cu = new CodeCompileUnit();
            CodeNamespace ns = new CodeNamespace("Namespace1");

            cu.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Compile Unit Region"));
            cu.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            cu.Namespaces.Add(ns);

            var cd = new CodeTypeDeclaration("Class1");
            ns.Types.Add(cd);

            cd.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Outer Type Region"));
            cd.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            cd.Comments.Add(new CodeCommentStatement("Outer Type Comment"));

            CodeMemberField field1 = new CodeMemberField(typeof(String), "field1");
            CodeMemberField field2 = new CodeMemberField(typeof(String), "field2");
            field1.Comments.Add(new CodeCommentStatement("Field 1 Comment"));
            field2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Field Region"));
            field2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeMemberEvent evt1 = new CodeMemberEvent();
            evt1.Name = "Event1";
            evt1.Type = new CodeTypeReference(typeof(System.EventHandler));
            evt1.Attributes = (evt1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            CodeMemberEvent evt2 = new CodeMemberEvent();
            evt2.Name = "Event2";
            evt2.Type = new CodeTypeReference(typeof(System.EventHandler));
            evt2.Attributes = (evt2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            evt2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Event Region"));
            evt2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeMemberMethod method1 = new CodeMemberMethod();
            method1.Name = "Method1";
            method1.Attributes = (method1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            method1.Statements.Add(
                new CodeDelegateInvokeExpression(
                    new CodeEventReferenceExpression(new CodeThisReferenceExpression(), "Event1"),
                    new CodeExpression[] {
                        new CodeThisReferenceExpression(),
                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
                    }));

            CodeMemberMethod method2 = new CodeMemberMethod();
            method2.Name = "Method2";
            method2.Attributes = (method2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            method2.Statements.Add(
                new CodeDelegateInvokeExpression(
                    new CodeEventReferenceExpression(new CodeThisReferenceExpression(), "Event2"),
                    new CodeExpression[] {
                    new CodeThisReferenceExpression(),
                    new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("System.EventArgs"), "Empty")
                    }));
            method2.LinePragma = new CodeLinePragma("MethodLinePragma.txt", 500);
            method2.Comments.Add(new CodeCommentStatement("Method 2 Comment"));

            method2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Method Region"));
            method2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeMemberProperty property1 = new CodeMemberProperty();
            property1.Name = "Property1";
            property1.Type = new CodeTypeReference(typeof(string));
            property1.Attributes = (property1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            property1.GetStatements.Add(
                new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        "field1")));

            CodeMemberProperty property2 = new CodeMemberProperty();
            property2.Name = "Property2";
            property2.Type = new CodeTypeReference(typeof(string));
            property2.Attributes = (property2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            property2.GetStatements.Add(
                new CodeMethodReturnStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(),
                        "field2")));

            property2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Property Region"));
            property2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeConstructor constructor1 = new CodeConstructor();
            constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            CodeStatement conState1 = new CodeAssignStatement(
                                        new CodeFieldReferenceExpression(
                                            new CodeThisReferenceExpression(),
                                            "field1"),
                                        new CodePrimitiveExpression("value1"));
            conState1.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Statements Region"));
            constructor1.Statements.Add(conState1);
            CodeStatement conState2 = new CodeAssignStatement(
                                        new CodeFieldReferenceExpression(
                                            new CodeThisReferenceExpression(),
                                            "field2"),
                                        new CodePrimitiveExpression("value2"));
            conState2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));
            constructor1.Statements.Add(conState2);

            constructor1.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Constructor Region"));
            constructor1.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeConstructor constructor2 = new CodeConstructor();
            constructor2.Attributes = (constructor2.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            constructor2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "value1"));
            constructor2.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "value2"));

            CodeTypeConstructor typeConstructor2 = new CodeTypeConstructor();

            typeConstructor2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Type Constructor Region"));
            typeConstructor2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeEntryPointMethod methodMain = new CodeEntryPointMethod();

            CodeTypeDeclaration nestedClass1 = new CodeTypeDeclaration("NestedClass1");
            CodeTypeDeclaration nestedClass2 = new CodeTypeDeclaration("NestedClass2");
            nestedClass2.LinePragma = new CodeLinePragma("NestedTypeLinePragma.txt", 400);
            nestedClass2.Comments.Add(new CodeCommentStatement("Nested Type Comment"));

            nestedClass2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Nested Type Region"));
            nestedClass2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            CodeTypeDelegate delegate1 = new CodeTypeDelegate();
            delegate1.Name = "nestedDelegate1";
            delegate1.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.Object"), "sender"));
            delegate1.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.EventArgs"), "e"));

            CodeTypeDelegate delegate2 = new CodeTypeDelegate();
            delegate2.Name = "nestedDelegate2";
            delegate2.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.Object"), "sender"));
            delegate2.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("System.EventArgs"), "e"));

            delegate2.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, "Delegate Region"));
            delegate2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            var snippet1 = new CodeSnippetTypeMember();
            var snippet2 = new CodeSnippetTypeMember();

            CodeRegionDirective regionStart = new CodeRegionDirective(CodeRegionMode.End, "");
            regionStart.RegionText = "Snippet Region";
            regionStart.RegionMode = CodeRegionMode.Start;
            snippet2.StartDirectives.Add(regionStart);
            snippet2.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            cd.Members.Add(field1);
            cd.Members.Add(method1);
            cd.Members.Add(constructor1);
            cd.Members.Add(property1);
            cd.Members.Add(methodMain);

            cd.Members.Add(evt1);
            cd.Members.Add(nestedClass1);
            cd.Members.Add(delegate1);

            cd.Members.Add(snippet1);

            cd.Members.Add(field2);
            cd.Members.Add(method2);
            cd.Members.Add(constructor2);
            cd.Members.Add(property2);

            cd.Members.Add(typeConstructor2);
            cd.Members.Add(evt2);
            cd.Members.Add(nestedClass2);
            cd.Members.Add(delegate2);
            cd.Members.Add(snippet2);

            AssertEqual(cu,
                @"#region Compile Unit Region
                  //------------------------------------------------------------------------------
                  // <auto-generated>
                  //     This code was generated by a tool.
                  //     Runtime Version:4.0.30319.42000
                  //
                  //     Changes to this file may cause incorrect behavior and will be lost if
                  //     the code is regenerated.
                  // </auto-generated>
                  //------------------------------------------------------------------------------

                  namespace Namespace1 {


                      #region Outer Type Region
                      // Outer Type Comment
                      public class Class1 {

                          // Field 1 Comment
                          private string field1;

                          #region Field Region
                          private string field2;
                          #endregion


                          #region Snippet Region
                  #endregion


                          #region Type Constructor Region
                          static Class1() {
                          }
                          #endregion

                          #region Constructor Region
                          public Class1() {
                              #region Statements Region
                              this.field1 = ""value1"";
                              this.field2 = ""value2"";
                #endregion
                        }
                #endregion

                        public Class1(string value1, string value2)
                        {
                        }

                        public string Property1
                        {
                            get
                            {
                                return this.field1;
                            }
                        }

                        #region Property Region
                        public string Property2
                        {
                            get
                            {
                                return this.field2;
                            }
                        }
                        #endregion

                        public event System.EventHandler Event1;

                        #region Event Region
                        public event System.EventHandler Event2;
                        #endregion

                        public void Method1()
                        {
                            this.Event1(this, System.EventArgs.Empty);
                        }

                        public static void Main()
                        {
                        }

                        #region Method Region
                        // Method 2 Comment

                #line 500 ""MethodLinePragma.txt""
                        public void Method2()
                        {
                            this.Event2(this, System.EventArgs.Empty);
                        }

                #line default
                #line hidden
                        #endregion

                        public class NestedClass1
                        {
                        }

                        public delegate void nestedDelegate1(object sender, System.EventArgs e);

                        #region Nested Type Region
                        // Nested Type Comment

                #line 400 ""NestedTypeLinePragma.txt""
                        public class NestedClass2
                        {
                        }

                #line default
                #line hidden
                        #endregion

                        #region Delegate Region
                        public delegate void nestedDelegate2(object sender, System.EventArgs e);
                        #endregion
                    }
                #endregion
                }
                  #endregion");
        }