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


C# CodeDom.CodeConditionStatement类代码示例

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


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

示例1: BuildDetectChangedMembers

        public static CodeStatementCollection BuildDetectChangedMembers(TableViewTableTypeBase table)
        {
            CodeStatementCollection ValidationSetStatement = new CodeStatementCollection();
            String PocoTypeName = "this";
            ValidationSetStatement.Add(new CodeSnippetExpression("Boolean bResult = new Boolean()"));
            ValidationSetStatement.Add(new CodeSnippetExpression("bResult = false"));

            foreach (Column c in table.Columns)
            {
                MemberGraph mGraph = new MemberGraph(c);
                CodeConditionStatement csTest1 = new CodeConditionStatement();

                if (mGraph.IsNullable)
                {
                    csTest1.Condition = new CodeSnippetExpression(PocoTypeName + "." + mGraph.PropertyName() + ".HasValue == true");
                    csTest1.TrueStatements.Add(new CodeSnippetExpression("bResult = true"));
                }
                else
                {
                    csTest1.Condition = new CodeSnippetExpression(PocoTypeName + "." + mGraph.PropertyName() + " == null");
                    csTest1.TrueStatements.Add(new CodeSnippetExpression(""));
                    csTest1.FalseStatements.Add(new CodeSnippetExpression("bResult = true"));
                }
            }

            return ValidationSetStatement;
        }
开发者ID:rexwhitten,项目名称:MGenerator,代码行数:27,代码来源:GraphAttributeSet.cs

示例2: CreateWithApiKey

        /// <summary>
        /// if (string.IsNullOrEmpty(APIKey) == false)
        ///    request = request.WithAPIKey(APIKey)
        /// </summary>
        /// <returns></returns>
        internal CodeConditionStatement CreateWithApiKey()
        {
            // !string.IsNullOrEmpty(Key)
            var condition = new CodeBinaryOperatorExpression(
                new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(string)), "IsNullOrEmpty",
                        new CodeVariableReferenceExpression(ApiKeyServiceDecorator.PropertyName)),
                CodeBinaryOperatorType.ValueEquality,
                new CodePrimitiveExpression(false));

            //var condition =
                //new CodeSnippetExpression("!string.IsNullOrEmpty(" + ApiKeyServiceDecorator.PropertyName + ")");

            // if (...) {
            var block = new CodeConditionStatement(condition);

            // request = request.WithKey(APIKey)
            var getProperty = new CodePropertyReferenceExpression(
                new CodeThisReferenceExpression(), ApiKeyServiceDecorator.PropertyName);
            var request = new CodeMethodInvokeExpression(
                new CodeVariableReferenceExpression("request"), "WithKey", getProperty);

            var trueCase = new CodeAssignStatement(new CodeVariableReferenceExpression("request"), request);

            // }
            block.TrueStatements.Add(trueCase);

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

示例3: BuildEvalExpression

        internal static void BuildEvalExpression(string field, string formatString, string propertyName,
            Type propertyType, ControlBuilder controlBuilder, CodeStatementCollection methodStatements, CodeStatementCollection statements, CodeLinePragma linePragma, bool isEncoded, ref bool hasTempObject) {

            // Altogether, this function will create a statement that looks like this:
            // if (this.Page.GetDataItem() != null) {
            //     target.{{propName}} = ({{propType}}) this.Eval(fieldName, formatString);
            // }

            //     this.Eval(fieldName, formatString)
            CodeMethodInvokeExpression evalExpr = new CodeMethodInvokeExpression();
            evalExpr.Method.TargetObject = new CodeThisReferenceExpression();
            evalExpr.Method.MethodName = EvalMethodName;
            evalExpr.Parameters.Add(new CodePrimitiveExpression(field));
            if (!String.IsNullOrEmpty(formatString)) {
                evalExpr.Parameters.Add(new CodePrimitiveExpression(formatString));
            }

            CodeStatementCollection evalStatements = new CodeStatementCollection();
            BuildPropertySetExpression(evalExpr, propertyName, propertyType, controlBuilder, methodStatements, evalStatements, linePragma, isEncoded, ref hasTempObject);

            // if (this.Page.GetDataItem() != null)
            CodeMethodInvokeExpression getDataItemExpr = new CodeMethodInvokeExpression();
            getDataItemExpr.Method.TargetObject = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Page");
            getDataItemExpr.Method.MethodName = GetDataItemMethodName;

            CodeConditionStatement ifStmt = new CodeConditionStatement();
            ifStmt.Condition = new CodeBinaryOperatorExpression(getDataItemExpr, 
                                                                CodeBinaryOperatorType.IdentityInequality, 
                                                                new CodePrimitiveExpression(null));
            ifStmt.TrueStatements.AddRange(evalStatements);
            statements.Add(ifStmt);
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:32,代码来源:DataBindingExpressionBuilder.cs

示例4: IfTrueReturnNull

	public static CodeConditionStatement IfTrueReturnNull (CodeExpression condition)
	{
	    CodeConditionStatement cond = new CodeConditionStatement ();
	    cond.Condition = condition;
	    cond.TrueStatements.Add (new CodeMethodReturnStatement (Null));
	    return cond;
	}
开发者ID:emtees,项目名称:old-code,代码行数:7,代码来源:CodeDomHelpers.cs

示例5: Emit

        // Emits the codedom statement for an if conditional block.
        public static CodeStatement Emit(IfBlock ifBlock)
        {
            // Create the codedom if statement.
            var i = new CodeConditionStatement();

            // Emit the conditional statements for the if block.
            i.Condition = CodeDomEmitter.EmitCodeExpression(ifBlock.Conditional.ChildExpressions[0]);

            // Emit the lists of statements for the true and false bodies of the if block.

            // Comments need to be added in case the bodies are empty: these two properties
            // of the CodeConditionStatement can't be null.
            i.FalseStatements.Add(new CodeCommentStatement("If condition is false, execute these statements."));
            i.TrueStatements.Add(new CodeCommentStatement("If condition is true, execute these statements."));

            // Emit the statements for the true block
            foreach (var e in ifBlock.TrueBlock.ChildExpressions)
                i.TrueStatements.Add(CodeDomEmitter.EmitCodeStatement(e));

            // Emit the statements for the false block.
            foreach (var e in ifBlock.FalseBlock.ChildExpressions)
                i.FalseStatements.Add(CodeDomEmitter.EmitCodeStatement(e));

            return i;
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:26,代码来源:IfBlockEmitter.cs

示例6: Constructor0_Deny_Unrestricted

		public void Constructor0_Deny_Unrestricted ()
		{
			CodeConditionStatement css = new CodeConditionStatement ();
			Assert.IsNull (css.Condition, "Condition");
			css.Condition = new CodeExpression ();
			Assert.AreEqual (0, css.FalseStatements.Count, "FalseStatements");
			Assert.AreEqual (0, css.TrueStatements.Count, "TrueStatements");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:8,代码来源:CodeConditionStatementCas.cs

示例7: Constructor1_Deny_Unrestricted

		public void Constructor1_Deny_Unrestricted ()
		{
			CodeExpression condition = new CodeExpression ();
			CodeStatement[] cs = new CodeStatement[1] { new CodeStatement () };
			CodeConditionStatement css = new CodeConditionStatement (condition, cs);
			Assert.AreSame (condition, css.Condition, "Condition");
			css.Condition = new CodeExpression ();
			Assert.AreEqual (0, css.FalseStatements.Count, "FalseStatements");
			Assert.AreEqual (1, css.TrueStatements.Count, "TrueStatements");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:CodeConditionStatementCas.cs

示例8: EmitConditionStatement

        void EmitConditionStatement(CodeConditionStatement cond)
        {
            writer.Write(Parser.FlowIf);
            writer.Write(Parser.SingleSpace);
            writer.Write(Parser.ParenOpen);
            EmitExpression(cond.Condition);
            writer.Write(Parser.ParenClose);

            if (cond.TrueStatements.Count > 1)
            {
                WriteSpace();
                writer.Write(Parser.BlockOpen);
            }

            depth++;
            EmitStatements(cond.TrueStatements);
            depth--;

            if (cond.TrueStatements.Count > 1)
            {
                WriteSpace();
                writer.Write(Parser.BlockClose);
            }

            if (cond.FalseStatements.Count > 0)
            {
                if (options.ElseOnClosing)
                    writer.Write(Parser.SingleSpace);
                else
                    WriteSpace();

                writer.Write(Parser.FlowElse);

                if (cond.FalseStatements.Count > 1)
                {
                    if (options.ElseOnClosing)
                        writer.Write(Parser.SingleSpace);
                    else
                        WriteSpace();

                    writer.Write(Parser.BlockOpen);
                }

                depth++;
                EmitStatements(cond.FalseStatements);
                depth--;

                if (cond.FalseStatements.Count > 1)
                {
                    WriteSpace();
                    writer.Write(Parser.BlockClose);
                }
            }
        }
开发者ID:lnsoso,项目名称:IronAHK,代码行数:54,代码来源:Flow.cs

示例9: Generate

        /// <summary>
        /// Generates the specified dictionary.
        /// </summary>
        /// <param name="dictionary">The dictionary.</param>
        /// <param name="classType">Type of the class.</param>
        /// <param name="initMethod">The initialize method.</param>
        /// <param name="fieldReference">The field reference.</param>
        public void Generate(ResourceDictionary dictionary, CodeTypeDeclaration classType, CodeMemberMethod initMethod, CodeExpression fieldReference)
        {
            foreach (var mergedDict in dictionary.MergedDictionaries)
            {
                string name = string.Empty;
                if (mergedDict.Source.IsAbsoluteUri)
                {
                    name = Path.GetFileNameWithoutExtension(mergedDict.Source.LocalPath);                    
                }
                else
                {
                    name = Path.GetFileNameWithoutExtension(mergedDict.Source.OriginalString);                    
                }

                if (string.IsNullOrEmpty(name))
                {
                    Console.WriteLine("Dictionary name not found.");
                    continue;
                }

                CodeMethodInvokeExpression addMergedDictionary = new CodeMethodInvokeExpression(
                        fieldReference, "MergedDictionaries.Add", new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(name), "Instance"));
                initMethod.Statements.Add(addMergedDictionary);
            }

            ValueGenerator valueGenerator = new ValueGenerator();
            List<object> keys = dictionary.Keys.Cast<object>().OrderBy(k => k.ToString()).ToList();
            foreach (var resourceKey in keys)
            {
                object resourceValue = dictionary[resourceKey];

                CodeComment comment = new CodeComment("Resource - [" + resourceKey.ToString() + "] " + resourceValue.GetType().Name);
                initMethod.Statements.Add(new CodeCommentStatement(comment));

                CodeExpression keyExpression = CodeComHelper.GetResourceKeyExpression(resourceKey);
                CodeExpression valueExpression = valueGenerator.ProcessGenerators(classType, initMethod, resourceValue, "r_" + uniqueId, dictionary);

                if (valueExpression != null)
                {
                    
                    CodeMethodInvokeExpression addResourceMethod = new CodeMethodInvokeExpression(fieldReference, "Add", keyExpression, valueExpression);

                    var check = new CodeConditionStatement(
                        new CodeMethodInvokeExpression(fieldReference, "Contains", keyExpression), 
                        new CodeStatement[] { },
                        new CodeStatement[] { new CodeExpressionStatement(addResourceMethod) });

                    initMethod.Statements.Add(check);
                }

                uniqueId++;
            }
        }
开发者ID:fearfullymade,项目名称:UI_Generator,代码行数:60,代码来源:ResourceDictionaryGenerator.cs

示例10: Clone

 public static CodeConditionStatement Clone(this CodeConditionStatement statement)
 {
     if (statement == null) return null;
     CodeConditionStatement s = new CodeConditionStatement();
     s.Condition = statement.Condition.Clone();
     s.EndDirectives.AddRange(statement.EndDirectives);
     s.FalseStatements.AddRange(statement.FalseStatements.Clone());
     s.LinePragma = statement.LinePragma;
     s.StartDirectives.AddRange(statement.StartDirectives);
     s.TrueStatements.AddRange(statement.TrueStatements.Clone());
     s.UserData.AddRange(statement.UserData);
     return s;
 }
开发者ID:jw56578,项目名称:SpecFlowTest,代码行数:13,代码来源:CodeConditionStatementExtensions.cs

示例11: FinishProcessingRun

		public override void FinishProcessingRun ()
		{
			var statement = new CodeConditionStatement (
				new CodeBinaryOperatorExpression (
					new CodePropertyReferenceExpression (
						new CodePropertyReferenceExpression (new CodeThisReferenceExpression (), "Errors"), "HasErrors"),
					CodeBinaryOperatorType.ValueEquality,
					new CodePrimitiveExpression (false)),
				postStatements.ToArray ());
			
			postStatements.Clear ();
			postStatements.Add (statement);
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:13,代码来源:ParameterDirectiveProcessor.cs

示例12: SetActualStmt

        internal void SetActualStmt(CodeConditionStatement actualStmt)
        {
            if (actualStmt == null)
            {
                actualStmt = this;
            }

            if (actualStmt != _actualStmt)
            {
                actualStmt.Condition = _actualStmt.Condition;
                actualStmt.TrueStatements.Clear();
                actualStmt.TrueStatements.AddRange(_actualStmt.TrueStatements);
                _actualStmt = actualStmt;
            }
        }
开发者ID:Saleslogix,项目名称:SLXMigration,代码行数:15,代码来源:CodeSwitchOption.cs

示例13: Visit

        public void Visit(WhenBooleanStatement statement)
        {
            var arg = VisitChild(statement.Expression, new CodeDomArg() { Scope = _codeStack.Peek().Scope });
            if (arg.Tag != null)
                _codeStack.Peek().Tag = arg.Tag;

            var condition = new CodeConditionStatement();
            condition.Condition = arg.CodeExpression;

            var then = VisitChild(statement.Then, new CodeDomArg() { Scope = _codeStack.Peek().Scope });
            condition.TrueStatements.Add(new CodeMethodReturnStatement(then.CodeExpression));
            if (arg.Tag != null)
                _codeStack.Peek().Tag = arg.Tag;

            _codeStack.Peek().ParentStatements.Add(condition);
        }
开发者ID:bitsummation,项目名称:pickaxe,代码行数:16,代码来源:Visitor.WhenBooleanStatement.cs

示例14: SetNodeValue

        public void SetNodeValue(XmlNode n)
        {
            for (int i = 0; i < n.Attributes.Count; i++)
            {
                string value = n.Attributes[i].Value;

                //AddField(n.Attributes[i].Name, value, MemberAttributes.Private);
                fieldList.Add(new ItemField(n.Attributes[i].Name, value, MemberAttributes.Private));

                ItemProperty item = new ItemProperty(n.Attributes[i].Name);
                item.SetGetName();
                item.SetValueType(value);
                item.SetModifier(MemberAttributes.Public | MemberAttributes.Final);
                propertyList.Add(item);

                CodeConditionStatement condition = new CodeConditionStatement();
                condition.Condition = new CodeVariableReferenceExpression("inArg0.ContainsKey(\"" + n.Attributes[i].Name + "\")");

                string parseLeft = "";
                string parseRight = "";
                if (Stringer.IsNumber(value))
                {
                    parseLeft = value.Contains(".") ? "float.Parse(" : "uint.Parse(";
                    parseRight = ")";
                }
                CodeVariableReferenceExpression right = new CodeVariableReferenceExpression(parseLeft + "inArg0[\"" + n.Attributes[i].Name + "\"]" + parseRight);
                CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "_" + Stringer.FirstLetterLower(n.Attributes[i].Name));

                if (Stringer.IsNumber(value))
                {
                    CodeConditionStatement numCondition = new CodeConditionStatement();
                    numCondition.Condition = new CodeVariableReferenceExpression("inArg0[\"" + n.Attributes[i].Name + "\"] == \"\"");

                    numCondition.TrueStatements.Add(new CodeAssignStatement(left, new CodeVariableReferenceExpression("0")));
                    numCondition.FalseStatements.Add(new CodeAssignStatement(left, right));

                    condition.TrueStatements.Add(numCondition);
                }
                else
                {
                    condition.TrueStatements.Add(new CodeAssignStatement(left, right));
                }

                AddConditionStatement(condition);
            }
            Create();
        }
开发者ID:killliu,项目名称:AutoCSharp,代码行数:47,代码来源:XmlUnit.cs

示例15: GetKeywordFromCodeDom

		public void GetKeywordFromCodeDom()
		{
			CodeStatement st = new CodeExpressionStatement(new CodeArgumentReferenceExpression("foo"));
			CodeExpression exp = new CodeArgumentReferenceExpression("foo");
			CodeIterationStatement it = new CodeIterationStatement(st, exp, st);

			CodeConditionStatement cond = new CodeConditionStatement(exp);

			new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromStatement(
				it, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
			new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromStatement(
				cond, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());

			new Microsoft.VisualBasic.VBCodeProvider().GenerateCodeFromStatement(
				it, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
			new Microsoft.VisualBasic.VBCodeProvider().GenerateCodeFromStatement(
				cond, Console.Out, new System.CodeDom.Compiler.CodeGeneratorOptions());
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:18,代码来源:RegexTests.cs


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