当前位置: 首页>>代码示例>>C#>>正文


C# CodeDom.CodeVariableDeclarationStatement类代码示例

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


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

示例1: Serialize

 public override object Serialize(IDesignerSerializationManager manager, object value)
 {
     CodeExpression expression;
     CodeTypeDeclaration declaration = manager.Context[typeof(CodeTypeDeclaration)] as CodeTypeDeclaration;
     RootContext context = manager.Context[typeof(RootContext)] as RootContext;
     CodeStatementCollection statements = new CodeStatementCollection();
     if ((declaration != null) && (context != null))
     {
         CodeMemberField field = new CodeMemberField(typeof(IContainer), "components") {
             Attributes = MemberAttributes.Private
         };
         declaration.Members.Add(field);
         expression = new CodeFieldReferenceExpression(context.Expression, "components");
     }
     else
     {
         CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(IContainer), "components");
         statements.Add(statement);
         expression = new CodeVariableReferenceExpression("components");
     }
     base.SetExpression(manager, value, expression);
     CodeObjectCreateExpression right = new CodeObjectCreateExpression(typeof(Container), new CodeExpression[0]);
     CodeAssignStatement statement2 = new CodeAssignStatement(expression, right);
     statement2.UserData["IContainer"] = "IContainer";
     statements.Add(statement2);
     return statements;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:ContainerCodeDomSerializer.cs

示例2: Serialize

		public virtual object Serialize (IDesignerSerializationManager manager, object value)
		{
			if (value == null)
				throw new ArgumentNullException ("value");
			if (manager == null)
				throw new ArgumentNullException ("manager");

			bool isComplete = true;
			CodeStatementCollection statements = new CodeStatementCollection ();
			ExpressionContext context = manager.Context[typeof (ExpressionContext)] as ExpressionContext;
			object serialized = null;

			if (context != null && context.PresetValue == value) {
				string varName = base.GetUniqueName (manager, value);
				CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement (value.GetType (), varName); // declare
				statement.InitExpression = base.SerializeCreationExpression (manager, value, out isComplete); // initialize
				base.SetExpression (manager, value, statement.InitExpression);
				statements.Add (statement);
				serialized = statement;
			} else {
				string name = manager.GetName (value);
				if (name == null)
					name = base.GetUniqueName (manager, value);
				serialized = GetFieldReference (manager, name);
			}

			base.SerializeProperties (manager, statements, value, new Attribute[0]);
			base.SerializeEvents (manager, statements, value, new Attribute[0]);

			return serialized;
		}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:31,代码来源:CodeDomSerializer.cs

示例3: BuildExpressionSetup

        internal static void BuildExpressionSetup(ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, bool isTwoWayBound, bool designerMode) {
            // {{controlType}} target;
            CodeVariableDeclarationStatement targetDecl = new CodeVariableDeclarationStatement(controlBuilder.ControlType, "dataBindingExpressionBuilderTarget");
            methodStatements.Add(targetDecl);

            CodeVariableReferenceExpression targetExp = new CodeVariableReferenceExpression(targetDecl.Name);

            // target = ({{controlType}}) sender;
            CodeAssignStatement setTarget = new CodeAssignStatement(targetExp,
                                                                    new CodeCastExpression(controlBuilder.ControlType,
                                                                                           new CodeArgumentReferenceExpression("sender")));
            setTarget.LinePragma = linePragma;
            statements.Add(setTarget);

            Type bindingContainerType = controlBuilder.BindingContainerType;
            CodeVariableDeclarationStatement containerDecl = new CodeVariableDeclarationStatement(bindingContainerType, "Container");
            methodStatements.Add(containerDecl);

            // {{containerType}} Container = ({{containerType}}) target.BindingContainer;
            CodeAssignStatement setContainer = new CodeAssignStatement(new CodeVariableReferenceExpression(containerDecl.Name),
                                                                       new CodeCastExpression(bindingContainerType,
                                                                                              new CodePropertyReferenceExpression(targetExp,
                                                                                                                                  "BindingContainer")));
            setContainer.LinePragma = linePragma;
            statements.Add(setContainer);
            string variableName = isTwoWayBound ? "BindItem" : "Item";
            GenerateItemTypeExpressions(controlBuilder, methodStatements, statements, linePragma, variableName);
            //Generate code for other variable as well at design time in addition to runtime variable for intellisense to work.
            if (designerMode) {
                GenerateItemTypeExpressions(controlBuilder, methodStatements, statements, linePragma, isTwoWayBound ?  "Item" : "BindItem");
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:32,代码来源:DataBindingExpressionBuilder.cs

示例4: GetControlTemplateValueExpression

        private static CodeExpression GetControlTemplateValueExpression(CodeTypeDeclaration parentClass, CodeMemberMethod method, object value, string baseName)
        {
            ControlTemplate controlTemplate = value as ControlTemplate;
            DependencyObject content = controlTemplate.LoadContent();
            string variableName = baseName + "_ct";
            string creator = CodeComHelper.GenerateTemplate(parentClass, method, content, variableName);
            Type targetType = controlTemplate.TargetType;
            CodeVariableDeclarationStatement controlTemplateVar;
            if (targetType != null)
            {
                controlTemplateVar = new CodeVariableDeclarationStatement(
                    "ControlTemplate", variableName,
                    new CodeObjectCreateExpression("ControlTemplate", new CodeTypeOfExpression(targetType.Name), new CodeSnippetExpression(creator)));
            }
            else
            {
                controlTemplateVar = new CodeVariableDeclarationStatement(
                    "ControlTemplate", variableName,
                    new CodeObjectCreateExpression("ControlTemplate", new CodeSnippetExpression(creator)));
            }

            method.Statements.Add(controlTemplateVar);

            TriggerCollection triggers = controlTemplate.Triggers;
            CodeComHelper.GenerateTriggers(parentClass, method, variableName, targetType, triggers);

            return new CodeVariableReferenceExpression(variableName);
        }
开发者ID:fearfullymade,项目名称:UI_Generator,代码行数:28,代码来源:ControlTemplateGeneratorValue.cs

示例5: ResourceCallAddBodyDeclaration

        protected void ResourceCallAddBodyDeclaration(IMethod method,
                                                      CodeMemberMethod member,
                                                      CodeTypeReference bodyType,
                                                      bool addBodyIfUnused)
        {
            switch (method.HttpMethod)
            {
                case Request.GET:
                case Request.DELETE:
                    if (!addBodyIfUnused)
                    {
                        break;
                    }

                    // string body = null;
                    var bodyVarDeclaration = new CodeVariableDeclarationStatement(bodyType, "body");
                    bodyVarDeclaration.InitExpression = new CodePrimitiveExpression(null);
                    member.Statements.Add(bodyVarDeclaration);
                    break;

                case Request.PUT:
                case Request.POST:
                case Request.PATCH:
                    // add body Parameter.
                    member.Parameters.Add(new CodeParameterDeclarationExpression(bodyType, "body"));
                    break;
                default:
                    throw new NotSupportedException("Unsupported HttpMethod [" + method.HttpMethod + "]");
            }
        }
开发者ID:jithuin,项目名称:infogeezer,代码行数:30,代码来源:ResourceBaseGenerator.cs

示例6: CodeLocalVariableBinder

 /// <summary>
 /// Initializes a new instance of the <see cref="CodeLocalVariableBinder"/> class
 /// with a local variable declaration.
 /// </summary>
 /// <param name="method">The method to add a <see cref="CodeTypeReference"/> to.</param>
 /// <param name="variableDeclaration">The variable declaration to add.</param>
 internal CodeLocalVariableBinder(CodeMemberMethod method, CodeVariableDeclarationStatement variableDeclaration)
 {
     Guard.NotNull(() => method, method);
     Guard.NotNull(() => variableDeclaration, variableDeclaration);
     this.method = method;
     this.variableDeclaration = variableDeclaration;
 }
开发者ID:Jedzia,项目名称:NStub,代码行数:13,代码来源:CodeLocalVariableBinder.cs

示例7: AddCallbackImplementation

 internal static void AddCallbackImplementation(CodeTypeDeclaration codeClass, string callbackName, string handlerName, string handlerArgs, bool methodHasOutParameters)
 {
     CodeFlags[] parameterFlags = new CodeFlags[1];
     CodeMemberMethod method = AddMethod(codeClass, callbackName, parameterFlags, new string[] { typeof(object).FullName }, new string[] { "arg" }, typeof(void).FullName, null, (CodeFlags) 0);
     CodeEventReferenceExpression left = new CodeEventReferenceExpression(new CodeThisReferenceExpression(), handlerName);
     CodeBinaryOperatorExpression condition = new CodeBinaryOperatorExpression(left, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
     CodeStatement[] trueStatements = new CodeStatement[2];
     trueStatements[0] = new CodeVariableDeclarationStatement(typeof(InvokeCompletedEventArgs), "invokeArgs", new CodeCastExpression(typeof(InvokeCompletedEventArgs), new CodeArgumentReferenceExpression("arg")));
     CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression("invokeArgs");
     CodeObjectCreateExpression expression4 = new CodeObjectCreateExpression();
     if (methodHasOutParameters)
     {
         expression4.CreateType = new CodeTypeReference(handlerArgs);
         expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Results"));
     }
     else
     {
         expression4.CreateType = new CodeTypeReference(typeof(AsyncCompletedEventArgs));
     }
     expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Error"));
     expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "Cancelled"));
     expression4.Parameters.Add(new CodePropertyReferenceExpression(targetObject, "UserState"));
     trueStatements[1] = new CodeExpressionStatement(new CodeDelegateInvokeExpression(new CodeEventReferenceExpression(new CodeThisReferenceExpression(), handlerName), new CodeExpression[] { new CodeThisReferenceExpression(), expression4 }));
     method.Statements.Add(new CodeConditionStatement(condition, trueStatements, new CodeStatement[0]));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:25,代码来源:WebCodeGenerator.cs

示例8: BindingElementExtensionSectionGenerator

        internal BindingElementExtensionSectionGenerator(Type bindingElementType, Assembly userAssembly, CodeDomProvider provider)
        {
            this.bindingElementType = bindingElementType;
            this.userAssembly = userAssembly;
            this.provider = provider;

            string typePrefix = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement));
            this.generatedClassName = typePrefix + Constants.ElementSuffix;
            this.constantsClassName = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.ConfigurationStrings;
            this.defaultValuesClassName = bindingElementType.Name.Substring(0, bindingElementType.Name.IndexOf(TypeNameConstants.BindingElement)) + Constants.Defaults;

            this.customBEVarInstance = Helpers.TurnFirstCharLower(bindingElementType.Name);
            customBEArgRef = new CodeArgumentReferenceExpression(customBEVarInstance);

            this.customBETypeRef = new CodeTypeReference(bindingElementType.Name);
            this.customBETypeOfRef = new CodeTypeOfExpression(customBETypeRef);
            this.customBENewVarAssignRef = new CodeVariableDeclarationStatement(
                                                customBETypeRef,
                                                customBEVarInstance,
                                                new CodeObjectCreateExpression(customBETypeRef));
            this.bindingElementMethodParamRef = new CodeParameterDeclarationExpression(
                                                    CodeDomHelperObjects.bindingElementTypeRef,
                                                    Constants.bindingElementParamName);

        }
开发者ID:ssickles,项目名称:archive,代码行数:25,代码来源:BindingElementExtensionSectionGenerator.cs

示例9: GenerateBuildCode

        public void GenerateBuildCode(GeneratorContext ctx)
        {
            string varName = ctx.NewId ();
            CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (typeof(Gtk.IconFactory), varName);
            varDec.InitExpression = new CodeObjectCreateExpression (typeof(Gtk.IconFactory));
            ctx.Statements.Add (varDec);

            CodeVariableReferenceExpression var = new CodeVariableReferenceExpression (varName);
            foreach (ProjectIconSet icon in icons) {

                CodeExpression exp = new CodeMethodInvokeExpression (
                    var,
                    "Add",
                    new CodePrimitiveExpression (icon.Name),
                    icon.GenerateObjectBuild (ctx)
                );
                ctx.Statements.Add (exp);
            }

            CodeExpression addd = new CodeMethodInvokeExpression (
                var,
                "AddDefault"
            );
            ctx.Statements.Add (addd);
        }
开发者ID:mono,项目名称:stetic,代码行数:25,代码来源:ProjectIconFactory.cs

示例10: GenerateInstanceExpression

		public virtual CodeExpression GenerateInstanceExpression (ObjectWrapper wrapper, CodeExpression newObject)
		{
			string varName = NewId ();
			CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (wrapper.WrappedTypeName.ToGlobalTypeRef (), varName);
			varDec.InitExpression = newObject;
			statements.Add (varDec);
			return new CodeVariableReferenceExpression (varName);
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:8,代码来源:GeneratorContext.cs

示例11: CreateObject

 protected string CreateObject(Type type, string proposedName)
 {
     var variableName = State.GetVariableName(proposedName);
     var variableDeclaration = new CodeVariableDeclarationStatement(
         type.Name, variableName, new CodeObjectCreateExpression(type.Name));
     State.AddStatement(variableDeclaration);
     return variableName;
 }
开发者ID:huinalam,项目名称:XAML-conversion,代码行数:8,代码来源:ParserBase.cs

示例12: GetInitializationStatements

        public virtual IEnumerable<CodeStatement> GetInitializationStatements(AggregateFunctionContext context)
        {
            CodeExpression[] parameters = new CodeExpression[0];
            CodeStatement st = new CodeVariableDeclarationStatement(context.ImplementationType, context.FunctionObjectName,
                            new CodeObjectCreateExpression(context.ImplementationType, parameters));

            return new CodeStatement[] {st};
        }
开发者ID:varunkumarmnnit,项目名称:otis-lib,代码行数:8,代码来源:DefaultAggregateFunctionCodeGenerator.cs

示例13: CreateVariable

        public static Tuple<CodeVariableDeclarationStatement, CodeVariableReferenceExpression> CreateVariable(CodeTypeReference typeReference, string name, params CodeExpression[] constructorParameters)
        {
            CodeObjectCreateExpression initializer = new CodeObjectCreateExpression(typeReference, constructorParameters);
            CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeReference, name, initializer);
            CodeVariableReferenceExpression reference = new CodeVariableReferenceExpression(name);

            return new Tuple<CodeVariableDeclarationStatement, CodeVariableReferenceExpression>(statement, reference);
        }
开发者ID:snipervld,项目名称:StormXamarin,代码行数:8,代码来源:CodeGeneratorHelper.cs

示例14: Generate

        /// <summary>
        /// Generates code
        /// </summary>
        /// <param name="source">The dependence object</param>
        /// <param name="classType">Type of the class.</param>
        /// <param name="method">The initialize method.</param>
        /// <param name="generateField"></param>
        /// <returns></returns>
        public override CodeExpression Generate(DependencyObject source, CodeTypeDeclaration classType, CodeMemberMethod method, bool generateField)
        {
            CodeExpression fieldReference = base.Generate(source, classType, method, generateField);

            ItemsControl itemsControl = source as ItemsControl;
            CodeComHelper.GenerateTemplateStyleField(classType, method, fieldReference, source, ItemsControl.ItemsPanelProperty);
            CodeComHelper.GenerateTemplateStyleField(classType, method, fieldReference, source, ItemsControl.ItemTemplateProperty);

            if (itemsControl.Items.Count > 0)
            {
                TypeGenerator typeGenerator = new TypeGenerator();
                ValueGenerator valueGenerator = new ValueGenerator();

                CodeMemberMethod itemsMethod = new CodeMemberMethod();
                itemsMethod.Attributes = MemberAttributes.Static | MemberAttributes.Private;
                itemsMethod.Name = "Get_" + itemsControl.Name + "_Items";
                itemsMethod.ReturnType = new CodeTypeReference(typeof(ObservableCollection<object>));
                classType.Members.Add(itemsMethod);

                CodeVariableDeclarationStatement collection = new CodeVariableDeclarationStatement(
                    typeof(ObservableCollection<object>), "items", new CodeObjectCreateExpression(typeof(ObservableCollection<object>)));
                itemsMethod.Statements.Add(collection);

                CodeVariableReferenceExpression itemsVar = new CodeVariableReferenceExpression("items");
                foreach (var item in itemsControl.Items)
                {
                    Type itemType = item.GetType();
                    CodeExpression itemExpr = null;
                    if (typeGenerator.HasGenerator(itemType))
                    {
                        itemExpr = typeGenerator.ProcessGenerators(item, classType, itemsMethod, false);
                    }
                    else
                    {
                        itemExpr = valueGenerator.ProcessGenerators(classType, itemsMethod, item, itemsControl.Name);
                    }

                    if (itemExpr != null)
                    {
                        CodeMethodInvokeExpression addItem = new CodeMethodInvokeExpression(itemsVar, "Add", itemExpr);
                        itemsMethod.Statements.Add(addItem);
                    }
                    else
                    {
                        CodeComHelper.GenerateError(itemsMethod, string.Format("Type {0} in Items Control collection not supported", itemType.Name));
                    }
                }

                CodeMethodReturnStatement returnStatement = new CodeMethodReturnStatement(itemsVar);
                itemsMethod.Statements.Add(returnStatement);

                method.Statements.Add(new CodeAssignStatement(
                    new CodeFieldReferenceExpression(fieldReference, "ItemsSource"),
                    new CodeMethodInvokeExpression(null, itemsMethod.Name)));
            }

            return fieldReference;
        }
开发者ID:fearfullymade,项目名称:UI_Generator,代码行数:66,代码来源:ItemsControlGeneratorType.cs

示例15: GetSoundSourceCollectionValueExpression

 private static CodeExpression GetSoundSourceCollectionValueExpression(CodeMemberMethod method, object value, string baseName)
 {
     string collVar = baseName + "_sounds";
     CodeVariableDeclarationStatement collection =
             new CodeVariableDeclarationStatement("var", collVar, new CodeObjectCreateExpression("SoundSourceCollection"));
     method.Statements.Add(collection);
     CodeComHelper.GenerateSoundSources(method, value as SoundSourceCollection, collVar);
     return new CodeVariableReferenceExpression(collVar);
 }         
开发者ID:fearfullymade,项目名称:UI_Generator,代码行数:9,代码来源:SoundSourceGeneratorValue.cs


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