本文整理汇总了C#中System.CodeDom.CodeStatement.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# CodeStatement.GetType方法的具体用法?C# CodeStatement.GetType怎么用?C# CodeStatement.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.CodeDom.CodeStatement
的用法示例。
在下文中一共展示了CodeStatement.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStatement
private static RuleCodeDomStatement GetStatement(CodeStatement statement)
{
Type type = statement.GetType();
if (type == typeof(CodeExpressionStatement))
{
return ExpressionStatement.Create(statement);
}
if (type == typeof(CodeAssignStatement))
{
return AssignmentStatement.Create(statement);
}
NotSupportedException exception = new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Messages.CodeStatementNotHandled, new object[] { statement.GetType().FullName }));
exception.Data["ErrorObject"] = statement;
throw exception;
}
示例2: Match
internal static bool Match(CodeStatement firstStatement, CodeStatement secondStatement)
{
if ((firstStatement == null) && (secondStatement == null))
{
return true;
}
if ((firstStatement == null) || (secondStatement == null))
{
return false;
}
if (firstStatement.GetType() != secondStatement.GetType())
{
return false;
}
return GetStatement(firstStatement).Match(secondStatement);
}
示例3: EmitStatement
void EmitStatement(CodeStatement Statement, bool ForceTypes)
{
if(Statement == null) return;
Depth++;
Debug("Emitting statement");
if(Statement is CodeAssignStatement)
{
EmitAssignStatement(Statement as CodeAssignStatement, ForceTypes);
}
else if(Statement is CodeExpressionStatement)
{
EmitExpressionStatement(Statement as CodeExpressionStatement, ForceTypes);
}
else if(Statement is CodeIterationStatement)
{
EmitIterationStatement(Statement as CodeIterationStatement);
}
else if(Statement is CodeConditionStatement)
{
EmitConditionStatement(Statement as CodeConditionStatement);
}
else if(Statement is CodeGotoStatement)
{
EmitGotoStatement(Statement as CodeGotoStatement);
}
else if(Statement is CodeLabeledStatement)
{
EmitLabeledStatement(Statement as CodeLabeledStatement);
}
else if(Statement is CodeMethodReturnStatement)
{
EmitReturnStatement(Statement as CodeMethodReturnStatement);
}
else if(Statement is CodeVariableDeclarationStatement)
{
EmitVariableDeclarationStatement(Statement as CodeVariableDeclarationStatement);
}
else
{
Depth++;
Debug("Unhandled statement: "+Statement.GetType());
Depth--;
}
Depth--;
}
示例4: EmitStatement
private void EmitStatement(CodeStatement statement)
{
if (statement is CodeAssignStatement)
EmitAssignment((CodeAssignStatement) statement);
else if (statement is CodeExpressionStatement)
EmitExpressionStatement(((CodeExpressionStatement) statement).Expression);
else if (statement is CodeIterationStatement)
EmitIteration((CodeIterationStatement) statement);
else if (statement is CodeConditionStatement)
EmitConditionStatement((CodeConditionStatement) statement);
else if (statement is CodeGotoStatement)
EmitGoto((CodeGotoStatement) statement);
else if (statement is CodeLabeledStatement)
EmitLabel((CodeLabeledStatement) statement);
else if (statement is CodeMethodReturnStatement)
EmitReturn((CodeMethodReturnStatement) statement);
else if (statement is CodeVariableDeclarationStatement)
EmitVariableDeclaration((CodeVariableDeclarationStatement) statement);
else if (statement is CodeCommentStatement)
EmitComment((CodeCommentStatement) statement);
else
throw new ArgumentException("Unrecognised statement: " + statement.GetType());
}
示例5: GenerateStatement
/// <devdoc>
/// <para>
/// Generates code for
/// the specified CodeDom based statement representation.
/// </para>
/// </devdoc>
private void GenerateStatement(CodeStatement e) {
if (e.StartDirectives.Count > 0) {
GenerateDirectives(e.StartDirectives);
}
if (e.LinePragma != null) {
GenerateLinePragmaStart(e.LinePragma);
}
if (e is CodeCommentStatement) {
GenerateCommentStatement((CodeCommentStatement)e);
}
else if (e is CodeMethodReturnStatement) {
GenerateMethodReturnStatement((CodeMethodReturnStatement)e);
}
else if (e is CodeConditionStatement) {
GenerateConditionStatement((CodeConditionStatement)e);
}
else if (e is CodeTryCatchFinallyStatement) {
GenerateTryCatchFinallyStatement((CodeTryCatchFinallyStatement)e);
}
else if (e is CodeAssignStatement) {
GenerateAssignStatement((CodeAssignStatement)e);
}
else if (e is CodeExpressionStatement) {
GenerateExpressionStatement((CodeExpressionStatement)e);
}
else if (e is CodeIterationStatement) {
GenerateIterationStatement((CodeIterationStatement)e);
}
else if (e is CodeThrowExceptionStatement) {
GenerateThrowExceptionStatement((CodeThrowExceptionStatement)e);
}
else if (e is CodeSnippetStatement) {
// Don't indent snippet statements, in order to preserve the column
// information from the original code. This improves the debugging
// experience.
int savedIndent = Indent;
Indent=0;
GenerateSnippetStatement((CodeSnippetStatement)e);
// Restore the indent
Indent=savedIndent;
}
else if (e is CodeVariableDeclarationStatement) {
GenerateVariableDeclarationStatement((CodeVariableDeclarationStatement)e);
}
else if (e is CodeAttachEventStatement) {
GenerateAttachEventStatement((CodeAttachEventStatement)e);
}
else if (e is CodeRemoveEventStatement) {
GenerateRemoveEventStatement((CodeRemoveEventStatement)e);
}
else if (e is CodeGotoStatement) {
GenerateGotoStatement((CodeGotoStatement)e);
}
else if (e is CodeLabeledStatement) {
GenerateLabeledStatement((CodeLabeledStatement)e);
}
else {
throw new ArgumentException(SR.GetString(SR.InvalidElementType, e.GetType().FullName), "e");
}
if (e.LinePragma != null) {
GenerateLinePragmaEnd(e.LinePragma);
}
if (e.EndDirectives.Count > 0) {
GenerateDirectives(e.EndDirectives);
}
}
示例6: ValidateStatement
private void ValidateStatement(CodeStatement e) {
ValidateCodeDirectives(e.StartDirectives);
ValidateCodeDirectives(e.EndDirectives);
if (e is CodeCommentStatement) {
ValidateCommentStatement((CodeCommentStatement)e);
}
else if (e is CodeMethodReturnStatement) {
ValidateMethodReturnStatement((CodeMethodReturnStatement)e);
}
else if (e is CodeConditionStatement) {
ValidateConditionStatement((CodeConditionStatement)e);
}
else if (e is CodeTryCatchFinallyStatement) {
ValidateTryCatchFinallyStatement((CodeTryCatchFinallyStatement)e);
}
else if (e is CodeAssignStatement) {
ValidateAssignStatement((CodeAssignStatement)e);
}
else if (e is CodeExpressionStatement) {
ValidateExpressionStatement((CodeExpressionStatement)e);
}
else if (e is CodeIterationStatement) {
ValidateIterationStatement((CodeIterationStatement)e);
}
else if (e is CodeThrowExceptionStatement) {
ValidateThrowExceptionStatement((CodeThrowExceptionStatement)e);
}
else if (e is CodeSnippetStatement) {
ValidateSnippetStatement((CodeSnippetStatement)e);
}
else if (e is CodeVariableDeclarationStatement) {
ValidateVariableDeclarationStatement((CodeVariableDeclarationStatement)e);
}
else if (e is CodeAttachEventStatement) {
ValidateAttachEventStatement((CodeAttachEventStatement)e);
}
else if (e is CodeRemoveEventStatement) {
ValidateRemoveEventStatement((CodeRemoveEventStatement)e);
}
else if (e is CodeGotoStatement) {
ValidateGotoStatement((CodeGotoStatement)e);
}
else if (e is CodeLabeledStatement) {
ValidateLabeledStatement((CodeLabeledStatement)e);
}
else {
throw new ArgumentException(SR.GetString(SR.InvalidElementType, e.GetType().FullName), "e");
}
}
示例7: AppendStatement
void AppendStatement(CodeStatement statement)
{
if (statement is CodeExpressionStatement) {
AppendExpressionStatement((CodeExpressionStatement)statement);
} else if (statement is CodeCommentStatement) {
AppendCommentStatement((CodeCommentStatement)statement);
} else if (statement is CodeAssignStatement) {
AppendAssignStatement((CodeAssignStatement)statement);
} else if (statement is CodeVariableDeclarationStatement) {
AppendVariableDeclarationStatement((CodeVariableDeclarationStatement)statement);
} else if (statement is CodeAttachEventStatement) {
AppendAttachEventStatement((CodeAttachEventStatement)statement);
} else {
Console.WriteLine("AppendStatement: " + statement.GetType().Name);
}
}
示例8: Match
internal static bool Match(CodeStatement firstStatement, CodeStatement secondStatement)
{
// If they're both null, they match.
if (firstStatement == null && secondStatement == null)
return true;
// If only one of them is null, there's no match.
if (firstStatement == null || secondStatement == null)
return false;
if (firstStatement.GetType() != secondStatement.GetType())
return false;
RuleCodeDomStatement ruleStmt = GetStatement(firstStatement);
return ruleStmt.Match(secondStatement);
}
示例9: RefactorMethodNamesInStatement
private void RefactorMethodNamesInStatement(CodeStatement statement, string newName)
{
if (typeof(CodeVariableDeclarationStatement) == statement.GetType())
{
CodeVariableDeclarationStatement vdeclStatement = (CodeVariableDeclarationStatement)statement;
if (vdeclStatement.InitExpression != null)
{
if (typeof(CodeCastExpression) == vdeclStatement.InitExpression.GetType())
{
CodeCastExpression castExp = (CodeCastExpression)vdeclStatement.InitExpression;
if (typeof(CodeMethodInvokeExpression) == castExp.Expression.GetType())
{
CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)castExp.Expression;
miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
}
}
else if (typeof(CodeMethodInvokeExpression) == vdeclStatement.InitExpression.GetType())
{
CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)vdeclStatement.InitExpression;
miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
}
}
}
else if (typeof(CodeExpressionStatement) == statement.GetType())
{
CodeExpressionStatement ceStatement = (CodeExpressionStatement)statement;
if (typeof(CodeMethodInvokeExpression) == ceStatement.Expression.GetType())
{
CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)ceStatement.Expression;
miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
}
}
else if (typeof(CodeAssignStatement) == statement.GetType())
{
CodeAssignStatement asnStatement = (CodeAssignStatement)statement;
if (typeof(CodeCastExpression) == asnStatement.Right.GetType())
{
CodeCastExpression castExp = (CodeCastExpression)asnStatement.Right;
if (typeof(CodeMethodInvokeExpression) == castExp.Expression.GetType())
{
CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)castExp.Expression;
miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
}
}
else if (typeof(CodeMethodInvokeExpression) == asnStatement.Right.GetType())
{
CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)asnStatement.Right;
miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
}
}
else if (typeof(CodeMethodReturnStatement) == statement.GetType())
{
CodeMethodReturnStatement retStatement = (CodeMethodReturnStatement)statement;
if (typeof(CodeMethodInvokeExpression) == retStatement.Expression.GetType())
{
CodeMethodInvokeExpression miExp = (CodeMethodInvokeExpression)retStatement.Expression;
miExp.Method.MethodName = PascalCaseConverterHelper.GetPascalCaseMethodName(miExp.Method.MethodName);
}
}
}
示例10: VisitCodeStatement
void VisitCodeStatement(CodeStatement statement)
{
WriteLine("VisitCodeStatement: " + statement.GetType().Name);
CodeVariableDeclarationStatement codeVariableDeclarationStatement = statement as CodeVariableDeclarationStatement;
CodeAssignStatement codeAssignStatement = statement as CodeAssignStatement;
CodeConditionStatement codeConditionStatement = statement as CodeConditionStatement;
CodeIterationStatement codeIterationStatement = statement as CodeIterationStatement;
CodeExpressionStatement codeExpressionStatement = statement as CodeExpressionStatement;
CodeTryCatchFinallyStatement codeTryCatchFinallyStatement = statement as CodeTryCatchFinallyStatement;
if (codeVariableDeclarationStatement != null) {
VisitCodeVariableDeclarationStatement(codeVariableDeclarationStatement);
} else if (codeAssignStatement != null) {
VisitCodeAssignStatement(codeAssignStatement);
} else if (codeConditionStatement != null) {
VisitCodeConditionStatement(codeConditionStatement);
} else if (codeIterationStatement != null) {
VisitCodeIterationStatement(codeIterationStatement);
} else if (codeExpressionStatement != null) {
VisitCodeExpressionStatement(codeExpressionStatement);
} else if (codeTryCatchFinallyStatement != null) {
VisitCodeTryCatchFinallyStatement(codeTryCatchFinallyStatement);
} else {
WriteLine("Unhandled statement: " + statement.GetType().Name);
}
}
示例11: GenerateStatement
private void GenerateStatement(CodeStatement e)
{
if (e.StartDirectives.Count > 0)
{
this.GenerateDirectives(e.StartDirectives);
}
if (e.LinePragma != null)
{
this.GenerateLinePragmaStart(e.LinePragma);
}
if (e is CodeCommentStatement)
{
this.GenerateCommentStatement((CodeCommentStatement) e);
}
else if (e is CodeMethodReturnStatement)
{
this.GenerateMethodReturnStatement((CodeMethodReturnStatement) e);
}
else if (e is CodeConditionStatement)
{
this.GenerateConditionStatement((CodeConditionStatement) e);
}
else if (e is CodeTryCatchFinallyStatement)
{
this.GenerateTryCatchFinallyStatement((CodeTryCatchFinallyStatement) e);
}
else if (e is CodeAssignStatement)
{
this.GenerateAssignStatement((CodeAssignStatement) e);
}
else if (e is CodeExpressionStatement)
{
this.GenerateExpressionStatement((CodeExpressionStatement) e);
}
else if (e is CodeIterationStatement)
{
this.GenerateIterationStatement((CodeIterationStatement) e);
}
else if (e is CodeThrowExceptionStatement)
{
this.GenerateThrowExceptionStatement((CodeThrowExceptionStatement) e);
}
else if (e is CodeSnippetStatement)
{
int num1 = this.Indent;
this.Indent = 0;
this.GenerateSnippetStatement((CodeSnippetStatement) e);
this.Indent = num1;
}
else if (e is CodeVariableDeclarationStatement)
{
this.GenerateVariableDeclarationStatement((CodeVariableDeclarationStatement) e);
}
else if (e is CodeAttachEventStatement)
{
this.GenerateAttachEventStatement((CodeAttachEventStatement) e);
}
else if (e is CodeRemoveEventStatement)
{
this.GenerateRemoveEventStatement((CodeRemoveEventStatement) e);
}
else if (e is CodeGotoStatement)
{
this.GenerateGotoStatement((CodeGotoStatement) e);
}
else
{
if (!(e is CodeLabeledStatement))
{
throw new ArgumentException("InvalidElementType" + e, e.GetType().FullName );
}
this.GenerateLabeledStatement((CodeLabeledStatement) e);
}
if (e.LinePragma != null)
{
this.GenerateLinePragmaEnd(e.LinePragma);
}
if (e.EndDirectives.Count > 0)
{
this.GenerateDirectives(e.EndDirectives);
}
}
示例12: GenerateStatement
/// <include file='doc\CodeGenerator.uex' path='docs/doc[@for="CodeGenerator.GenerateStatement"]/*' />
/// <devdoc>
/// <para>
/// Generates code for
/// the specified CodeDom based statement representation.
/// </para>
/// </devdoc>
protected void GenerateStatement(CodeStatement e) {
if (e.LinePragma != null) {
GenerateLinePragmaStart(e.LinePragma);
}
if (e is CodeCommentStatement) {
GenerateCommentStatement((CodeCommentStatement)e);
}
else if (e is CodeMethodReturnStatement) {
GenerateMethodReturnStatement((CodeMethodReturnStatement)e);
}
else if (e is CodeConditionStatement) {
GenerateConditionStatement((CodeConditionStatement)e);
}
else if (e is CodeTryCatchFinallyStatement) {
GenerateTryCatchFinallyStatement((CodeTryCatchFinallyStatement)e);
}
else if (e is CodeAssignStatement) {
GenerateAssignStatement((CodeAssignStatement)e);
}
else if (e is CodeExpressionStatement) {
GenerateExpressionStatement((CodeExpressionStatement)e);
}
else if (e is CodeIterationStatement) {
GenerateIterationStatement((CodeIterationStatement)e);
}
else if (e is CodeThrowExceptionStatement) {
GenerateThrowExceptionStatement((CodeThrowExceptionStatement)e);
}
else if (e is CodeSnippetStatement) {
GenerateSnippetStatement((CodeSnippetStatement)e);
}
else if (e is CodeVariableDeclarationStatement) {
GenerateVariableDeclarationStatement((CodeVariableDeclarationStatement)e);
}
else if (e is CodeAttachEventStatement) {
GenerateAttachEventStatement((CodeAttachEventStatement)e);
}
else if (e is CodeRemoveEventStatement) {
GenerateRemoveEventStatement((CodeRemoveEventStatement)e);
}
else if (e is CodeGotoStatement) {
GenerateGotoStatement((CodeGotoStatement)e);
}
else if (e is CodeLabeledStatement) {
GenerateLabeledStatement((CodeLabeledStatement)e);
}
else {
throw new ArgumentException(SR.GetString(SR.InvalidElementType, e.GetType().FullName), "e");
}
if (e.LinePragma != null) {
GenerateLinePragmaEnd(e.LinePragma);
}
}
示例13: Translate
private Statement Translate(CodeStatement statement){
if (statement == null) return null;
if (statement is CodeAssignStatement) return this.Translate((CodeAssignStatement)statement);
if (statement is CodeAttachEventStatement) return this.Translate((CodeAttachEventStatement)statement);
if (statement is CodeCommentStatement) return this.Translate((CodeCommentStatement)statement);
if (statement is CodeConditionStatement) return this.Translate((CodeConditionStatement)statement);
if (statement is CodeExpressionStatement) return this.Translate((CodeExpressionStatement)statement);
if (statement is CodeGotoStatement) return this.Translate((CodeGotoStatement)statement);
if (statement is CodeIterationStatement) return this.Translate((CodeIterationStatement)statement);
if (statement is CodeLabeledStatement) return this.Translate((CodeLabeledStatement)statement);
if (statement is CodeMethodReturnStatement) return this.Translate((CodeMethodReturnStatement)statement);
if (statement is CodeRemoveEventStatement) return this.Translate((CodeRemoveEventStatement)statement);
if (statement is CodeSnippetStatement) return this.Translate((CodeSnippetStatement)statement);
if (statement is CodeThrowExceptionStatement) return this.Translate((CodeThrowExceptionStatement)statement);
if (statement is CodeTryCatchFinallyStatement) return this.Translate((CodeTryCatchFinallyStatement)statement);
if (statement is CodeVariableDeclarationStatement) return this.Translate((CodeVariableDeclarationStatement)statement);
throw new ArgumentException("unknown statement", statement.GetType().FullName);
}
示例14: GetCodeTypeReferenceInCodeStatement
private CodeTypeReferenceCollection GetCodeTypeReferenceInCodeStatement(CodeStatement statement)
{
CodeTypeReferenceCollection references = new CodeTypeReferenceCollection();
// Is this a variable declaration statement?
if (typeof(CodeVariableDeclarationStatement) == statement.GetType())
{
// Add CodeTypeReference used to define the type of the variable to output.
CodeVariableDeclarationStatement vdeclStatement = (CodeVariableDeclarationStatement)statement;
references.Add(vdeclStatement.Type);
// Do we have an initialization expression?
if (vdeclStatement.InitExpression != null)
{
// Add CodeTypeReference in the initialization statement if available.
CodeTypeReference r = GetCodeTypeReferenceInCodeExpression(vdeclStatement.InitExpression);
Debug.Assert(r != null, "Could not obtain a proper CodeTypeReference from the variable initialization expression.");
if (r == null)
{
Debugger.Break();
}
references.Add(r);
}
}
//// Is this a return statement?
//else if (typeof(CodeMethodReturnStatement) == statement.GetType())
//{
// CodeMethodReturnStatement retStatement = (CodeMethodReturnStatement)statement;
// // Add CodeTypeReference in the return statement if available.
// CodeTypeReference r = GetCodeTypeReferenceInCodeExpression(retStatement.Expression);
// Debug.Assert(r != null, "Could not obtain a proper CodeTypeReference from the variable initialization expression.");
// references.Add(r);
//}
// Finally return the references.
return references;
}
示例15: PrintStatement
private static void PrintStatement(TextWriter output, CodeStatement statement)
{
if (statement is CodeVariableDeclarationStatement)
{
PrintVariableDeclarationStatement(output, (CodeVariableDeclarationStatement)statement);
return;
}
if (statement is CodeExpressionStatement)
{
PrintExpressionStatement(output, (CodeExpressionStatement)statement);
return;
}
if (statement is CodeMethodReturnStatement)
{
PrintMethodReturnStatement(output, (CodeMethodReturnStatement)statement);
return;
}
if (statement is CodeAssignStatement)
{
PrintAssignStatement(output, (CodeAssignStatement)statement);
return;
}
if (statement is CodeThrowExceptionStatement)
{
PrintThrowExceptionStatement(output, (CodeThrowExceptionStatement)statement);
return;
}
if (statement is CodeConditionStatement)
{
PrintConditionStatement(output, (CodeConditionStatement)statement);
return;
}
if (statement is CodeCommentStatement)
{
PrintCommentStatement(output, (CodeCommentStatement)statement);
return;
}
output.WriteLine("*** UNKNOWN STATEMENT: " + statement.GetType() + " ***");
}