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


C# CodeDom.CodeThrowExceptionStatement类代码示例

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


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

示例1: Constructor1_Deny_Unrestricted

		public void Constructor1_Deny_Unrestricted ()
		{
			CodeExpression to_throw = new CodeExpression ();
			CodeThrowExceptionStatement ctes = new CodeThrowExceptionStatement (to_throw);
			Assert.AreSame (to_throw, ctes.ToThrow, "ToThrow");
			ctes.ToThrow = new CodeExpression ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:CodeThrowExceptionStatementCas.cs

示例2: Inspect

        /// <summary>
        /// Inspects the specified code unit.
        /// </summary>
        /// <param name="unit">The code unit.</param>
        /// <param name="ns">The code namespace declaration.</param>
        /// <param name="type">The code type declaration.</param>
        /// <param name="executeMethod">The code method declaration for the Execute method.</param>
        public void Inspect(CodeCompileUnit unit, CodeNamespace ns, CodeTypeDeclaration type, CodeMemberMethod executeMethod)
        {
            var statement = new CodeThrowExceptionStatement(
                new CodeObjectCreateExpression(
                    new CodeTypeReference(typeof(System.InvalidOperationException)), new CodeExpression[] {}));

            executeMethod.Statements.Insert(0, statement);
        }
开发者ID:MatthewSJones,项目名称:RazorEngine,代码行数:15,代码来源:ThrowExceptionCodeInspector.cs

示例3: Emit

        // Generate a codedom throw statement
        public static CodeStatement Emit(Throw th)
        {
            var codeThrow = new CodeThrowExceptionStatement();

            codeThrow.ToThrow = CodeDomEmitter.EmitCodeExpression(th.ChildExpressions[0]);

            return codeThrow;
        }
开发者ID:maleficus1234,项目名称:Pie,代码行数:9,代码来源:ExceptionHandlerEmitter.cs

示例4: TypescriptThrowExceptionStatement

 public TypescriptThrowExceptionStatement(
     IExpressionFactory expressionFactory,
     CodeThrowExceptionStatement statement,
     CodeGeneratorOptions options)
 {
     _expressionFactory = expressionFactory;
     _statement = statement;
     _options = options;
 }
开发者ID:s2quake,项目名称:TypescriptCodeDom,代码行数:9,代码来源:TypescriptThrowExceptionStatement.cs

示例5: Clone

 public static CodeThrowExceptionStatement Clone(this CodeThrowExceptionStatement statement)
 {
     if (statement == null) return null;
     CodeThrowExceptionStatement s = new CodeThrowExceptionStatement();
     s.EndDirectives.AddRange(statement.EndDirectives);
     s.LinePragma = statement.LinePragma;
     s.StartDirectives.AddRange(statement.StartDirectives);
     s.ToThrow = statement.ToThrow.Clone();
     s.UserData.AddRange(statement.UserData);
     return s;
 }
开发者ID:mgagne-atman,项目名称:Projects,代码行数:11,代码来源:CodeThrowExceptionStatementExtensions.cs

示例6: GenerateExceptionStatement

        private CodeThrowExceptionStatement GenerateExceptionStatement(GenerateErrorActivity activity)
        {
            var parameters = DefaultActivityBuilder.GenerateParameters(new List<string> {
                @"""Message : {0}\nMessage code : {1} """
            }, activity);

            CodeMethodInvokeExpression stringFormatCall = new CodeMethodInvokeExpression();
            stringFormatCall.Parameters.AddRange(parameters);

            CodeMethodReferenceExpression formatMethod = new CodeMethodReferenceExpression();
            formatMethod.MethodName = "Format";
            CodeVariableReferenceExpression stringObject = new CodeVariableReferenceExpression();
            stringObject.VariableName = "String";
            formatMethod.TargetObject = stringObject;
            stringFormatCall.Method = formatMethod;
            CodeThrowExceptionStatement throwException = new CodeThrowExceptionStatement(new CodeObjectCreateExpression(new CodeTypeReference(typeof(System.Exception)), stringFormatCall));
            return throwException;
        }
开发者ID:swoog,项目名称:EaiConverter,代码行数:18,代码来源:GenerateErrorActivityBuilder.cs

示例7: EmitCodeToAddIntoCustomStdBinding

        internal static void EmitCodeToAddIntoCustomStdBinding(Type standardBindingType, string generatedElementClassName, string generatedCollectionElementClassName, string srcFile)
        {
            CodeMemberMethod applyCfgMethodForStdBinding = new CodeMemberMethod();
            applyCfgMethodForStdBinding.Name = MethodNameConstants.ApplyConfigurationMethod;

            string paramConfigName = "configurationName";
            CodeVariableReferenceExpression paramVarRef = new CodeVariableReferenceExpression(paramConfigName);

            applyCfgMethodForStdBinding.Parameters.Add(new CodeParameterDeclarationExpression(
                                                          CodeDomHelperObjects.stringTypeRef,
                                                          paramConfigName));

            string bindingsString = "bindings";
            CodeVariableReferenceExpression bindingsVarRef = new CodeVariableReferenceExpression(bindingsString);

            string sectionString = "section";
            CodeVariableReferenceExpression sectionVarRef = new CodeVariableReferenceExpression(sectionString);

            string elementString = "element";
            CodeVariableReferenceExpression elementVarRef = new CodeVariableReferenceExpression(elementString);

            string topLevelSectionNameInConfig = "system.serviceModel/bindings/";
            string subSectionNameInConfig = Helpers.TurnFirstCharLower(standardBindingType.Name);

            CodeVariableDeclarationStatement bindingsInit = new CodeVariableDeclarationStatement(
                                                            new CodeTypeReference(TypeNameConstants.BindingsSection),
                                                            bindingsString,
                                                            new CodeCastExpression(TypeNameConstants.BindingsSection,
                                                                new CodeMethodInvokeExpression(
                                                                    new CodeTypeReferenceExpression(TypeNameConstants.ConfigurationManager),
                                                                    MethodNameConstants.GetSectionMethod,
                                                                    new CodePrimitiveExpression(topLevelSectionNameInConfig))));
            applyCfgMethodForStdBinding.Statements.Add(bindingsInit);

            CodeVariableDeclarationStatement sectionInit = new CodeVariableDeclarationStatement(
                                                            new CodeTypeReference(generatedCollectionElementClassName),
                                                            sectionString,
                                                            new CodeCastExpression(generatedCollectionElementClassName,
                                                                new CodeArrayIndexerExpression(
                                                                    bindingsVarRef,
                                                                    new CodePrimitiveExpression(subSectionNameInConfig))));
            applyCfgMethodForStdBinding.Statements.Add(sectionInit);

            CodeVariableDeclarationStatement elementInit = new CodeVariableDeclarationStatement(
                                                new CodeTypeReference(generatedElementClassName),
                                                elementString,
                                                new CodeArrayIndexerExpression(
                                                    new CodeFieldReferenceExpression(
                                                        sectionVarRef,
                                                        PropertyNameConstants.BindingsProperty),
                                                    paramVarRef));
            applyCfgMethodForStdBinding.Statements.Add(elementInit);

            CodeBinaryOperatorExpression cboe = new CodeBinaryOperatorExpression(
                                                    elementVarRef,
                                                    CodeBinaryOperatorType.IdentityEquality,
                                                    CodeDomHelperObjects.NullRef);

            CodeThrowExceptionStatement ctes = new CodeThrowExceptionStatement(
                        new CodeObjectCreateExpression(
                            new CodeTypeReference(typeof(ConfigurationErrorsException)),
                            new CodeMethodInvokeExpression(
                                new CodeTypeReferenceExpression(CodeDomHelperObjects.stringTypeRef),
                                MethodNameConstants.FormatMethod,
                                CodeDomHelperObjects.cultureInfoCurrent,
                                new CodePrimitiveExpression("There is no binding named {0} at {1}."),
                                paramVarRef,
                                new CodePropertyReferenceExpression(
                                    sectionVarRef, PropertyNameConstants.BindingNameProperty))));
            CodeMethodInvokeExpression cmie = new CodeMethodInvokeExpression(
                                                            elementVarRef,
                                                            MethodNameConstants.ApplyConfigurationMethod,
                                                            CodeDomHelperObjects.ThisRef);
            CodeStatement[] trueStatements = { ctes };
            CodeStatement[] falseStatements = { new CodeExpressionStatement(cmie) };
            CodeConditionStatement ccs = new CodeConditionStatement(cboe, trueStatements, falseStatements);
            applyCfgMethodForStdBinding.Statements.Add(ccs);

            string indent = "    ";
            CodeDomProvider provider = new Microsoft.CSharp.CSharpCodeProvider();

            using (System.IO.StreamWriter sbSW = new System.IO.StreamWriter(srcFile, false))
            {
                using (IndentedTextWriter sbTW = new IndentedTextWriter(sbSW, indent))
                {
                    provider.GenerateCodeFromMember(
                                    applyCfgMethodForStdBinding,
                                    sbTW,
                                    new CodeGeneratorOptions());
                }
            }
        }
开发者ID:ssickles,项目名称:archive,代码行数:92,代码来源:UserTypeCodeEnhancer.cs

示例8: ParseStatement

        public CodeStatement ParseStatement()
        {
            if (IsKeyword("var"))
            {
                GetNextToken();
                CodeTypeReference type = ParseType();
                string name = EatKeyword();
                if (TokenType == CDILToken.Assign)
                {
                    Expect(CDILToken.Assign);
                    CodeExpression expr = ParseExpression();
                    return new CodeVariableDeclarationStatement(type, name, expr);
                }
                else
                {
                    return new CodeVariableDeclarationStatement(type, name);
                }
            }
            if (IsKeyword("call"))
            {
                GetNextToken();
                return new CodeExpressionStatement(ParseExpression());
            }

            if (IsKeyword("return"))
            {
                CodeMethodReturnStatement retVal;

                GetNextToken();
                retVal = new CodeMethodReturnStatement();
                if (TokenType != CDILToken.Semicolon && TokenType != CDILToken.EOF)
                    retVal.Expression = ParseExpression();
                return retVal;
            }
            if (IsKeyword("throw"))
            {
                CodeThrowExceptionStatement retVal;

                GetNextToken();
                retVal = new CodeThrowExceptionStatement();
                if (TokenType != CDILToken.Semicolon && TokenType != CDILToken.EOF)
                    retVal.ToThrow = ParseExpression();
                return retVal;
            }
            if (IsKeyword("if"))
            {
                CodeConditionStatement retVal = new CodeConditionStatement();
                GetNextToken();
                retVal.Condition = ParseExpression();
                ExpectKeyword("then");
                while (TokenType != CDILToken.EOF && !IsKeyword("else") && !IsKeyword("endif"))
                {
                    retVal.TrueStatements.Add(ParseStatement());
                    if (TokenType == CDILToken.Semicolon)
                        GetNextToken();
                }
                if (IsKeyword("else"))
                {
                    ExpectKeyword("else");
                    while (TokenType != CDILToken.EOF && !IsKeyword("endif"))
                    {
                        retVal.FalseStatements.Add(ParseStatement());
                        if (TokenType == CDILToken.Semicolon)
                            GetNextToken();
                    }
                }
                ExpectKeyword("endif");
                return retVal;
            }
            if (IsKeyword("let"))
            {
                CodeAssignStatement retVal = new CodeAssignStatement();
                GetNextToken();
                retVal.Left = ParseExpression();
                Expect(CDILToken.Assign);
                retVal.Right = ParseExpression();
                return retVal;
            }
            if (IsKeyword("comment"))
            {
                GetNextToken();
                string s = TokenValue.ToString();
                GetNextToken();
                return new CodeCommentStatement(s);
            }
            throw BuildException("Invalid token: '" + TokenType + "': " + TokenValue);
        }
开发者ID:valery-shinkevich,项目名称:sooda,代码行数:87,代码来源:CDILParser.cs

示例9: Generate

 public void Generate(CodeThrowExceptionStatement statement)
 {
     Write("raise ");
     Generate(statement.ToThrow);
     WriteLine();
 }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:6,代码来源:RubyCodeGenerator.cs

示例10: GenerateConstructors

        private static void GenerateConstructors(Type t, CodeTypeDeclaration codeType)
        {
            CodeFieldReferenceExpression omObjectFieldReference = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), OmObject);

            ConstructorInfo[] constructors = t.GetConstructors();
            ConstructorInfo publicParameterless = null;
            ConstructorInfo publicSystemParams = null;
            ConstructorInfo publicEnumParams = null;
            List<ConstructorInfo> publicGeneralParams = new List<ConstructorInfo>();
            foreach (ConstructorInfo con in constructors.Where(c => c.IsPublic || c.IsStatic))
            {
                ParameterInfo[] parameters = con.GetParameters();
                if (parameters == null || parameters.Length == 0)
                {
                    publicParameterless = con;
                }
                else if (con.IsStatic)
                {
                }
                else
                {
                    publicGeneralParams.Add(con);
                }
            }

            if (publicParameterless != null)
            {
                CodeConstructor constructor = new CodeConstructor();
                constructor.Attributes = MemberAttributes.Public;
                CodeObjectCreateExpression createExpression = new CodeObjectCreateExpression(t);
                constructor.Statements.Add(new CodeAssignStatement(omObjectFieldReference, createExpression));
                codeType.Members.Add(constructor);
            }

            foreach (ConstructorInfo c in publicGeneralParams)
            {
                AddConstructorWithCopiedParameters(codeType, t, omObjectFieldReference, c);
            }

            // Default internal constructor that accepts the OM object to wrap
            CodeConstructor defaultConstructor = new CodeConstructor();
            defaultConstructor.Attributes = MemberAttributes.Assembly;
            CodeParameterDeclarationExpression omObjectParameter = new CodeParameterDeclarationExpression(t, OmObject);
            defaultConstructor.Parameters.Add(omObjectParameter);
            CodeArgumentReferenceExpression omObjectArgumentReference = new CodeArgumentReferenceExpression(OmObject);
            CodeObjectCreateExpression createException = new CodeObjectCreateExpression(typeof(ArgumentNullException), new CodePrimitiveExpression(OmObject));
            CodeThrowExceptionStatement throwException = new CodeThrowExceptionStatement(createException);
            CodeBinaryOperatorExpression nullCheck = new CodeBinaryOperatorExpression(omObjectArgumentReference, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null));

            // if the parameter is null, throw an exception
            defaultConstructor.Statements.Add(new CodeConditionStatement(nullCheck, throwException));

            defaultConstructor.Statements.Add(new CodeAssignStatement(omObjectFieldReference, omObjectArgumentReference));
            codeType.Members.Add(defaultConstructor);
        }
开发者ID:Azure,项目名称:azure-powershell,代码行数:55,代码来源:Program.cs

示例11: GenerateThrowExceptionStatement

 protected override void GenerateThrowExceptionStatement(CodeThrowExceptionStatement e)
 {
     base.Output.Write("Throw");
     if (e.ToThrow != null)
     {
         base.Output.Write(" ");
         base.GenerateExpression(e.ToThrow);
     }
     base.Output.WriteLine("");
 }
开发者ID:laymain,项目名称:CodeDomUtils,代码行数:10,代码来源:VBCodeGenerator.cs

示例12: GenerateThrowExceptionStatement

		protected override void GenerateThrowExceptionStatement (CodeThrowExceptionStatement statement)
		{
			Output.Write ("Throw");
			if (statement.ToThrow != null) {
				Output.Write (' ');
				GenerateExpression (statement.ToThrow);
			}
			Output.WriteLine ();
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:VBCodeGenerator.cs

示例13: GenerateThrowExceptionStatement

		protected abstract void GenerateThrowExceptionStatement (CodeThrowExceptionStatement s);
开发者ID:carrie901,项目名称:mono,代码行数:1,代码来源:CodeGenerator.cs

示例14: CodeThrowExceptionStatementTest

		public void CodeThrowExceptionStatementTest ()
		{
			CodeThrowExceptionStatement ctes = new CodeThrowExceptionStatement ();
			statement = ctes;

			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"throw;{0}", NewLine), Generate (), "#1");

			ctes.ToThrow = new CodeSnippetExpression ("whatever");
			Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
				"throw whatever;{0}", NewLine), Generate (), "#2");
		}
开发者ID:zxlin25,项目名称:mono,代码行数:12,代码来源:CodeGeneratorFromStatementTest.cs

示例15: GenerateThrowExceptionStatement

        /// <summary>
        /// Generates code for the specified throw exception statement.
        /// </summary>
        /// <remarks><c>throw TOTHROW;</c></remarks>
        protected override void GenerateThrowExceptionStatement(CodeThrowExceptionStatement e)
        {
            Output.Write(Keywords.Throw + WhiteSpace.Space);
            GenerateExpression(e.ToThrow);

            Output.WriteLine(Tokens.Semicolon);
        }
开发者ID:jdluzen,项目名称:Phalanger,代码行数:11,代码来源:PhpGenerator.CLR.cs


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