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); } } }
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); } }
protected void GenerateStatement(CodeStatement e) { 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 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(string.Format(SR.InvalidElementType, e.GetType().FullName), nameof(e)); } }
protected void GenerateStatement(CodeStatement s) { #if NET_2_0 if (s.StartDirectives.Count > 0) { GenerateDirectives(s.StartDirectives); } #endif if (s.LinePragma != null) { GenerateLinePragmaStart(s.LinePragma); } CodeSnippetStatement snippet = s as CodeSnippetStatement; if (snippet != null) { #if NET_2_0 int indent = Indent; try { Indent = 0; GenerateSnippetStatement(snippet); } finally { Indent = indent; } #else GenerateSnippetStatement(snippet); #endif } else { try { s.Accept(visitor); } catch (NotImplementedException) { throw new ArgumentException("Element type " + s.GetType() + " is not supported.", "s"); } } if (s.LinePragma != null) { GenerateLinePragmaEnd(s.LinePragma); } #if NET_2_0 if (s.EndDirectives.Count > 0) { GenerateDirectives(s.EndDirectives); } #endif }
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); } }
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--; }
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)); }
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; }
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()); } }
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() + " ***"); }
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)); }
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); }
private static RuleCodeDomStatement GetStatement(CodeStatement statement) { Type statementType = statement.GetType(); RuleCodeDomStatement wrapper = null; if (statementType == typeof(CodeExpressionStatement)) { wrapper = ExpressionStatement.Create(statement); } else if (statementType == typeof(CodeAssignStatement)) { wrapper = AssignmentStatement.Create(statement); } else { string message = string.Format(CultureInfo.CurrentCulture, Messages.CodeStatementNotHandled, statement.GetType().FullName); NotSupportedException exception = new NotSupportedException(message); exception.Data[RuleUserDataKeys.ErrorObject] = statement; throw exception; } return(wrapper); }
protected 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.Format(SR.InvalidElementType, e.GetType().FullName), nameof(e)); } if (e.LinePragma != null) { GenerateLinePragmaEnd(e.LinePragma); } if (e.EndDirectives.Count > 0) { GenerateDirectives(e.EndDirectives); } }
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.Format(SR.InvalidElementType, e.GetType().FullName), nameof(e)); } }
private static void ProcessStmt(CodeStatement stmt, LinqToCodedom.CodeDomGenerator.Language language) { if (stmt == null) { return; } foreach (CodeDirective directive in stmt.StartDirectives) { ProcessDirective(directive, language); } foreach (CodeDirective directive in stmt.EndDirectives) { ProcessDirective(directive, language); } if (typeof(CodeAssignStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeAssignStatement)stmt).Left, language); ProcessExpr(((CodeAssignStatement)stmt).Right, language); } else if (typeof(CodeAttachEventStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeAttachEventStatement)stmt).Listener, language); } else if (typeof(CodeCommentStatement).IsAssignableFrom(stmt.GetType())) { } else if (typeof(CodeConditionStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeConditionStatement)stmt).Condition, language); ProcessStmt(((CodeConditionStatement)stmt).TrueStatements, language); ProcessStmt(((CodeConditionStatement)stmt).FalseStatements, language); } else if (typeof(CodeExpressionStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeExpressionStatement)stmt).Expression, language); } else if (typeof(CodeGotoStatement).IsAssignableFrom(stmt.GetType())) { } else if (typeof(CodeIterationStatement).IsAssignableFrom(stmt.GetType())) { ProcessStmt(((CodeIterationStatement)stmt).IncrementStatement, language); ProcessStmt(((CodeIterationStatement)stmt).InitStatement, language); ProcessStmt(((CodeIterationStatement)stmt).Statements, language); ProcessExpr(((CodeIterationStatement)stmt).TestExpression, language); } else if (typeof(CodeLabeledStatement).IsAssignableFrom(stmt.GetType())) { ProcessStmt(((CodeLabeledStatement)stmt).Statement, language); } else if (typeof(CodeMethodReturnStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeMethodReturnStatement)stmt).Expression, language); } else if (typeof(CodeRemoveEventStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeRemoveEventStatement)stmt).Listener, language); } else if (typeof(CodeThrowExceptionStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeThrowExceptionStatement)stmt).ToThrow, language); } else if (typeof(CodeTryCatchFinallyStatement).IsAssignableFrom(stmt.GetType())) { ProcessStmt(((CodeTryCatchFinallyStatement)stmt).FinallyStatements, language); ProcessStmt(((CodeTryCatchFinallyStatement)stmt).TryStatements, language); foreach (CodeCatchClause c in ((CodeTryCatchFinallyStatement)stmt).CatchClauses) { ProcessStmt(c.Statements, language); } } else if (typeof(CodeVariableDeclarationStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeVariableDeclarationStatement)stmt).InitExpression, language); } else if (typeof(CodeUsingStatement).IsAssignableFrom(stmt.GetType())) { ProcessStmt(((CodeUsingStatement)stmt).Statements, language); ProcessExpr(((CodeUsingStatement)stmt).UsingExpression, language); } else if (typeof(CodeForeachStatement).IsAssignableFrom(stmt.GetType())) { ProcessStmt(((CodeForeachStatement)stmt).Statements, language); ProcessExpr(((CodeForeachStatement)stmt).IterExpression, language); } else if (typeof(CodeDoStatement).IsAssignableFrom(stmt.GetType())) { ProcessStmt(((CodeDoStatement)stmt).Statements, language); ProcessExpr(((CodeDoStatement)stmt).TestExpression, language); } else if (typeof(CodeWhileStatement).IsAssignableFrom(stmt.GetType())) { ProcessStmt(((CodeWhileStatement)stmt).Statements, language); ProcessExpr(((CodeWhileStatement)stmt).TestExpression, language); } else if (typeof(CodeSwitchStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeSwitchStatement)stmt).SwitchExpression, language); foreach (CodeSwitchStatement.CaseBlock cb in ((CodeSwitchStatement)stmt).Cases) { ProcessExpr(cb.CaseExpression, language); ProcessStmt(cb.Statements, language); } } else if (typeof(CodeLockStatement).IsAssignableFrom(stmt.GetType())) { ProcessExpr(((CodeLockStatement)stmt).LockExpression, language); ProcessStmt(((CodeLockStatement)stmt).Statements, language); } ICustomCodeDomObject co = stmt as ICustomCodeDomObject; if (co != null) { co.GenerateCode(language); } }
public static void ReplaceType(this CodeStatement statement, string oldType, string newType) { if (statement == null) { return; } if (statement is CodeAssignStatement) { (statement as CodeAssignStatement).ReplaceType(oldType, newType); } else if (statement is CodeAttachEventStatement) { (statement as CodeAttachEventStatement).ReplaceType(oldType, newType); } else if (statement is CodeConditionStatement) { (statement as CodeConditionStatement).ReplaceType(oldType, newType); } else if (statement is CodeExpressionStatement) { (statement as CodeExpressionStatement).ReplaceType(oldType, newType); } else if (statement is CodeIterationStatement) { (statement as CodeIterationStatement).ReplaceType(oldType, newType); } else if (statement is CodeLabeledStatement) { (statement as CodeLabeledStatement).ReplaceType(oldType, newType); } else if (statement is CodeMethodReturnStatement) { (statement as CodeMethodReturnStatement).ReplaceType(oldType, newType); } else if (statement is CodeRemoveEventStatement) { (statement as CodeRemoveEventStatement).ReplaceType(oldType, newType); } else if (statement is CodeThrowExceptionStatement) { (statement as CodeThrowExceptionStatement).ReplaceType(oldType, newType); } else if (statement is CodeTryCatchFinallyStatement) { (statement as CodeTryCatchFinallyStatement).ReplaceType(oldType, newType); } else if (statement is CodeVariableDeclarationStatement) { (statement as CodeVariableDeclarationStatement).ReplaceType(oldType, newType); } // The following statements don't have any types to replace. else if (statement is CodeCommentStatement) { return; } else if (statement is CodeGotoStatement) { return; } else if (statement is CodeSnippetStatement) { return; } // Unknown statement types. else { throw new NotImplementedException("ReplaceType has not been implemented for statement of type: " + statement.GetType().FullName); } }
private static void DumpStatement(StreamWriter writer, CodeStatement s) { if (s.UserData.Count > 0) { dumpUserData(s.UserData); } /* * System.CodeDom.CodeAssignStatement * System.CodeDom.CodeAttachEventStatement * System.CodeDom.CodeCommentStatement * System.CodeDom.CodeConditionStatement * System.CodeDom.CodeExpressionStatement * System.CodeDom.CodeGotoStatement * System.CodeDom.CodeIterationStatement * System.CodeDom.CodeLabeledStatement * System.CodeDom.CodeMethodReturnStatement * System.CodeDom.CodeRemoveEventStatement * System.CodeDom.CodeSnippetStatement * System.CodeDom.CodeThrowExceptionStatement * System.CodeDom.CodeTryCatchFinallyStatement * System.CodeDom.CodeVariableDeclarationStatement */ _indent++; if (s is CodeAssignStatement) { var stmt = (CodeAssignStatement)s; if (stmt.Left != null) { dumpExpression(stmt.Left); } writeLineIndent(getExpression(stmt.Right)); if (stmt.Right != null) { dumpExpression(stmt.Right); } } else if (s is CodeExpressionStatement) { var stmt = (CodeExpressionStatement)s; writeLineIndent(stmt.Expression.GetType().ToString()); dumpExpression(stmt.Expression); } else if (s is CodeVariableDeclarationStatement) { var stmt = (CodeVariableDeclarationStatement)s; writeLineIndent(stmt.Name); var tr = stmt.Type; writeLineIndent(tr.BaseType); } else if (s is CodeAttachEventStatement) { var stmt = (CodeAttachEventStatement)s; dumpExpression(stmt.Event); dumpExpression(stmt.Listener); } else if (s is CodeMethodReturnStatement) { var stmt = (CodeMethodReturnStatement)s; dumpExpression(stmt.Expression); } else { writeLineIndent(s.GetType().ToString()); } _indent--; }
static KeyValuePair <MemberInfo, object[]> _GetInstanceData(CodeStatement stmt) { var a = stmt as CodeAssignStatement; if (null != a) { if (_HasExtraNonsense(a)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { a.Left, a.Right, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeExpression), typeof(CodeExpression) }), new object[] { a.Left, a.Right })); } var ae = stmt as CodeAttachEventStatement; if (null != ae) { if (_HasExtraNonsense(ae)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { ae.Event, ae.Listener, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeEventReferenceExpression), typeof(CodeExpression) }), new object[] { ae.Event, ae.Listener })); } var cm = stmt as CodeCommentStatement; if (null != cm) { if (_HasExtraNonsense(cm)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { cm.Comment, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } if (!cm.Comment.DocComment) { return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(string) }), new object[] { cm.Comment.Text })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(string), typeof(bool) }), new object[] { cm.Comment.Text, cm.Comment.DocComment })); } var c = stmt as CodeConditionStatement; if (null != c) { if (_HasExtraNonsense(c)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { c.Condition, _ToArray(c.TrueStatements), _ToArray(c.FalseStatements), _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeExpression), typeof(CodeStatement[]), typeof(CodeStatement[]) }), new object[] { c.Condition, _ToArray(c.TrueStatements), _ToArray(c.FalseStatements) })); } var e = stmt as CodeExpressionStatement; if (null != e) { if (_HasExtraNonsense(e)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { e.Expression, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeExpression) }), new object[] { e.Expression })); } var g = stmt as CodeGotoStatement; if (null != g) { if (_HasExtraNonsense(g)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { g.Label, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(string) }), new object[] { g.Label })); } var i = stmt as CodeIterationStatement; if (null != i) { if (_HasExtraNonsense(i)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { i.InitStatement, i.TestExpression, i.IncrementStatement, _ToArray(i.Statements), _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeStatement), typeof(CodeExpression), typeof(CodeStatement), typeof(CodeStatement[]) }), new object[] { i.InitStatement, i.TestExpression, i.IncrementStatement, _ToArray(i.Statements) })); } var l = stmt as CodeLabeledStatement; if (null != l) { if (_HasExtraNonsense(l)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { l.Label, l.Statement, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(string), typeof(CodeStatement) }), new object[] { l.Label, l.Statement })); } var r = stmt as CodeMethodReturnStatement; if (null != r) { if (_HasExtraNonsense(r)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { r.Expression, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeExpression) }), new object[] { r.Expression })); } var re = stmt as CodeRemoveEventStatement; if (null != re) { if (_HasExtraNonsense(re)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { re.Event, re.Listener, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeEventReferenceExpression), typeof(CodeExpression) }), new object[] { re.Event, re.Listener })); } var s = stmt as CodeSnippetStatement; if (null != s) { if (_HasExtraNonsense(s)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { s.Value, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(string) }), new object[] { s.Value })); } var t = stmt as CodeThrowExceptionStatement; if (null != t) { if (_HasExtraNonsense(t)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { t.ToThrow, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeExpression) }), new object[] { t.ToThrow })); } var tc = stmt as CodeTryCatchFinallyStatement; if (null != tc) { if (_HasExtraNonsense(tc)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { _ToArray(tc.TryStatements), _ToArray(tc.CatchClauses), _ToArray(tc.FinallyStatements), _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeStatement[]), typeof(CodeCatchClause[]), typeof(CodeStatement[]) }), new object[] { _ToArray(tc.TryStatements), _ToArray(tc.CatchClauses), _ToArray(tc.FinallyStatements) })); } var v = stmt as CodeVariableDeclarationStatement; if (null != v) { if (_HasExtraNonsense(v)) { return(new KeyValuePair <MemberInfo, object[]>( typeof(CodeDomBuilder).GetMethod(stmt.GetType().Name.Substring(4)), new object[] { v.Type, v.Name, v.InitExpression, _ToArray(a.StartDirectives), _ToArray(a.EndDirectives), a.LinePragma })); } return(new KeyValuePair <MemberInfo, object[]>( stmt.GetType().GetConstructor(new Type[] { typeof(CodeTypeReference), typeof(string), typeof(CodeExpression) }), new object[] { v.Type, v.Name, v.InitExpression })); } throw new NotSupportedException("The statement instance data could not be serialized."); }
private void GenerateStatement(CodeStatement e) { switch (e) { case CodeCommentStatement val: GenerateCommentStatement(val); break; case CodeMethodReturnStatement val: GenerateMethodReturnStatement(val); break; case CodeConditionStatement val: GenerateConditionStatement(val); break; case CodeTryCatchFinallyStatement val: GenerateTryCatchFinallyStatement(val); break; case CodeAssignStatement val: GenerateAssignStatement(val); break; case CodeExpressionStatement val: GenerateExpressionStatement(val); break; case CodeIterationStatement val: GenerateIterationStatement(val); break; case CodeWhileLoopStatement val: GenerateWhileLoopStatement(val); break; case CodeSimpleForLoopStatement val: GenerateSimpleForLoopStatement(val); break; case CodeThrowExceptionStatement val: GenerateThrowExceptionStatement(val); break; case CodeSnippetStatement val: // 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(val); Indent = savedIndent; // Restore the indent break; case CodeVariableDeclarationStatement val: GenerateVariableDeclarationStatement(val); break; case CodeBreakLabelStatement val: GenerateBreakLabelStatement(val); break; case CodeContinueLabelStatement val: GenerateContinueLabelStatement(val); break; case CodeLabeledStatement val: GenerateLabeledStatement(val); break; case CodeForeachStatement val: GenerateForEachStatement(val); break; default: throw new ArgumentException(InvalidElementType(e.GetType())); } }
private void GenerateStatement(CodeStatement e) { 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 CodeLabeledStatement) { GenerateLabeledStatement((CodeLabeledStatement)e); } else { throw new ArgumentException("Invalid element type: " + e.GetType().FullName, "e"); } }
public IStatement GetStatement(CodeStatement codeStatement, CodeGeneratorOptions codeGeneratorOptions) { return(_statementMap[codeStatement.GetType()](codeStatement, codeGeneratorOptions)); }
private void ValidateStatement(CodeStatement e) { ValidateCodeDirectives(e.StartDirectives); ValidateCodeDirectives(e.EndDirectives); if (e is CodeCommentStatement) { this.ValidateCommentStatement((CodeCommentStatement)e); } else if (e is CodeMethodReturnStatement) { this.ValidateMethodReturnStatement((CodeMethodReturnStatement)e); } else if (e is CodeConditionStatement) { this.ValidateConditionStatement((CodeConditionStatement)e); } else if (e is CodeTryCatchFinallyStatement) { this.ValidateTryCatchFinallyStatement((CodeTryCatchFinallyStatement)e); } else if (e is CodeAssignStatement) { this.ValidateAssignStatement((CodeAssignStatement)e); } else if (e is CodeExpressionStatement) { this.ValidateExpressionStatement((CodeExpressionStatement)e); } else if (e is CodeIterationStatement) { this.ValidateIterationStatement((CodeIterationStatement)e); } else if (e is CodeThrowExceptionStatement) { this.ValidateThrowExceptionStatement((CodeThrowExceptionStatement)e); } else if (e is CodeSnippetStatement) { this.ValidateSnippetStatement((CodeSnippetStatement)e); } else if (e is CodeVariableDeclarationStatement) { this.ValidateVariableDeclarationStatement((CodeVariableDeclarationStatement)e); } else if (e is CodeAttachEventStatement) { this.ValidateAttachEventStatement((CodeAttachEventStatement)e); } else if (e is CodeRemoveEventStatement) { this.ValidateRemoveEventStatement((CodeRemoveEventStatement)e); } else if (e is CodeGotoStatement) { ValidateGotoStatement((CodeGotoStatement)e); } else { if (!(e is CodeLabeledStatement)) { throw new ArgumentException(SR.GetString("InvalidElementType", new object[] { e.GetType().FullName }), "e"); } this.ValidateLabeledStatement((CodeLabeledStatement)e); } }
protected void GenerateStatement(CodeStatement s) { try { s.Accept(visitor); } catch (NotImplementedException) { throw new ArgumentException("Element type " + s.GetType() + " is not supported.", "s"); } }
private static void DumpStatement(StreamWriter writer, CodeStatement s) { if (writer is null) { throw new ArgumentNullException(nameof(writer)); } if (s.UserData.Count > 0) { DumpUserData(s.UserData); } /* * System.CodeDom.CodeAssignStatement * System.CodeDom.CodeAttachEventStatement * System.CodeDom.CodeCommentStatement * System.CodeDom.CodeConditionStatement * System.CodeDom.CodeExpressionStatement * System.CodeDom.CodeGotoStatement * System.CodeDom.CodeIterationStatement * System.CodeDom.CodeLabeledStatement * System.CodeDom.CodeMethodReturnStatement * System.CodeDom.CodeRemoveEventStatement * System.CodeDom.CodeSnippetStatement * System.CodeDom.CodeThrowExceptionStatement * System.CodeDom.CodeTryCatchFinallyStatement * System.CodeDom.CodeVariableDeclarationStatement */ _indent++; if (s is CodeAssignStatement cas) { if (cas.Left != null) { DumpExpression(cas.Left); } WriteLineIndent(GetExpression(cas.Right)); if (cas.Right != null) { DumpExpression(cas.Right); } } else if (s is CodeExpressionStatement ces) { WriteLineIndent(ces.Expression.GetType().ToString()); DumpExpression(ces.Expression); } else if (s is CodeVariableDeclarationStatement cvds) { WriteLineIndent(cvds.Name); var tr = cvds.Type; WriteLineIndent(tr.BaseType); } else if (s is CodeAttachEventStatement caes) { DumpExpression(caes.Event); DumpExpression(caes.Listener); } else if (s is CodeMethodReturnStatement cmrs) { DumpExpression(cmrs.Expression); } else { WriteLineIndent(s.GetType().ToString()); } _indent--; }
public static CodeStatement Clone(this CodeStatement statement) { if (statement == null) { return(null); } if (statement is CodeAssignStatement) { return((statement as CodeAssignStatement).Clone()); } if (statement is CodeAttachEventStatement) { return((statement as CodeAttachEventStatement).Clone()); } if (statement is CodeConditionStatement) { return((statement as CodeConditionStatement).Clone()); } if (statement is CodeExpressionStatement) { return((statement as CodeExpressionStatement).Clone()); } if (statement is CodeIterationStatement) { return((statement as CodeIterationStatement).Clone()); } if (statement is CodeLabeledStatement) { return((statement as CodeLabeledStatement).Clone()); } if (statement is CodeMethodReturnStatement) { return((statement as CodeMethodReturnStatement).Clone()); } if (statement is CodeRemoveEventStatement) { return((statement as CodeRemoveEventStatement).Clone()); } if (statement is CodeThrowExceptionStatement) { return((statement as CodeThrowExceptionStatement).Clone()); } if (statement is CodeTryCatchFinallyStatement) { return((statement as CodeTryCatchFinallyStatement).Clone()); } if (statement is CodeVariableDeclarationStatement) { return((statement as CodeVariableDeclarationStatement).Clone()); } // The following statements don't have any types to replace, so we don't need to // change anything about them right now. If we were doing something more // advanced in the future, we might need to do more work here. if (statement is CodeCommentStatement) { return(statement); } if (statement is CodeGotoStatement) { return(statement); } if (statement is CodeSnippetStatement) { return(statement); } throw new NotImplementedException("Clone has not been implemented for statement of type: " + statement.GetType().FullName); }