public void GenerateCodeFromStatement(CodeStatement e, TextWriter w, CodeGeneratorOptions o) { ICustomCodeDomObject co = e as ICustomCodeDomObject; if (co != null) { co.GenerateCode(GetLang()); } _generator.GenerateCodeFromStatement(e, w, o); }
public void GenerateCodeFromExpression(CodeExpression e, TextWriter w, CodeGeneratorOptions o) { ICustomCodeDomObject co = e as ICustomCodeDomObject; if (co != null) { co.GenerateCode(GetLang()); } _generator.GenerateCodeFromExpression(e, w, o); }
private static CodeTypeMember ProcessMember(CodeTypeMember m, LinqToCodedom.CodeDomGenerator.Language language) { foreach (CodeDirective directive in m.StartDirectives) { ProcessDirective(directive, language); } foreach (CodeDirective directive in m.EndDirectives) { ProcessDirective(directive, language); } if (typeof(CodeMemberMethod).IsAssignableFrom(m.GetType())) { foreach (CodeStatement stmt in ((CodeMemberMethod)m).Statements) { ProcessStmt(stmt, language); } } else if (typeof(CodeMemberProperty).IsAssignableFrom(m.GetType())) { foreach (CodeStatement stmt in ((CodeMemberProperty)m).GetStatements) { ProcessStmt(stmt, language); } foreach (CodeStatement stmt in ((CodeMemberProperty)m).SetStatements) { ProcessStmt(stmt, language); } } else if (typeof(CodeConstructor).IsAssignableFrom(m.GetType())) { ProcessExpr(((CodeConstructor)m).BaseConstructorArgs, language); ProcessExpr(((CodeConstructor)m).ChainedConstructorArgs, language); ProcessStmt(((CodeConstructor)m).Statements, language); } else if (typeof(CodeMemberField).IsAssignableFrom(m.GetType())) { ProcessExpr(((CodeMemberField)m).InitExpression, language); } else if (typeof(CodeTypeDeclaration).IsAssignableFrom(m.GetType())) { CodeTypeDeclaration td = (CodeTypeDeclaration)m; ProcessTypeDeclaration(td, language); foreach (CodeTypeMember ms in td.Members) { ProcessMember(ms, language); } } ICustomCodeDomObject co = m as ICustomCodeDomObject; if (co != null) { co.GenerateCode(language); } if (typeof(CodeMemberMethod).IsAssignableFrom(m.GetType())) { return(ProcessMethod(m as CodeMemberMethod, language)); } return(m); }
private static void ProcessExpr(CodeExpression codeExpression, CodeDomGenerator.Language language) { if (codeExpression == null) { return; } if (typeof(CodeArgumentReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodeArrayCreateExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeArrayCreateExpression)codeExpression).Initializers, language); ProcessExpr(((CodeArrayCreateExpression)codeExpression).SizeExpression, language); } else if (typeof(CodeArrayIndexerExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeArrayIndexerExpression)codeExpression).Indices, language); } else if (typeof(CodeBaseReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodeBinaryOperatorExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeBinaryOperatorExpression)codeExpression).Left, language); ProcessExpr(((CodeBinaryOperatorExpression)codeExpression).Right, language); } else if (typeof(CodeCastExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeCastExpression)codeExpression).Expression, language); } else if (typeof(CodeDefaultValueExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodeDelegateCreateExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeDelegateCreateExpression)codeExpression).TargetObject, language); } else if (typeof(CodeDelegateInvokeExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeDelegateInvokeExpression)codeExpression).Parameters, language); ProcessExpr(((CodeDelegateInvokeExpression)codeExpression).TargetObject, language); } else if (typeof(CodeDirectionExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeDirectionExpression)codeExpression).Expression, language); } else if (typeof(CodeEventReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeEventReferenceExpression)codeExpression).TargetObject, language); } else if (typeof(CodeFieldReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeFieldReferenceExpression)codeExpression).TargetObject, language); } else if (typeof(CodeIndexerExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeIndexerExpression)codeExpression).Indices, language); ProcessExpr(((CodeIndexerExpression)codeExpression).TargetObject, language); } else if (typeof(CodeMethodInvokeExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeMethodInvokeExpression)codeExpression).Method, language); ProcessExpr(((CodeMethodInvokeExpression)codeExpression).Parameters, language); } else if (typeof(CodeMethodReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeMethodReferenceExpression)codeExpression).TargetObject, language); } else if (typeof(CodeObjectCreateExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeObjectCreateExpression)codeExpression).Parameters, language); } else if (typeof(CodeParameterDeclarationExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodePrimitiveExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodePropertyReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodePropertyReferenceExpression)codeExpression).TargetObject, language); } else if (typeof(CodePropertySetValueReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodeThisReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodeTypeOfExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodeTypeReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodeVariableReferenceExpression).IsAssignableFrom(codeExpression.GetType())) { } else if (typeof(CodeAssignExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeAssignExpression)codeExpression).Expression, language); } else if (typeof(CodeAsExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeAsExpression)codeExpression).Expression, language); } else if (typeof(CodeIsExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeIsExpression)codeExpression).Expression, language); } else if (typeof(CodeXorExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeXorExpression)codeExpression).Left, language); ProcessExpr(((CodeXorExpression)codeExpression).Right, language); } else if (typeof(CodeUnaryExpression).IsAssignableFrom(codeExpression.GetType())) { ProcessExpr(((CodeUnaryExpression)codeExpression).Expression, language); } ICustomCodeDomObject co = codeExpression as ICustomCodeDomObject; if (co != null) { co.GenerateCode(language); } }
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); } }
internal static CodeTypeMember ProcessMember(CodeTypeMember m, LinqToCodedom.CodeDomGenerator.Language language) { foreach (CodeDirective directive in m.StartDirectives) { ProcessDirective(directive, language); } foreach (CodeDirective directive in m.EndDirectives) { ProcessDirective(directive, language); } if (typeof(CodeMemberMethod).IsAssignableFrom(m.GetType())) { foreach (CodeStatement stmt in ((CodeMemberMethod)m).Statements) { ProcessStmt(stmt, language); } } else if (typeof(CodeMemberProperty).IsAssignableFrom(m.GetType())) { foreach (CodeStatement stmt in ((CodeMemberProperty)m).GetStatements) { ProcessStmt(stmt, language); } foreach (CodeStatement stmt in ((CodeMemberProperty)m).SetStatements) { ProcessStmt(stmt, language); } } else if (typeof(CodeConstructor).IsAssignableFrom(m.GetType())) { ProcessExpr(((CodeConstructor)m).BaseConstructorArgs, language); ProcessExpr(((CodeConstructor)m).ChainedConstructorArgs, language); ProcessStmt(((CodeConstructor)m).Statements, language); } else if (typeof(CodeMemberField).IsAssignableFrom(m.GetType())) { ProcessExpr(((CodeMemberField)m).InitExpression, language); } else if (typeof(CodeTypeDeclaration).IsAssignableFrom(m.GetType())) { CodeTypeDeclaration td = (CodeTypeDeclaration)m; ProcessTypeDeclaration(td, language); foreach (CodeTypeMember ms in td.Members) { ProcessMember(ms, language); } } else if (typeof(CodeDefaultProperty).IsAssignableFrom(m.GetType())) { ProcessMember((m as CodeDefaultProperty).Property, language); foreach (CodeExpression p in (m as CodeDefaultProperty).Parameters) { ProcessExpr(p, language); } } else if (typeof(CodeReadOnlyField).IsAssignableFrom(m.GetType())) { ProcessMember((m as CodeReadOnlyField).Field, language); } else if (typeof(CodePropertyImplementsInterface).IsAssignableFrom(m.GetType())) { ProcessMember((m as CodePropertyImplementsInterface).Property, language); } else if (typeof(CodePartialMethod).IsAssignableFrom(m.GetType())) { ProcessMember((m as CodePartialMethod).Method, language); } else if (typeof(CodeMemberOperatorOverride).IsAssignableFrom(m.GetType())) { foreach (CodeExpression p in (m as CodeMemberOperatorOverride).Parameters) { ProcessExpr(p, language); } } else if (typeof(CodeCustomEvent).IsAssignableFrom(m.GetType())) { var ce = m as CodeCustomEvent; ProcessMember(ce.Event, language); ProcessMember(ce.AddMethod, language); ProcessMember(ce.RemoveMethod, language); ProcessMember(ce.RaiseMethod, language); } ICustomCodeDomObject co = m as ICustomCodeDomObject; if (co != null) { co.GenerateCode(language); } if (typeof(CodeMemberMethod).IsAssignableFrom(m.GetType())) { return(ProcessMethod(m as CodeMemberMethod, language)); } return(m); }