本文整理汇总了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 ();
}
示例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);
}
示例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;
}
示例4: TypescriptThrowExceptionStatement
public TypescriptThrowExceptionStatement(
IExpressionFactory expressionFactory,
CodeThrowExceptionStatement statement,
CodeGeneratorOptions options)
{
_expressionFactory = expressionFactory;
_statement = statement;
_options = options;
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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);
}
示例9: Generate
public void Generate(CodeThrowExceptionStatement statement)
{
Write("raise ");
Generate(statement.ToThrow);
WriteLine();
}
示例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);
}
示例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("");
}
示例12: GenerateThrowExceptionStatement
protected override void GenerateThrowExceptionStatement (CodeThrowExceptionStatement statement)
{
Output.Write ("Throw");
if (statement.ToThrow != null) {
Output.Write (' ');
GenerateExpression (statement.ToThrow);
}
Output.WriteLine ();
}
示例13: GenerateThrowExceptionStatement
protected abstract void GenerateThrowExceptionStatement (CodeThrowExceptionStatement s);
示例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");
}
示例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);
}