Inheritance: CodeMemberMethod
Example #1
0
 public void Init()
 {
     functionalConstructor = null;
     staticConstructor = null;
     hasElementWildCards = false;
     contentModelExpression = null;
     if (propertyNameTypeTable != null) {
         propertyNameTypeTable.Clear();
     }
 }
 public CodeCompileUnit InitialiseCompileUnit(GLSLAssembly assembly)
 {
     var contentUnit = new CodeCompileUnit ();
     SetVersionNumber (contentUnit, assembly.Version);
     string nameSpace = assembly.Namespace;
     if (string.IsNullOrWhiteSpace (nameSpace))
     {
         nameSpace = System.IO.Path.GetFileNameWithoutExtension (assembly.OutputAssembly);
     }
     var contentNs = new CodeNamespace (nameSpace);
     contentUnit.Namespaces.Add (contentNs);
     var uniforms = CreateClass (contentNs, "Uniforms");
     var defaultConstructor = new CodeTypeConstructor ();
     defaultConstructor.Attributes = MemberAttributes.Public | MemberAttributes.Final;
     uniforms.Members.Add (defaultConstructor);
     defaultConstructor.Statements.Add (new CodeVariableDeclarationStatement (typeof(int), "testInt", new CodePrimitiveExpression (0)));
     foreach (var block in mExtractor.Blocks)
     {
         AddStruct (contentNs, uniforms, block);
     }
     return contentUnit;
 }
Example #3
0
        CodeTypeConstructor RegisterColums()
        {
            var c = new CodeTypeConstructor();
            foreach (var col in this.Columns)
            {
                c.Statements.Add(GetRegisterMethod("RegisterColumn", col.Member, new CodeTypeReference(col.GetColumnType())));
            }

            foreach(var a in this.Associations)
            {
                if (a.IsForeignKey || (!a.IsForeignKey && a.Cardinality == "One"))
                {
                    c.Statements.Add(GetRegisterMethod("RegisterAssociation", a.Member, new CodeTypeReference(a.Type)));
                }
            }

            return c;
        }
Example #4
0
		protected override void GenerateTypeConstructor (CodeTypeConstructor e)
		{
		}
Example #5
0
		protected override void GenerateTypeConstructor (CodeTypeConstructor constructor)
		{
			if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface)
				return;

			OutputAttributes (constructor.CustomAttributes, null,
				LineHandling.ContinueLine);

			Output.WriteLine ("Shared Sub New()");
			Indent++;
			GenerateStatements (constructor.Statements);
			Indent--;
			Output.WriteLine ("End Sub");
		}
Example #6
0
			public void Visit (CodeTypeConstructor o)
			{
				g.GenerateTypeConstructor (o);
			}
Example #7
0
        public CodeTypeConstructor ParseTypeConstructor()
        {
            CodeTypeConstructor ctor = new CodeTypeConstructor();

            ExpectKeyword("typeconstructor");
            ExpectKeyword("begin");
            while (!IsKeyword("end") && TokenType != CDILToken.EOF)
            {
                ctor.Statements.Add(ParseStatement());
                if (TokenType == CDILToken.Semicolon)
                    Expect(CDILToken.Semicolon);
                else
                    break;
            }
            ExpectKeyword("end");
            return ctor;
        }
		public override void BuildCodeDomTree (CodeCompileUnit compileUnit)
		{
         
			CodeThisReferenceExpression @this = new CodeThisReferenceExpression ();
			CodeBaseReferenceExpression @base = new CodeBaseReferenceExpression ();
			CodeTypeReferenceExpression thisType = new CodeTypeReferenceExpression (new CodeTypeReference (GeneratedTypeName));
			CodeTypeReference uriType = new CodeTypeReference (typeof(Uri));

			CodeMemberField executableField = new CodeMemberField {
            Name = "_Executable",
            Type = new CodeTypeReference(typeof(XsltExecutable)),
            Attributes = MemberAttributes.Private | MemberAttributes.Static
         };

			// methods

			// cctor
			CodeTypeConstructor cctor = new CodeTypeConstructor {
            CustomAttributes = { 
               new CodeAttributeDeclaration(DebuggerNonUserCodeTypeReference)
            }
         };

			CodeVariableDeclarationStatement procVar = new CodeVariableDeclarationStatement {
            Name = "proc",
            Type = new CodeTypeReference(typeof(IXsltProcessor)),
            InitExpression = new CodeIndexerExpression {
               TargetObject = new CodePropertyReferenceExpression {
                  PropertyName = "Xslt",
                  TargetObject = new CodeTypeReferenceExpression(typeof(Processors))
               },
               Indices = { 
                  new CodePrimitiveExpression(parser.ProcessorName)
               }
            } 
         };

			CodeVariableDeclarationStatement sourceVar = new CodeVariableDeclarationStatement {
            Name = "source",
            Type = new CodeTypeReference(typeof(Stream)),
            InitExpression = new CodePrimitiveExpression(null)
         };

			CodeVariableDeclarationStatement sourceUriVar = new CodeVariableDeclarationStatement {
            Name = "sourceUri",
            Type = uriType,
            InitExpression = new CodeObjectCreateExpression {
               CreateType = uriType,
               Parameters = {
                  new CodePrimitiveExpression(ValidatorUri.AbsoluteUri)
               }
            }
         };

			CodeVariableDeclarationStatement resolverVar = new CodeVariableDeclarationStatement {
            Name = "resolver",
            Type = new CodeTypeReference(typeof(XmlResolver)),
            InitExpression = new CodeObjectCreateExpression(typeof(XmlEmbeddedResourceResolver))
         };

			CodeTryCatchFinallyStatement trySt = new CodeTryCatchFinallyStatement { 
            TryStatements = {
               new CodeAssignStatement {
                  Left = new CodeVariableReferenceExpression(sourceVar.Name),
                  Right = new CodeCastExpression {
                     TargetType = new CodeTypeReference(typeof(Stream)),
                     Expression = new CodeMethodInvokeExpression {
                        Method = new CodeMethodReferenceExpression {
                           MethodName = "GetEntity",
                           TargetObject = new CodeVariableReferenceExpression(resolverVar.Name)
                        },
                        Parameters = {
                           new CodeVariableReferenceExpression(sourceUriVar.Name),
                           new CodePrimitiveExpression(null),
                           new CodeTypeOfExpression(typeof(Stream))
                        }
                     }
                  }
               }
            }
         };

			CodeVariableDeclarationStatement optionsVar = new CodeVariableDeclarationStatement {
            Name = "options",
            Type = new CodeTypeReference(typeof(XsltCompileOptions)),
         };
			optionsVar.InitExpression = new CodeObjectCreateExpression (optionsVar.Type);

			trySt.TryStatements.Add (optionsVar);
			trySt.TryStatements.Add (new CodeAssignStatement {
            Left = new CodePropertyReferenceExpression {
               PropertyName = "BaseUri",
               TargetObject = new CodeVariableReferenceExpression(optionsVar.Name)
            },
            Right = new CodeVariableReferenceExpression(sourceUriVar.Name)
         });
			trySt.TryStatements.Add (new CodeAssignStatement {
            Left = new CodeFieldReferenceExpression {
               FieldName = executableField.Name,
               TargetObject = thisType
            },
            Right = new CodeMethodInvokeExpression(
               new CodeMethodReferenceExpression {
                  MethodName = "Compile",
                  TargetObject = new CodeVariableReferenceExpression(procVar.Name)
               },
               new CodeVariableReferenceExpression(sourceVar.Name),
               new CodeVariableReferenceExpression(optionsVar.Name)
            )
         });

			CodeConditionStatement disposeIf = new CodeConditionStatement {
            Condition = new CodeBinaryOperatorExpression {
               Left = new CodeVariableReferenceExpression(sourceVar.Name),
               Operator = CodeBinaryOperatorType.IdentityInequality,
               Right = new CodePrimitiveExpression(null)
            },
            TrueStatements = {
               new CodeMethodInvokeExpression {
                  Method = new CodeMethodReferenceExpression {
                     MethodName = "Dispose",
                     TargetObject = new CodeVariableReferenceExpression(sourceVar.Name)
                  }
               }
            }
         };

			trySt.FinallyStatements.Add (disposeIf);

			cctor.Statements.AddRange (new CodeStatement[] {
                procVar,
                sourceVar,
                sourceUriVar,
                resolverVar,
                trySt
            });

			// ctor
			CodeConstructor ctor = new CodeConstructor {
            Attributes = MemberAttributes.Public,
            CustomAttributes = { 
               new CodeAttributeDeclaration(DebuggerNonUserCodeTypeReference)
            },
            BaseConstructorArgs = { 
               new CodeFieldReferenceExpression {
                  FieldName = executableField.Name,
                  TargetObject = thisType
               }
            }
         };

			// class
			CodeTypeDeclaration codeType = new CodeTypeDeclaration {
            Name = GeneratedTypeName,
            IsClass = true,
            BaseTypes = { typeof(SchematronXsltValidator) },
            Members = { cctor, ctor, executableField }
         };

			CodeNamespace codeNamespace = new CodeNamespace {
            Name = GeneratedTypeNamespace,
            Types = { codeType }
         };

			compileUnit.Namespaces.Add (codeNamespace);
		}
        /// <devdoc>
        ///    <para>
        ///       Generates code for the specified CodeDom based class constructor
        ///       representation.
        ///    </para>
        /// </devdoc>
        private  void GenerateTypeConstructor(CodeTypeConstructor e) {
            if (!(IsCurrentClass || IsCurrentStruct)) return;

            if (e.CustomAttributes.Count > 0) {
                GenerateAttributes(e.CustomAttributes);
            }
            Output.Write("static ");
            Output.Write(CurrentTypeName);
            Output.Write("()");
            OutputStartingBrace();
            Indent++;
            GenerateStatements(e.Statements);
            Indent--;
            Output.WriteLine("}");
        }
Example #10
0
 protected override void GenerateTypeConstructor(System.CodeDom.CodeTypeConstructor e)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Example #11
0
 private void Write(CodeTypeConstructor e, string typeName){
   TextWriter w = this.writer;
   this.WriteIndent();
   w.Write("static ");
   this.WriteIdentifier(typeName);
   w.Write("() ");
   this.WriteStartingBrace();
   this.Write(e.Statements);
   this.WriteClosingBrace();
 }
Example #12
0
        protected override void GenerateTypeConstructor(CodeTypeConstructor e)
        {
            FlushOutput(e);

            MyGenerateStatements(e.Statements);
        }
Example #13
0
 protected override void GenerateTypeConstructor(CodeTypeConstructor e)
 {
     if (base.IsCurrentClass || base.IsCurrentStruct)
     {
         base.Output.Write("static ");
         this.OutputStartingBrace();
         this.GenerateMethodStatements(e.Statements);
         this.OutputEndingBrace();
     }
 }
        protected virtual CodeTypeConstructor Rewrite(CodeTypeConstructor source, ref bool didRewrite)
        {
            if (source == null)
            {
                return source;
            }

            bool didChildRewrite = false;
            CodeTypeConstructor result = new CodeTypeConstructor();
            result.ReturnType = this.Rewrite(source.ReturnType, ref didChildRewrite);
            this.Rewrite(result.Statements, source.Statements, ref didChildRewrite);
            this.Rewrite(result.Parameters, source.Parameters, ref didChildRewrite);
            result.PrivateImplementationType = this.Rewrite(source.PrivateImplementationType, ref didChildRewrite);
            this.Rewrite(result.ImplementationTypes, source.ImplementationTypes, ref didChildRewrite);
            this.Rewrite(result.ReturnTypeCustomAttributes, source.ReturnTypeCustomAttributes, ref didChildRewrite);
            this.Rewrite(result.TypeParameters, source.TypeParameters, ref didChildRewrite);
            result.Name = source.Name;
            result.Attributes = this.Rewrite(source.Attributes, ref didChildRewrite);
            this.Rewrite(result.CustomAttributes, source.CustomAttributes, ref didChildRewrite);
            result.LinePragma = this.Rewrite(source.LinePragma, ref didChildRewrite);
            this.Rewrite(result.Comments, source.Comments, ref didChildRewrite);
            this.Rewrite(result.StartDirectives, source.StartDirectives, ref didChildRewrite);
            this.Rewrite(result.EndDirectives, source.EndDirectives, ref didChildRewrite);
            this.Rewrite(result.UserData, source.UserData, ref didChildRewrite);
            if (didChildRewrite)
            {
                didRewrite = true;
                return result;
            }
            else
            {
                return source;
            }
        }
        protected override void GenerateTypeConstructor(CodeTypeConstructor constructor)
        {
            if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface)
                return;

            Output.Write ("static " + GetSafeName (CurrentTypeName));
            OutputStartBrace ();
            Indent++;
            GenerateStatements (constructor.Statements);
            Indent--;
            Output.WriteLine ('}');
        }
Example #16
0
 private void ValidateTypeConstructor(CodeTypeConstructor e) {
     ValidateStatements(e.Statements);
 }
        /// <devdoc>
        ///    <para>
        ///       Generates code for the specified CodeDom based class constructor
        ///       representation.
        ///    </para>
        /// </devdoc>
        protected override void GenerateTypeConstructor(CodeTypeConstructor e) {
            if (!(IsCurrentClass || IsCurrentStruct)) return;

            if (e.CustomAttributes.Count > 0) {
                OutputAttributes(e.CustomAttributes, false);
            }

            Output.WriteLine("Shared Sub New()");
            Indent++;
            GenerateVBStatements(e.Statements);
            Indent--;
            Output.WriteLine("End Sub");
        }
Example #18
0
        /// <include file='doc\CSharpCodeProvider.uex' path='docs/doc[@for="CSharpCodeGenerator.GenerateTypeConstructor"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Generates code for the specified CodeDom based class constructor
        ///       representation.
        ///    </para>
        /// </devdoc>
        protected override void GenerateTypeConstructor(CodeTypeConstructor e) {
            if (!(IsCurrentClass || IsCurrentStruct)) return;

            Output.Write("static ");
            Output.Write(CurrentTypeName);
            Output.Write("()");
            OutputStartingBrace();
            Indent++;
            GenerateStatements(e.Statements);
            Indent--;
            Output.WriteLine("}");
        }
 public void Generate(CodeTypeConstructor member)
 {
     Generate(member.Comments);
     foreach (CodeStatement statement in member.Statements)
         Generate(statement);
 }
Example #20
0
        internal DryadLinqCodeGen(DryadLinqContext context, VertexCodeGen vertexCodeGen)
        {
            this.m_context = context;
            this.m_vertexCodeGen = vertexCodeGen;
            this.m_loadedVertexAssembly = null;
            this.m_dryadLinqUnit = new CodeCompileUnit();

            // Create a namespace
            this.m_dryadCodeSpace = new CodeNamespace(TargetNamespace);
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Collections"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Collections.Generic"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Text"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Linq"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Linq.Expressions"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Diagnostics"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Runtime.Serialization"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Data.SqlTypes"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Data.Linq"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("System.Data.Linq.Mapping"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("Microsoft.Research.DryadLinq"));
            this.m_dryadCodeSpace.Imports.Add(new CodeNamespaceImport("Microsoft.Research.DryadLinq.Internal"));

            this.m_dryadLinqUnit.Namespaces.Add(this.m_dryadCodeSpace);

            // Create the class for all the DryadLinq extension methods
            this.m_dryadExtensionClass = new CodeTypeDeclaration(ExtensionClassName);
            this.m_dryadExtensionClass.IsClass = true;
            this.m_dryadExtensionClass.IsPartial = true;
            this.m_dryadExtensionClass.TypeAttributes = TypeAttributes.Public;
            this.m_dryadCodeSpace.Types.Add(this.m_dryadExtensionClass);

            // Create the static constructor for the vertex extension class
            this.m_extensionStaticCtor = new CodeTypeConstructor();
            this.m_dryadExtensionClass.Members.Add(this.m_extensionStaticCtor);

            // Create the class for all the DryadLinq vertex methods
            this.m_dryadVertexClass = new CodeTypeDeclaration(VertexClassName);
            this.m_dryadVertexClass.IsClass = true;
            this.m_dryadVertexClass.TypeAttributes = TypeAttributes.Public | TypeAttributes.Sealed;
            this.m_dryadCodeSpace.Types.Add(this.m_dryadVertexClass);
            this.AddCopyResourcesMethod();

            // The set of input/output channel datatypes
            this.m_dryadDataTypes = new HashSet<Type>();
            this.m_dryadDataTypes.Add(typeof(byte));
            this.m_dryadDataTypes.Add(typeof(sbyte));
            this.m_dryadDataTypes.Add(typeof(bool));
            this.m_dryadDataTypes.Add(typeof(char));
            this.m_dryadDataTypes.Add(typeof(short));
            this.m_dryadDataTypes.Add(typeof(ushort));
            this.m_dryadDataTypes.Add(typeof(int));
            this.m_dryadDataTypes.Add(typeof(uint));
            this.m_dryadDataTypes.Add(typeof(long));
            this.m_dryadDataTypes.Add(typeof(ulong));
            this.m_dryadDataTypes.Add(typeof(float));
            this.m_dryadDataTypes.Add(typeof(decimal));
            this.m_dryadDataTypes.Add(typeof(double));
            this.m_dryadDataTypes.Add(typeof(DateTime));      
            this.m_dryadDataTypes.Add(typeof(string));
            this.m_dryadDataTypes.Add(typeof(LineRecord));
            this.m_dryadDataTypes.Add(typeof(SqlDateTime));
            this.m_dryadDataTypes.Add(typeof(Guid)); 
            
            // The set of datatypes we have added serialization methods
            this.m_serializationDatatypes = new HashSet<Type>();

            this.m_fieldToStaticName = new Dictionary<FieldInfo, string>();
            this.m_staticFieldDefined = new HashSet<string>();
            this.m_typeToSerializerName = new Dictionary<Type, string>();
            this.m_anonymousTypeToName = new Dictionary<Type, string>();
            this.m_nameToAlias = new Dictionary<string, string>();
        }
		public void Constructor0 ()
		{
			CodeTypeConstructor ctc = new CodeTypeConstructor ();

			Assert.AreEqual (MemberAttributes.Private | MemberAttributes.Final,
				ctc.Attributes, "#1");

			Assert.IsNotNull (ctc.Comments, "#2");
			Assert.AreEqual (0, ctc.Comments.Count, "#3");

			Assert.IsNotNull (ctc.CustomAttributes, "#4");
			Assert.AreEqual (0, ctc.CustomAttributes.Count, "#5");

			Assert.IsNotNull (ctc.StartDirectives, "#6");
			Assert.AreEqual (0, ctc.StartDirectives.Count, "#7");

			Assert.IsNotNull (ctc.EndDirectives, "#8");
			Assert.AreEqual (0, ctc.EndDirectives.Count, "#9");

			Assert.IsNotNull (ctc.TypeParameters, "#10");
			Assert.AreEqual (0, ctc.TypeParameters.Count, "#11");

			Assert.IsNull (ctc.LinePragma, "#12");

			Assert.IsNotNull (ctc.Name, "#13");
			Assert.AreEqual (".cctor", ctc.Name, "#14");

			Assert.IsNotNull (ctc.UserData, "#15");
			Assert.AreEqual (typeof(ListDictionary), ctc.UserData.GetType (), "#16");
			Assert.AreEqual (0, ctc.UserData.Count, "#17");

			Assert.IsNotNull (ctc.ImplementationTypes, "#18");
			Assert.AreEqual (0, ctc.ImplementationTypes.Count, "#19");

			Assert.IsNotNull (ctc.Parameters, "#20");
			Assert.AreEqual (0, ctc.Parameters.Count, "#21");

			Assert.IsNull (ctc.PrivateImplementationType, "#22");

			Assert.IsNotNull (ctc.ReturnType, "#23");
			Assert.AreEqual (typeof(void).FullName, ctc.ReturnType.BaseType, "#24");

			Assert.IsNotNull (ctc.ReturnTypeCustomAttributes, "#25");
			Assert.AreEqual (0, ctc.ReturnTypeCustomAttributes.Count, "#26");

			Assert.IsNotNull (ctc.Statements, "#27");
			Assert.AreEqual (0, ctc.Statements.Count, "#28");

			string name = "mono";
			ctc.Name = name;
			Assert.IsNotNull (ctc.Name, "#29");
			Assert.AreSame (name, ctc.Name, "#30");

			ctc.Name = null;
			Assert.IsNotNull (ctc.Name, "#31");
			Assert.AreEqual (string.Empty, ctc.Name, "#32");

			CodeLinePragma clp = new CodeLinePragma ("mono", 10);
			ctc.LinePragma = clp;
			Assert.IsNotNull (ctc.LinePragma, "#33");
			Assert.AreSame (clp, ctc.LinePragma, "#34");

			ctc.LinePragma = null;
			Assert.IsNull (ctc.LinePragma, "#35");
		}
 private static void PrintTypeConstructor(TextWriter output, CodeTypeConstructor typeConstructor)
 {
     output.WriteLine("typeconstructor");
     foreach (CodeAttributeDeclaration cad in typeConstructor.CustomAttributes)
     {
         output.Write("    customattribute ");
         PrintCustomAttributeDeclaration(output, cad);
         output.WriteLine();
     }
     output.WriteLine("begin");
     for (int i = 0; i < typeConstructor.Statements.Count; ++i)
     {
         output.Write("    ");
         PrintStatement(output, typeConstructor.Statements[i]);
         if (i + 1 < typeConstructor.Statements.Count)
             output.WriteLine(';');
         else
             output.WriteLine();
     }
     output.WriteLine("end");
 }
 private void GenerateTypeConstructor(CodeTypeConstructor e)
 {
     if (this.IsCurrentClass || this.IsCurrentStruct)
     {
         if (e.CustomAttributes.Count > 0)
         {
             this.GenerateAttributes(e.CustomAttributes);
         }
         this.Output.Write("static ");
         this.Output.Write(this.CurrentTypeName);
         this.Output.Write("()");
         this.OutputStartingBrace();
         this.Indent++;
         this.GenerateStatements(e.Statements);
         this.Indent--;
         this.Output.WriteLine("}");
     }
 }
Example #24
0
		protected abstract void GenerateTypeConstructor (CodeTypeConstructor constructor);
Example #25
0
        internal static CodeTypeDeclaration CreateTypeManager(XmlQualifiedName rootElementName,
                                                              bool enableServiceReference,  
                                                              CodeStatementCollection typeDictionaryStatements, 
                                                              CodeStatementCollection elementDictionaryStatements,
                                                              CodeStatementCollection wrapperDictionaryStatements) {
            //Create the services type class and add members
            string servicesClassName = NameGenerator.GetServicesClassName();
            CodeTypeDeclaration servicesTypeDecl = new CodeTypeDeclaration(servicesClassName);
            servicesTypeDecl.Attributes = MemberAttributes.Public;

            //Create singleton
            CodeMemberField singletonField = CodeDomHelper.CreateMemberField(Constants.TypeManagerSingletonField, servicesClassName, MemberAttributes.Static, true);
            CodeMemberProperty singletonProperty = CodeDomHelper.CreateProperty(Constants.TypeManagerInstance, null, singletonField, MemberAttributes.Public | MemberAttributes.Static, false);

            MemberAttributes privateStatic = MemberAttributes.Private | MemberAttributes.Static;
            //Create static constructor
            CodeTypeConstructor staticServicesConstructor = new CodeTypeConstructor();

            CodeTypeReference returnType = CodeDomHelper.CreateDictionaryType("XName", "System.Type");
            CodeTypeReference wrapperReturnType = CodeDomHelper.CreateDictionaryType("System.Type", "System.Type");
            
            //Create a dictionary of TypeName vs System.Type and the method to create it
            CodeMemberProperty typeDictProperty = null;
            if (typeDictionaryStatements.Count > 0) {
                
                typeDictProperty = CodeDomHelper.CreateInterfaceImplProperty(Constants.GlobalTypeDictionary, Constants.ILinqToXsdTypeManager, returnType, Constants.TypeDictionaryField);
                
                CodeMemberField staticTypeDictionary = CodeDomHelper.CreateDictionaryField(Constants.TypeDictionaryField, "XName", "System.Type");
                CodeMemberMethod buildTypeDictionary = CodeDomHelper.CreateMethod(Constants.BuildTypeDictionary, privateStatic, null);
                buildTypeDictionary.Statements.AddRange(typeDictionaryStatements);

                staticServicesConstructor.Statements.Add(CodeDomHelper.CreateMethodCall(null, Constants.BuildTypeDictionary));
                servicesTypeDecl.Members.Add(staticTypeDictionary);
                servicesTypeDecl.Members.Add(buildTypeDictionary);
            }                
            else {
                typeDictProperty = CodeDomHelper.CreateInterfaceImplProperty(Constants.GlobalTypeDictionary, Constants.ILinqToXsdTypeManager, returnType);
                typeDictProperty.GetStatements.Add(
                    new CodeMethodReturnStatement(
                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(Constants.XTypedServices), Constants.EmptyDictionaryField)));
            }

            //Create a dictionary of ElementName Vs System.Type - For Auto typing and substitutionGroups
            CodeMemberProperty elementDictProperty = null;
            if (elementDictionaryStatements.Count > 0) {
                elementDictProperty = CodeDomHelper.CreateInterfaceImplProperty(Constants.GlobalElementDictionary, Constants.ILinqToXsdTypeManager, returnType, Constants.ElementDictionaryField);
                
                CodeMemberField staticElementDictionary = CodeDomHelper.CreateDictionaryField(Constants.ElementDictionaryField, "XName", "System.Type");
                CodeMemberMethod buildElementDictionary = CodeDomHelper.CreateMethod(Constants.BuildElementDictionary, privateStatic, null);
                buildElementDictionary.Statements.AddRange(elementDictionaryStatements);

                staticServicesConstructor.Statements.Add(CodeDomHelper.CreateMethodCall(null, Constants.BuildElementDictionary));
                servicesTypeDecl.Members.Add(staticElementDictionary);
                servicesTypeDecl.Members.Add(buildElementDictionary);
            }  
            else {
                elementDictProperty = CodeDomHelper.CreateInterfaceImplProperty(Constants.GlobalElementDictionary, Constants.ILinqToXsdTypeManager, returnType);
                elementDictProperty.GetStatements.Add(
                    new CodeMethodReturnStatement(
                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(Constants.XTypedServices), Constants.EmptyDictionaryField)));
            }              

            //Create a dictionary of Wrapper Element Type Vs Wrapper Type - For Auto typing when casting from XElement to Type
            CodeMemberProperty wrapperDictProperty = null;
            if (wrapperDictionaryStatements.Count > 0) {
                wrapperDictProperty = CodeDomHelper.CreateInterfaceImplProperty(Constants.RootContentTypeMapping, Constants.ILinqToXsdTypeManager, wrapperReturnType, Constants.WrapperDictionaryField);
                
                CodeMemberField staticWrapperDictionary = CodeDomHelper.CreateDictionaryField(Constants.WrapperDictionaryField, "System.Type", "System.Type");
                CodeMemberMethod buildWrapperDictionary = CodeDomHelper.CreateMethod(Constants.BuildWrapperDictionary, privateStatic, null);
                buildWrapperDictionary.Statements.AddRange(wrapperDictionaryStatements);
                
                staticServicesConstructor.Statements.Add(CodeDomHelper.CreateMethodCall(null, Constants.BuildWrapperDictionary));
                servicesTypeDecl.Members.Add(staticWrapperDictionary);
                servicesTypeDecl.Members.Add(buildWrapperDictionary);
            }        
            else {
                wrapperDictProperty = CodeDomHelper.CreateInterfaceImplProperty(Constants.RootContentTypeMapping, Constants.ILinqToXsdTypeManager, wrapperReturnType);
                wrapperDictProperty.GetStatements.Add(
                    new CodeMethodReturnStatement(
                        new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(Constants.XTypedServices), Constants.EmptyTypeMappingDictionary)));
            }

            //Implement IXmlSerializable AddSchemas method for the XmlSchemaProvider method and Schemas get set property for runtime access to schemas
            //if (enableServiceReference) { //Since property is on the interface, it has to be implemented;
                string schemaSetFieldName = "schemaSet";
                CodeTypeReference schemaSetType = new CodeTypeReference("XmlSchemaSet");

                CodeMemberField schemaSetField = new CodeMemberField(schemaSetType, schemaSetFieldName);
                schemaSetField.Attributes = MemberAttributes.Private | MemberAttributes.Static;

                    //AddSchemas method
                CodeMemberMethod addSchemasMethod = CodeDomHelper.CreateMethod("AddSchemas", MemberAttributes.FamilyOrAssembly | MemberAttributes.Static, null);
                addSchemasMethod.Parameters.Add(new CodeParameterDeclarationExpression("XmlSchemaSet", "schemas"));
                //schemas.Add(schemaSet);
                addSchemasMethod.Statements.Add(CodeDomHelper.CreateMethodCall(new CodeVariableReferenceExpression("schemas"), "Add", new CodeFieldReferenceExpression(null, schemaSetFieldName)));

                
                CodeTypeReferenceExpression interLockedType = new CodeTypeReferenceExpression("System.Threading.Interlocked");

                CodeMemberProperty schemaSetProperty = CodeDomHelper.CreateInterfaceImplProperty("Schemas", Constants.ILinqToXsdTypeManager, schemaSetType);
                CodeFieldReferenceExpression schemaSetFieldRef = new CodeFieldReferenceExpression(null, schemaSetFieldName);
                
                CodeDirectionExpression schemaSetParam = new CodeDirectionExpression(FieldDirection.Ref, schemaSetFieldRef);

                schemaSetProperty.GetStatements.Add(
                    new CodeConditionStatement(
                        new CodeBinaryOperatorExpression(schemaSetFieldRef, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null)),
                        new CodeVariableDeclarationStatement(schemaSetType, "tempSet", new CodeObjectCreateExpression(schemaSetType)),
                        new CodeExpressionStatement(
                            CodeDomHelper.CreateMethodCall(interLockedType, "CompareExchange",
                                                        schemaSetParam, 
                                                        new CodeVariableReferenceExpression("tempSet"), 
                                                        new CodePrimitiveExpression(null)))));
                
                schemaSetProperty.GetStatements.Add(
                    new CodeMethodReturnStatement(
                        new CodeVariableReferenceExpression(schemaSetFieldName)));

                //Setter
                schemaSetProperty.SetStatements.Add(new CodeAssignStatement(schemaSetFieldRef, new CodePropertySetValueReferenceExpression()));

                servicesTypeDecl.Members.Add(schemaSetField);
                servicesTypeDecl.Members.Add(schemaSetProperty);
                servicesTypeDecl.Members.Add(addSchemasMethod);
            //}
            //Implement ILinqToXsdTypeManager
            servicesTypeDecl.Members.Add(typeDictProperty);
            servicesTypeDecl.Members.Add(elementDictProperty);
            servicesTypeDecl.Members.Add(wrapperDictProperty);
            servicesTypeDecl.BaseTypes.Add(Constants.ILinqToXsdTypeManager);
            
            


            //Add a getter that will get the root type name
            CodeMemberMethod getRootType = new CodeMemberMethod(); 
            getRootType.Attributes = MemberAttributes.Static | MemberAttributes.Public;
            getRootType.Name = Constants.GetRootType;
            getRootType.ReturnType = new CodeTypeReference("System.Type");
            if (rootElementName.IsEmpty) {
                getRootType.Statements.Add(
                    new CodeMethodReturnStatement(
                        CodeDomHelper.Typeof("Xml.Schema.Linq.XTypedElement")));
            }
            else {
                getRootType.Statements.Add(
                    new CodeMethodReturnStatement(
                        new CodeIndexerExpression(
                            CodeDomHelper.CreateFieldReference(null, Constants.ElementDictionaryField),
                            CodeDomHelper.XNameGetExpression(rootElementName.Name, rootElementName.Namespace))));
            }

            servicesTypeDecl.Members.Add(staticServicesConstructor);
            servicesTypeDecl.Members.Add(getRootType);
            servicesTypeDecl.Members.Add(singletonField);
            servicesTypeDecl.Members.Add(singletonProperty);
            return servicesTypeDecl;
        }
		private void CreateConstructor()
		{

			//create the constructor

			CodeConstructor constructor = new CodeConstructor();
			constructor.Attributes = MemberAttributes.Public | MemberAttributes.Final;

			classDom.Members.Add(constructor);

			Comment(constructor, string.Format("Construct an instance of the '{0}' shader", this.techniqueName));

			foreach (DomBase dom in this.domList)
				dom.AddConstructor(this, delegate(CodeStatement s) { constructor.Statements.Add(s); });

			//create the static constructor

			CodeTypeConstructor staticConstructor = new CodeTypeConstructor();
			Comment(staticConstructor, string.Format("Static Constructor for '{0}'", this.techniqueName));
			staticConstructor.Attributes = MemberAttributes.Private | MemberAttributes.Final;

			foreach (DomBase dom in this.domList)
				dom.AddStaticConstructor(this, delegate(CodeStatement s) { staticConstructor.Statements.Add(s); });

			if (staticConstructor.Statements.Count > 0)
				classDom.Members.Add(staticConstructor);

		}
Example #27
0
 /// <summary>
 /// Generates code for the specified class constructor.
 /// </summary>
 /// <remarks>Not supported.</remarks>
 protected override void GenerateTypeConstructor(CodeTypeConstructor e)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Example #28
0
 protected override void GenerateTypeConstructor(CodeTypeConstructor e)
 {
     if (base.IsCurrentClass || base.IsCurrentStruct)
     {
         if (e.CustomAttributes.Count > 0)
         {
             this.OutputAttributes(e.CustomAttributes, false);
         }
         base.Output.WriteLine("Shared Sub New()");
         base.Indent++;
         this.GenerateVBStatements(e.Statements);
         base.Indent--;
         base.Output.WriteLine("End Sub");
     }
 }
		protected string GenerateTypeConstructor (CodeGeneratorOptions options)
		{
			TypeDeclaration.Name = "Test1";

			CodeTypeConstructor typeCtor = new CodeTypeConstructor ();
			// access, scope and vtable modifiers should be ignored
			typeCtor.Attributes |= MemberAttributes.Public | MemberAttributes.Abstract
				| MemberAttributes.Const | MemberAttributes.Final
				| MemberAttributes.New | MemberAttributes.Overloaded
				| MemberAttributes.Override | MemberAttributes.Static;
			TypeDeclaration.Members.Add (typeCtor);

			// custom attributes
			CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
			attrDec.Name = "A";
			typeCtor.CustomAttributes.Add (attrDec);

			attrDec = new CodeAttributeDeclaration ();
			attrDec.Name = "B";
			typeCtor.CustomAttributes.Add (attrDec);

			// parameter should be ignored
			CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (
				typeof (object), "value1");
			typeCtor.Parameters.Add (param);

			// implementation types should be ignored on type ctors
			typeCtor.ImplementationTypes.Add (new CodeTypeReference ("IPolicy"));

			// private immplementation type should be ignored on type ctors
			typeCtor.PrivateImplementationType = new CodeTypeReference (typeof (int));

			// return type should be ignored on type ctors
			typeCtor.ReturnType = new CodeTypeReference (typeof (int));

			// return TypeDeclaration custom attributes
			attrDec = new CodeAttributeDeclaration ();
			attrDec.Name = "A";
			attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
				new CodePrimitiveExpression (false)));
			attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
				new CodePrimitiveExpression (true)));
			typeCtor.ReturnTypeCustomAttributes.Add (attrDec);

			return GenerateCodeFromType (TypeDeclaration, options);
		}
		protected override void GenerateTypeConstructor(CodeTypeConstructor e)
		{
			Output.WriteLine("[CodeTypeConstructor : {0}]", e.ToString());
		}
Example #31
0
		protected override void GenerateTypeConstructor (CodeTypeConstructor constructor)
		{
			if (IsCurrentDelegate || IsCurrentEnum || IsCurrentInterface) {
				return;
			}

#if NET_2_0
			OutputAttributes (constructor.CustomAttributes, null, false);
#endif

			Output.Write ("static " + GetSafeName (CurrentTypeName) + "()");
			OutputStartBrace ();
			Indent++;
			GenerateStatements (constructor.Statements);
			Indent--;
			Output.WriteLine ('}');
		}