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

C# CodeDom.CodeConditionStatement类代码示例

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

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



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


示例16: BuildSelectBE

        /// <summary>
        /// 
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public CodeMemberMethod BuildSelectBE(TableViewTableTypeBase table)
        {
            CodeMemberMethod cmSelect = new CodeMemberMethod();
            cmSelect.Attributes = MemberAttributes.Public;
            cmSelect.ReturnType = new CodeTypeReference("System.Data.DataSet");
            String cp_name = "ssp_" + table.Name;
            String PocoTypeName = table.Name;
            String FullPocoTypeName = PocoTypeName;

            CodeParameterDeclarationExpression cpdePoco = new CodeParameterDeclarationExpression();
            cpdePoco.Name = "query";
            cpdePoco.Type = new CodeTypeReference(table.Name);
            cpdePoco.Direction = FieldDirection.In;
            cmSelect.Parameters.Add(cpdePoco);
            cmSelect.Attributes = MemberAttributes.Public;
            cmSelect.Name = "Select";
            cmSelect.Statements.Add(new CodeSnippetExpression("this.Access.CreateProcedureCommand(\"" + cp_name + "\")"));

            foreach (Column c in table.Columns)
            {
                MemberGraph mGraph = new MemberGraph(c);
                String DotNetTypeName = TypeConvertor.ToNetType(c.DataType.SqlDataType).ToString();

                System.CodeDom.CodeConditionStatement ccsField = new CodeConditionStatement();
                if (mGraph.IsNullable)
                {
                    ccsField.Condition = new CodeSnippetExpression("query." + mGraph.PropertyName() + ".HasValue");
                    ccsField.TrueStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\",query." + mGraph.PropertyName() + ".Value, ParameterDirection.Input)"));
                    ccsField.FalseStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", null , ParameterDirection.Input)"));
                }
                else
                {
                    ccsField.Condition = new CodeSnippetExpression("query." + mGraph.PropertyName() + " == null");
                    ccsField.TrueStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\", null , ParameterDirection.Input)"));
                    ccsField.FalseStatements.Add(new CodeSnippetExpression("this.Access.AddParameter(\"" + mGraph.PropertyName() + "\",query." + mGraph.PropertyName() + ", ParameterDirection.Input)"));
                }

                cmSelect.Statements.Add(ccsField);
            }

            cmSelect.Statements.Add(new CodeSnippetExpression("return this.Access.ExecuteDataSet()"));
            cmSelect.Comments.Add(new CodeCommentStatement("Select by Object [Implements Query By Example], returns DataSet"));
            return cmSelect;
        }
开发者ID:rexwhitten,项目名称:MGenerator,代码行数:49,代码来源:DalClassFactory.cs


示例17: CreateMappingStatements

        public static CodeStatement[] CreateMappingStatements(ClassMappingDescriptor descriptor, CodeGeneratorContext context)
        {
            Dictionary<string, List<MemberMappingDescriptor>> aggregateGroups = new Dictionary<string, List<MemberMappingDescriptor>>();
            List<CodeStatement> statements = new List<CodeStatement>(20);
            foreach (MemberMappingDescriptor member in descriptor.MemberDescriptors)
            {
                if (member.IsAggregateExpression)
                {
                    // group all agregates by expression to avoid multiple traversals over same path
                    //string path = GetPath(member.Expression);
                    string path = GetPath(descriptor, member);
                    if(!aggregateGroups.ContainsKey(path))
                        aggregateGroups[path] = new List<MemberMappingDescriptor>(1);
                    aggregateGroups[path].Add(member);
                }
                else
                {
                    CodeStatement[] st = CreateNonAggregateMappingStatements(descriptor, member, context);
                    if(member.HasNullValue)
                    {
                        CodeStatement[] falseStatements = st;
                        CodeStatement[] trueStatements = new CodeStatement[1];
                        trueStatements[0] = new CodeAssignStatement(
                            new CodeVariableReferenceExpression("target." + member.Member),
                            new CodeSnippetExpression(member.NullValue.ToString()));

                        string checkExpression = GetNullablePartsCheckExpression(member);
                        CodeExpression ifExpression = new CodeSnippetExpression(checkExpression);

                        st = new CodeStatement[1];
                        st[0] = new CodeConditionStatement(ifExpression, trueStatements, falseStatements);
                    }
                    statements.AddRange(st);
                }
            }

            foreach (List<MemberMappingDescriptor> group in aggregateGroups.Values)
            {
                    CodeStatement[] st = CreateAggregateMappingStatements(descriptor, group, context);
                    statements.AddRange(st);
            }

            return statements.ToArray();
        }
开发者ID:varunkumarmnnit,项目名称:otis-lib,代码行数:44,代码来源:FunctionMappingGenerator.cs


示例18: CreateTransformMethod

        internal static CodeMemberMethod CreateTransformMethod(bool withNullParameter)
        {
            CodeMemberMethod method = new CodeMemberMethod();
            method.Name = "Transform<T,S>";
            method.ReturnType = new CodeTypeReference("T");

            // this parameter is only neede for the compiler to deduce the type parameter
            // it is not used inside the function
            method.Parameters.Add(new CodeParameterDeclarationExpression("T", "target"));
            method.Parameters[0].Direction = FieldDirection.In;

            method.Parameters.Add(new CodeParameterDeclarationExpression("S", "source"));
            method.Parameters[1].Direction = FieldDirection.In;

            if (withNullParameter)
            {
                method.Parameters.Add(new CodeParameterDeclarationExpression("T", "nullValue"));
                method.Parameters[2].Direction = FieldDirection.In;
            }

            AddNullHandling(method, withNullParameter, true);

            CodeStatement[] statements = new CodeStatement[3];
            statements[0] = new CodeVariableDeclarationStatement("IAssembler<T, S>", "converter",
                                                                      new CodeSnippetExpression("this as IAssembler<T, S>"));

            statements[1] = new CodeConditionStatement(
                new CodeBinaryOperatorExpression(
                    new CodeSnippetExpression("converter"),
                    CodeBinaryOperatorType.ValueEquality,
                    new CodeSnippetExpression("null")),
                new CodeStatement[]{
                                   	new CodeVariableDeclarationStatement(typeof(string), "msg",
                                   	                                     new CodeSnippetExpression("string.Format(\"Assembler for transformation [{0} -> {1}] is not configured\", typeof(S).FullName, typeof(T).FullName)")),
                                   	new CodeThrowExceptionStatement(new CodeSnippetExpression("new OtisException(msg)"))
                                   },
                new CodeStatement[0]
                );

            statements[2] = CreateReturnStatement("converter.AssembleFrom(source)");
            method.Statements.AddRange(statements);
            return method;
        }
开发者ID:varunkumarmnnit,项目名称:otis-lib,代码行数:43,代码来源:Util.cs


示例19: CreateNullHandlingStatement

        internal static CodeStatement CreateNullHandlingStatement(bool replaceNullValue, bool hasReturnType, bool useNullInsteadOfDefault)
        {
            string retValue = "";
            CodeStatement[] trueStatements = new CodeStatement[1];
            if(hasReturnType)
            {
                retValue = replaceNullValue ? "nullValue" : (useNullInsteadOfDefault ? "null" : "default(T)");
            }

            trueStatements[0] = CreateReturnStatement(retValue);

            CodeExpression ifExpression = new CodeBinaryOperatorExpression(
                new CodeSnippetExpression("source"),
                CodeBinaryOperatorType.ValueEquality,
                new CodeSnippetExpression("null"));
            CodeConditionStatement st = new CodeConditionStatement(ifExpression, trueStatements, new CodeStatement[0]);

            return st;
        }
开发者ID:varunkumarmnnit,项目名称:otis-lib,代码行数:19,代码来源:Util.cs


示例20: EmitConditionStatement

        private void EmitConditionStatement(CodeConditionStatement Condition)
        {
            Label False = Generator.DefineLabel();
            Label End = Generator.DefineLabel();

            // TODO: emitting condition statements could probably be done more efficiently
            EmitExpression(Condition.Condition);
            Generator.Emit(OpCodes.Ldc_I4_0);
            Generator.Emit(OpCodes.Beq, False);

            // Execute code for true and jump to end
            EmitStatementCollection(Condition.TrueStatements);
            Generator.Emit(OpCodes.Br, End);

            // Execute code for false and move on
            Generator.MarkLabel(False);
            EmitStatementCollection(Condition.FalseStatements);

            Generator.MarkLabel(End);
        }
开发者ID:Tyelpion,项目名称:IronAHK,代码行数:20,代码来源:EmitFlow.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# CodeDom.CodeConstructor类代码示例发布时间:2022-05-26
下一篇:
C# CodeDom.CodeCompileUnit类代码示例发布时间: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