• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CodeDom.CodeConstructor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.CodeDom.CodeConstructor的典型用法代码示例。如果您正苦于以下问题:C# CodeConstructor类的具体用法?C# CodeConstructor怎么用?C# CodeConstructor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CodeConstructor类属于System.CodeDom命名空间,在下文中一共展示了CodeConstructor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Process

        public void Process(CodeTypeDeclaration typeDecl)
        {
            for (int i = 0; i < typeDecl.Members.Count; i++)
            {
                CodeTypeMember typeMember = typeDecl.Members[i];

                if (typeMember is CodeMemberMethod)
                {
                    CodeMemberMethod memberMethod = (CodeMemberMethod) typeMember;
                    CodeObjectSource source = Utils.GetTypeReferenceSource(memberMethod.ReturnType);

                    if (source.Target == typeof (void) && source.ArrayRanks.Length == 0 && memberMethod.Parameters.Count == 0)
                    {
                        if (StringUtils.CaseInsensitiveEquals(memberMethod.Name, "Class_Initialize"))
                        {
                            CodeConstructor constructor = new CodeConstructor();
                            constructor.Statements.AddRange(memberMethod.Statements);
                            typeDecl.Members[i] = constructor;
                        }
                        else if (StringUtils.CaseInsensitiveEquals(memberMethod.Name, "Class_Terminate"))
                        {
                            CodeDestructor destructor = new CodeDestructor();
                            destructor.Statements.AddRange(memberMethod.Statements);
                            typeDecl.Members[i] = destructor;
                        }
                    }
                }
                else if (typeMember is CodeTypeDeclaration)
                {
                    Process((CodeTypeDeclaration) typeMember);
                }
            }
        }
开发者ID:Saleslogix,项目名称:SLXMigration,代码行数:33,代码来源:NestedClassConstructorCorrector.cs


示例2: AddBodyParameterTest

        public void AddBodyParameterTest()
        {
            var method = new MockMethod() { Name = "Method", Parameters = new Dictionary<string, IParameter>() };
            var typeProvider = new DefaultObjectTypeProvider("Schema");

            // Confirm that no body parameter is added.
            var decorator = new RequestConstructorDecorator(typeProvider);
            CodeConstructor constructor = new CodeConstructor();
            method.HasBody = false;
            decorator.AddBodyParameter(constructor, method);

            Assert.AreEqual(0, constructor.Parameters.Count);
            Assert.AreEqual(0, constructor.Statements.Count);

            // Confirm that a required body parameter is added.
            method.RequestType = "MySchema";
            method.HasBody = true;
            constructor = new CodeConstructor();
            decorator.AddBodyParameter(constructor, method);

            Assert.AreEqual(1, constructor.Parameters.Count);
            Assert.AreEqual("body", constructor.Parameters[0].Name);
            Assert.AreEqual("Schema.MySchema", constructor.Parameters[0].Type.BaseType);
            Assert.AreEqual(1, constructor.Statements.Count);
        }
开发者ID:JANCARLO123,项目名称:google-apis,代码行数:25,代码来源:RequestConstructorDecoratorTest.cs


示例3: CreateConstructor

        internal CodeConstructor CreateConstructor(String serviceClassName, IResource resource)
        {
            var constructor = new CodeConstructor();

            // public [ResourceClass]([ServiceClass] service, Google.Apis.Authentication.IAuthenticator authenticator)
            constructor.Attributes = MemberAttributes.Public;
            constructor.Parameters.Add(
                new CodeParameterDeclarationExpression(serviceClassName, ResourceBaseGenerator.ServiceFieldName));
            constructor.Parameters.Add(
                new CodeParameterDeclarationExpression(typeof(Google.Apis.Authentication.IAuthenticator),
                    ResourceClassGenerator.AuthenticatorName));

            // this.service = service
            constructor.Statements.Add(
                new CodeAssignStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(), ResourceBaseGenerator.ServiceFieldName),
                    new CodeArgumentReferenceExpression(ResourceBaseGenerator.ServiceFieldName)));

            // this.authenticator = authenticator
            constructor.Statements.Add(
                new CodeAssignStatement(
                    new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(), ResourceClassGenerator.AuthenticatorName),
                    new CodeArgumentReferenceExpression(ResourceClassGenerator.AuthenticatorName)));

            // Initialize subresources
            constructor.Statements.AddRange(CreateSubresourceCreateStatements(resource));
            
            return constructor;
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:31,代码来源:StandardConstructorResourceDecorator.cs


示例4: CreateServicesConstructor

		protected virtual CodeConstructor CreateServicesConstructor()
		{
			CodeConstructor constructor = new CodeConstructor();
			constructor.Attributes = MemberAttributes.Public;
			constructor.Parameters.Add(new CodeParameterDeclarationExpression(_serviceType, _naming.ToVariableName(_serviceIdentifier)));
			return constructor;
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:7,代码来源:AbstractGenerator.cs


示例5: BuildCountCode

        /// <summary>
        /// This is a simple helper method to create a test valid
        /// CodeObject to be feed into the 
        ///     CreateScriptSource(CodeObject content, string id)
        ///     
        /// However, CodeObject is simply a base class so we probably
        /// need a specific type of CodeObject but what?
        /// 
        /// [Bill - has indicate that CodeObject parameter for CreateScriptSource
        ///  does in fact need to be a CodeMemberMethod - Maybe a spec BUG]
        /// 
        /// Probably need to put this somewhere else maybe put this in:
        ///     ScriptEngineTestHelper.cs
        /// </summary>
        /// <returns>A valid CodeObject boxes some kind of CompileUnit</returns>
        private static CodeObject BuildCountCode()
        {
            // Create a new CodeCompileUnit to contain
            // the program graph.
            CodeCompileUnit compileUnit = new CodeCompileUnit();

            // Declare a new namespace called Samples.
            CodeNamespace samples = new CodeNamespace("Samples");
            // Add the new namespace to the compile unit.
            compileUnit.Namespaces.Add(samples);

            // Declare a new code entry point method.
            CodeEntryPointMethod start = new CodeEntryPointMethod();

            CodeConstructor codecon = new CodeConstructor();

            //
            CodeNamespace cns = new CodeNamespace("Test");
            CodeTypeDeclaration ctd = new CodeTypeDeclaration("testclass");
            ctd.IsClass = true;

            CodeMemberMethod method = new CodeMemberMethod();
            method.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            method.Name = "AddTenToNumber";
            method.ReturnType = new CodeTypeReference("Int32");
            method.Parameters.Add(new CodeParameterDeclarationExpression("int", "number"));
            method.Statements.Add(new CodeSnippetExpression("return number+10"));
            ctd.Members.Add(method);

            samples.Types.Add(ctd);
            // If we return just the method this will not throw exception
            // on CreateScriptSource
            // return method;
            return compileUnit;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:50,代码来源:ScriptEngineTestHelper.cs


示例6: CreateConstructor

		private static CodeConstructor CreateConstructor(string className)
		{
			CodeConstructor result = new CodeConstructor();
			result.Attributes = MemberAttributes.Public;
			result.Name = className;
			return result;
		}
开发者ID:erdonet,项目名称:EntityJustworks,代码行数:7,代码来源:Code.cs


示例7: DeclareCodeType

        public override void DeclareCodeType(IDLInterface idlIntf)
        {
            // Proxy class.
            typeProxy = new CodeTypeDeclaration(name + "Proxy");
            typeProxy.IsClass = true;
            typeProxy.TypeAttributes = TypeAttributes.Public;
            eventsDeclarationHolder = new CodeTypeDeferredNamespaceDeclarationHolderEvents(idlIntf);
            typeProxy.BaseTypes.Add(genInterfaceName);

            // Interface field.
            CodeMemberField memberProxy = new CodeMemberField(genInterfaceName, proxyName);
            memberProxy.Attributes = MemberAttributes.Private;
            typeProxy.Members.Add(memberProxy); // TODO: Going to need a using or a fully qualified name.

            // Constructor.
            CodeConstructor constructor = new CodeConstructor();
            constructor.Attributes = MemberAttributes.Public;
            // TODO - use the actual interface type rather than a string.
            paramProxy = new CodeParameterDeclarationExpression(genInterfaceName, proxyName);
            constructor.Parameters.Add(paramProxy);
            thisProxyFieldRef = new CodeFieldReferenceExpression(
                new CodeThisReferenceExpression(), proxyName
            );
            assignProxy = new CodeAssignStatement(thisProxyFieldRef,
                new CodeArgumentReferenceExpression(proxyName));
            constructor.Statements.Add(assignProxy);
            typeProxy.Members.Add(constructor);

            declarationHolder = new CodeTypeIgnoredNamespaceDeclarationHolderParams(idlIntf);
            contextDeclarationHolder = declarationHolder;

            bAddNamespace = false;
        }
开发者ID:jean-edouard,项目名称:win-tools,代码行数:33,代码来源:ProxyBuilder.cs


示例8: SetTestFixtureSetup

        public void SetTestFixtureSetup(CodeMemberMethod fixtureSetupMethod)
        {
            // xUnit uses IUseFixture<T> on the class

            fixtureSetupMethod.Attributes |= MemberAttributes.Static;

            _currentFixtureTypeDeclaration = new CodeTypeDeclaration("FixtureData");
            _currentTestTypeDeclaration.Members.Add(_currentFixtureTypeDeclaration);

            var fixtureDataType = 
                CodeDomHelper.CreateNestedTypeReference(_currentTestTypeDeclaration, _currentFixtureTypeDeclaration.Name);
            
            var useFixtureType = new CodeTypeReference(IUSEFIXTURE_INTERFACE, fixtureDataType);
            CodeDomHelper.SetTypeReferenceAsInterface(useFixtureType);

            _currentTestTypeDeclaration.BaseTypes.Add(useFixtureType);

            // public void SetFixture(T) { } // explicit interface implementation for generic interfaces does not work with codedom

            CodeMemberMethod setFixtureMethod = new CodeMemberMethod();
            setFixtureMethod.Attributes = MemberAttributes.Public;
            setFixtureMethod.Name = "SetFixture";
            setFixtureMethod.Parameters.Add(new CodeParameterDeclarationExpression(fixtureDataType, "fixtureData"));
            setFixtureMethod.ImplementationTypes.Add(useFixtureType);
            _currentTestTypeDeclaration.Members.Add(setFixtureMethod);

            // public <_currentFixtureTypeDeclaration>() { <fixtureSetupMethod>(); }
            CodeConstructor ctorMethod = new CodeConstructor();
            ctorMethod.Attributes = MemberAttributes.Public;
            _currentFixtureTypeDeclaration.Members.Add(ctorMethod);
            ctorMethod.Statements.Add(
                new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(new CodeTypeReference(_currentTestTypeDeclaration.Name)),
                    fixtureSetupMethod.Name));
        }
开发者ID:zbs11491,项目名称:SpecFlow,代码行数:35,代码来源:XUnitTestGeneratorProvider.cs


示例9: GenerateCodeFromConstructor

        /// <summary>
        /// Generates code from the specified <paramref name="constructor"/>.
        /// </summary>
        /// <param name="constructor">Class constructor for which code needs to be generated.</param>
        /// <param name="type">Type declaration.</param>
        /// <param name="namespace">Namespace declaration.</param>
        /// <param name="options">Code generation options.</param>
        /// <remarks>
        /// This method is a workaround for <see cref="CodeDomProvider.GenerateCodeFromMember"/> 
        /// not generating constructors properly.
        /// </remarks>
        private void GenerateCodeFromConstructor(
            CodeConstructor constructor,
            CodeTypeDeclaration type,
            CodeNamespace @namespace,
            CodeGeneratorOptions options)
        {
            const string StartMarker = "___startMarker___";
            const string EndMarker = "___endMarker___";

            // Insert marker fields around the target constructor
            int indexOfMember = type.Members.IndexOf(constructor);
            type.Members.Insert(indexOfMember + 1, new CodeMemberField(typeof(int), EndMarker));
            type.Members.Insert(indexOfMember, new CodeMemberField(typeof(int), StartMarker));

            using (StringWriter buffer = new StringWriter(CultureInfo.InvariantCulture))
            {
                // Generate type declaration in verbatim order to preserve placement of marker fields
                options = options ?? new CodeGeneratorOptions();
                options.VerbatimOrder = true;
                this.LanguageProvider.GenerateCodeFromNamespace(@namespace, buffer, options);

                // Extract constructor code from the generated type code
                const string ConstructorCode = "constructor";
                Regex regex = new Regex(
                    @"^[^\r\n]*" + StartMarker + @"[^\n]*$" +
                    @"(?<" + ConstructorCode + @">.*)" +
                    @"^[^\r\n]*" + EndMarker + @"[^\n]*$",
                    RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.ExplicitCapture);
                string code = regex.Match(buffer.ToString()).Groups[ConstructorCode].Value;

                // Write constructor code to the output buffer
                this.ClassCode.Write(code);
            }
        }
开发者ID:gyb333,项目名称:Learning,代码行数:45,代码来源:TransformationContextProcessor.cs


示例10: Generate

		public CodeExpression[] Generate(Table table, HardwireCodeGenerationContext generatorContext, CodeTypeMemberCollection members)
		{
			string className = "AIDX_" + Guid.NewGuid().ToString("N");
			string name = table.Get("name").String;
			bool setter = table.Get("setter").Boolean;

			CodeTypeDeclaration classCode = new CodeTypeDeclaration(className);

			classCode.TypeAttributes = System.Reflection.TypeAttributes.NestedPrivate | System.Reflection.TypeAttributes.Sealed;

			classCode.BaseTypes.Add(typeof(ArrayMemberDescriptor));

			CodeConstructor ctor = new CodeConstructor();
			ctor.Attributes = MemberAttributes.Assembly;
			classCode.Members.Add(ctor);

			ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(name));
			ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(setter));
			
			DynValue vparams = table.Get("params");

			if (vparams.Type == DataType.Table)
			{
				List<HardwireParameterDescriptor> paramDescs = HardwireParameterDescriptor.LoadDescriptorsFromTable(vparams.Table);

				ctor.BaseConstructorArgs.Add(new CodeArrayCreateExpression(typeof(ParameterDescriptor), paramDescs.Select(e => e.Expression).ToArray()));
			}

			members.Add(classCode);
			return new CodeExpression[] { new CodeObjectCreateExpression(className) };
		}
开发者ID:InfectedBytes,项目名称:moonsharp,代码行数:31,代码来源:ArrayMemberDescriptorGenerator.cs


示例11: GetInitializeMethod

 protected override CodeMemberMethod GetInitializeMethod(IDesignerSerializationManager manager, CodeTypeDeclaration typeDecl, object value)
 {
     if (manager == null)
     {
         throw new ArgumentNullException("manager");
     }
     if (typeDecl == null)
     {
         throw new ArgumentNullException("typeDecl");
     }
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     CodeMemberMethod method = typeDecl.UserData[_initMethodKey] as CodeMemberMethod;
     if (method == null)
     {
         method = new CodeMemberMethod {
             Name = "InitializeComponent",
             Attributes = MemberAttributes.Private
         };
         typeDecl.UserData[_initMethodKey] = method;
         CodeConstructor constructor = new CodeConstructor {
             Attributes = MemberAttributes.Public
         };
         constructor.Statements.Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InitializeComponent", new CodeExpression[0]));
         typeDecl.Members.Add(constructor);
     }
     return method;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:ActivityTypeCodeDomSerializer.cs


示例12: GenerateCode

        public CodeCompileUnit GenerateCode(string typeName, string codeBody,
            StringCollection imports,
            string prefix)
        {
            var compileUnit = new CodeCompileUnit();

            var typeDecl = new CodeTypeDeclaration(typeName);
            typeDecl.IsClass = true;
            typeDecl.TypeAttributes = TypeAttributes.Public;

            // create constructor
            var constructMember = new CodeConstructor {Attributes = MemberAttributes.Public};
            typeDecl.Members.Add(constructMember);

            // pump in the user specified code as a snippet
            var literalMember =
                new CodeSnippetTypeMember(codeBody);
            typeDecl.Members.Add(literalMember);

            var nspace = new CodeNamespace();

            ////Add default imports
            //foreach (string nameSpace in ScriptExecuter._namespaces)
            //{
            //    nspace.Imports.Add(new CodeNamespaceImport(nameSpace));
            //}
            foreach (string nameSpace in imports)
            {
                nspace.Imports.Add(new CodeNamespaceImport(nameSpace));
            }
            compileUnit.Namespaces.Add(nspace);
            nspace.Types.Add(typeDecl);

            return compileUnit;
        }
开发者ID:hiriumi,项目名称:EasyReporting,代码行数:35,代码来源:CompilerInfo.cs


示例13: GetInitializeMethod

        protected override CodeMemberMethod GetInitializeMethod(IDesignerSerializationManager manager, CodeTypeDeclaration typeDecl, object value)
        {
            if (manager == null)
                throw new ArgumentNullException("manager");
            if (typeDecl == null)
                throw new ArgumentNullException("typeDecl");
            if (value == null)
                throw new ArgumentNullException("value");

            CodeMemberMethod method = typeDecl.UserData[_initMethodKey] as CodeMemberMethod;
            if (method == null)
            {
                method = new CodeMemberMethod();
                method.Name = _initMethodName;
                method.Attributes = MemberAttributes.Private;
                typeDecl.UserData[_initMethodKey] = method;

                // Now create a ctor that calls this method.
                CodeConstructor ctor = new CodeConstructor();
                ctor.Attributes = MemberAttributes.Public;
                ctor.Statements.Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), _initMethodName));
                typeDecl.Members.Add(ctor);
            }
            return method;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:25,代码来源:ActivityTypeCodeDomSerializer.cs


示例14: AddConstructor

        private static void AddConstructor(CodeTypeDeclaration declaration)
        {
            CodeConstructor constructor = new CodeConstructor();
            constructor.Attributes = MemberAttributes.Public;

            constructor.Parameters.Add(
                new CodeParameterDeclarationExpression(
                    typeof(IDbConnection), "connection"));

            constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression("connection"));

            constructor.CustomAttributes.Add(new CodeAttributeDeclaration(
                    new CodeTypeReference(typeof(DebuggerNonUserCodeAttribute))
                ));

            constructor.Statements.Add(
                new CodeAssignStatement(
                    new CodeVariableReferenceExpression(SqlDataContextHelperClassName),
                    new CodeObjectCreateExpression(
                        typeof(SqlDataContextHelperClass),
                        new CodeExpression[] {
                            new CodeThisReferenceExpression()
                        }
                    )
                ));

            declaration.Members.Add(constructor);
        }
开发者ID:DBailey635,项目名称:C1-CMS,代码行数:28,代码来源:DataContextClassGenerator.cs


示例15: AddConstructor

        /// <summary>
        /// Add a constructor to the class.
        /// </summary>
        public void AddConstructor()
        {
            // Declare the constructor
            CodeConstructor constructor = new CodeConstructor();
            constructor.Attributes =
                MemberAttributes.Public | MemberAttributes.Final;

            // Add parameters.
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(
                typeof(System.Double), "width"));
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(
                typeof(System.Double), "height"));

            // Add field initialization logic
            CodeFieldReferenceExpression widthReference =
                new CodeFieldReferenceExpression(
                new CodeThisReferenceExpression(), "widthValue");
            constructor.Statements.Add(new CodeAssignStatement(widthReference,
                new CodeArgumentReferenceExpression("width")));
            CodeFieldReferenceExpression heightReference =
                new CodeFieldReferenceExpression(
                new CodeThisReferenceExpression(), "heightValue");
            constructor.Statements.Add(new CodeAssignStatement(heightReference,
                new CodeArgumentReferenceExpression("height")));
            targetClass.Members.Add(constructor);
        }
开发者ID:WaylandGod,项目名称:Unity_CodeDOMSample,代码行数:29,代码来源:Sample.cs


示例16: CreateRequiredConstructor

        internal CodeConstructor CreateRequiredConstructor(CodeTypeDeclaration resourceClass,
                                                           IMethod request,
                                                           bool addOptionalParameters)
        {
            var constructor = new CodeConstructor();
            constructor.Attributes = MemberAttributes.Public;

            // IRequestProvider service
            var serviceArg = new CodeParameterDeclarationExpression(typeof(IRequestProvider), ServiceName);
            constructor.Parameters.Add(serviceArg);

            // : base(service, "path", "HTTPMETHOD")
            constructor.BaseConstructorArgs.Add(
                new CodePropertyReferenceExpression(
                    new CodeVariableReferenceExpression(ServiceName), BaseUriName));
            constructor.BaseConstructorArgs.Add(new CodePrimitiveExpression(request.MediaUpload.Simple.Path));
            constructor.BaseConstructorArgs.Add(new CodePrimitiveExpression(request.HttpMethod));

            // Add all required arguments to the constructor.
            AddBodyParameter(constructor, request);

            // Add common upload arguements.
            constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(StreamParameterName));
            constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(ContentTypeParameterName));

            AddAuthorizationAssignment(constructor);
            AddRequestParameters(resourceClass, request, constructor, addOptionalParameters);

            constructor.Parameters.Add(new CodeParameterDeclarationExpression(
                new CodeTypeReference(typeof(System.IO.Stream)), StreamParameterName));
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(
                new CodeTypeReference(typeof(System.String)), ContentTypeParameterName));

            return constructor;
        }
开发者ID:JANCARLO123,项目名称:google-apis,代码行数:35,代码来源:UploadConstructorDecorator.cs


示例17: Emit

        // Generates a codedom constructor expression and attaches it to the given type.
        public static void Emit(CodeTypeDeclaration codeTypeDeclaration, Constructor ctor)
        {
            // Create the codedom constructor
            var codeCtor = new CodeConstructor();
            codeTypeDeclaration.Members.Add(codeCtor);

            // Translate accessibility of the constructor
            MemberAttributes memberAttributes = MemberAttributes.Public;
            switch (ctor.Accessibility)
            {
                case Accessibility.Internal:
                    memberAttributes |= MemberAttributes.FamilyAndAssembly;
                    break;
                case Accessibility.Private:
                    memberAttributes |= MemberAttributes.Private;
                    break;
                case Accessibility.Protected:
                    memberAttributes |= MemberAttributes.Family;
                    break;
                case Accessibility.Public:
                    memberAttributes |= MemberAttributes.Public;
                    break;
            }
            codeCtor.Attributes = memberAttributes;

            // Translate the parameters of the constructor
            foreach (Expression p in ctor.Parameters)
            {
                if (p is SimpleParameter) // ex "int i"
                    codeCtor.Parameters.Add(new CodeParameterDeclarationExpression((p as SimpleParameter).TypeName, (p as SimpleParameter).Name));
                if (p is DirectionedParameter) // ex "ref int i"
                {
                    var codeParameter = new CodeParameterDeclarationExpression((p as DirectionedParameter).TypeName, (p as DirectionedParameter).Name);
                    switch ((p as DirectionedParameter).Direction)
                    {
                        case ParameterDirection.Out:
                            codeParameter.Direction = FieldDirection.Out;
                            break;
                        case ParameterDirection.Ref:
                            codeParameter.Direction = FieldDirection.Ref;
                            break;
                    }
                    codeCtor.Parameters.Add(codeParameter);
                }
            }

            // Add call to a constructor of the base class or another in the same class.
            foreach (var a in ctor.SubParameters.ChildExpressions)
            {
                if (ctor.Sub)
                    codeCtor.ChainedConstructorArgs.Add(CodeDomEmitter.EmitCodeExpression(a));
                else
                    codeCtor.BaseConstructorArgs.Add(CodeDomEmitter.EmitCodeExpression(a));
            }

            // Add all the statements in the body of the constructor
            foreach (var e in ctor.ChildExpressions)
                codeCtor.Statements.Add(CodeDomEmitter.EmitCodeStatement(e));
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:60,代码来源:ConstructorEmitter.cs


示例18: AddConstructor

        public CodeConstructor AddConstructor(CodeTypeDeclaration type)
        {
            CodeConstructor constructor = new CodeConstructor();
            constructor.Attributes = MemberAttributes.Public | MemberAttributes.Final;

            type.Members.Add(constructor);
            return constructor;
        }
开发者ID:xpk-rodaire,项目名称:GitHubVS2013,代码行数:8,代码来源:ClassBuilder.cs


示例19: GenerateDefaultConstructor

 private void GenerateDefaultConstructor(CodeTypeDeclaration classObject, JsonObject jsonObject)
 {
     CodeConstructor constructor = new CodeConstructor();
     classObject.Members.Add(constructor);
     constructor.Attributes = MemberAttributes.Public;
     CodeAssignStatement statement = new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), "RootObject"), new CodeObjectCreateExpression(jsonObject.GetType(), new CodeExpression[0]));
     constructor.Statements.Add(statement);
 }
开发者ID:jojozhuang,项目名称:Projects,代码行数:8,代码来源:JsonGenerator.cs


示例20: Generate

        public virtual string Generate(Window window)
        {
            window.ReInitialize(InitializeOption.WithCache);
            var stringBuilder = new StringBuilder();
            var stringWriter = new StringWriter(stringBuilder);

            var cscProvider = new CSharpCodeProvider();
            ICodeGenerator codeGenerator = cscProvider.CreateGenerator(stringWriter);
            var codeGeneratorOptions = new CodeGeneratorOptions {BlankLinesBetweenMembers = false, VerbatimOrder = false};

            codeGenerator.GenerateCodeFromCompileUnit(new CodeSnippetCompileUnit(string.Format("using {0};", typeof(UIItem).Namespace)), stringWriter, codeGeneratorOptions);
            codeGenerator.GenerateCodeFromCompileUnit(new CodeSnippetCompileUnit(string.Format("using {0};", typeof(Window).Namespace)), stringWriter, codeGeneratorOptions);
            codeGenerator.GenerateCodeFromCompileUnit(new CodeSnippetCompileUnit(string.Format("using {0};", typeof(AppScreen).Namespace)), stringWriter, codeGeneratorOptions);

            CodeNamespace codeNamespace = null;
            if (S.IsNotEmpty(options.Namespace))
            {
                codeNamespace = new CodeNamespace(options.Namespace);
            }

            var classDefinition = new CodeTypeDeclaration
                                      {
                                          IsClass = true,
                                          IsPartial = true,
                                          Name = window.Title.Trim().Replace(" ", string.Empty),
                                          TypeAttributes = TypeAttributes.Public
                                      };
            classDefinition.BaseTypes.Add(typeof (AppScreen));

            var constructor = new CodeConstructor {Attributes = MemberAttributes.Family};
            classDefinition.Members.Add(constructor);

            constructor = new CodeConstructor {Attributes = MemberAttributes.Public};
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Window), "window"));
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(typeof (ScreenRepository), "screenRepository"));
            constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression("window"));
            constructor.BaseConstructorArgs.Add(new CodeVariableReferenceExpression("screenRepository"));
            classDefinition.Members.Add(constructor);

            var visitor = new CodeGenerationVisitor(new WindowCodeGenerationStrategy(options));
            window.Visit(visitor);
            visitor.Generate(classDefinition);

            if (codeNamespace != null)
            {
                codeNamespace.Types.Add(classDefinition);
                codeGenerator.GenerateCodeFromNamespace(codeNamespace, stringWriter, codeGeneratorOptions);
            }
            else
            {
                codeGenerator.GenerateCodeFromType(classDefinition, stringWriter, codeGeneratorOptions);
            }

            stringWriter.Close();
            return stringBuilder.ToString();
        }
开发者ID:hsteinhilber,项目名称:white-project,代码行数:56,代码来源:ScreenObjectGenerator.cs



注:本文中的System.CodeDom.CodeConstructor类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CodeDom.CodeEventReferenceExpression类代码示例发布时间:2022-05-26
下一篇:
C# CodeDom.CodeConditionStatement类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap