csharpcodecompiler.cs
来自「没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没」· CS 代码 · 共 1,254 行 · 第 1/3 页
CS
1,254 行
(CodeEventReferenceExpression e) { if(e.TargetObject != null) { GenerateExpression(e.TargetObject); Output.Write("."); } OutputIdentifier(e.EventName); } protected override void GenerateFieldReferenceExpression (CodeFieldReferenceExpression e) { if(e.TargetObject != null) { GenerateExpression(e.TargetObject); Output.Write("."); } OutputIdentifier(e.FieldName); } protected override void GenerateIndexerExpression (CodeIndexerExpression e) { GenerateExpression(e.TargetObject); Output.Write("["); OutputExpressionList(e.Indices); Output.Write("]"); } protected override void GenerateMethodInvokeExpression (CodeMethodInvokeExpression e) { GenerateMethodReferenceExpression(e.Method); Output.Write("("); OutputExpressionList(e.Parameters); Output.Write(")"); } protected override void GenerateMethodReferenceExpression (CodeMethodReferenceExpression e) { if(e.TargetObject != null) { GenerateExpression(e.TargetObject); Output.Write("."); } OutputIdentifier(e.MethodName); } protected override void GenerateObjectCreateExpression (CodeObjectCreateExpression e) { Output.Write("new "); OutputType(e.CreateType); Output.Write("("); OutputExpressionList(e.Parameters); Output.Write(")"); } protected override void GeneratePropertyReferenceExpression (CodePropertyReferenceExpression e) { if(e.TargetObject != null) { GenerateExpression(e.TargetObject); Output.Write("."); } OutputIdentifier(e.PropertyName); } protected override void GeneratePropertySetValueReferenceExpression (CodePropertySetValueReferenceExpression e) { Output.Write("value"); } protected override void GenerateSnippetExpression (CodeSnippetExpression e) { Output.Write(e.Value); } protected override void GenerateThisReferenceExpression (CodeThisReferenceExpression e) { Output.Write("this"); } protected override void GenerateVariableReferenceExpression (CodeVariableReferenceExpression e) { OutputIdentifier(e.VariableName); } // Start a new indented block. private void StartBlock() { if(Options.BracingStyle == "C") { Output.WriteLine(); Output.WriteLine("{"); } else { Output.WriteLine(" {"); } Indent += 1; } // End an indented block. private void EndBlock() { Indent -= 1; Output.WriteLine("}"); } // Generate various statement categories. protected override void GenerateAssignStatement (CodeAssignStatement e) { GenerateExpression(e.Left); Output.Write(" = "); GenerateExpression(e.Right); if(!outputForInit) { Output.WriteLine(";"); } } protected override void GenerateAttachEventStatement (CodeAttachEventStatement e) { GenerateExpression(e.Event); Output.Write(" += "); GenerateExpression(e.Listener); Output.WriteLine(";"); } protected override void GenerateConditionStatement (CodeConditionStatement e) { Output.Write("if ("); GenerateExpression(e.Condition); Output.Write(")"); StartBlock(); GenerateStatements(e.TrueStatements); EndBlock(); CodeStatementCollection stmts = e.FalseStatements; if(stmts.Count > 0 || Options.ElseOnClosing) { Output.Write("else"); StartBlock(); GenerateStatements(stmts); EndBlock(); } } protected override void GenerateExpressionStatement (CodeExpressionStatement e) { GenerateExpression(e.Expression); if(!outputForInit) { Output.WriteLine(";"); } } protected override void GenerateGotoStatement (CodeGotoStatement e) { Output.Write("goto "); Output.Write(e.Label); Output.WriteLine(";"); } protected override void GenerateIterationStatement (CodeIterationStatement e) { if(e.InitStatement == null && e.TestExpression != null && e.IncrementStatement == null) { // Special case - output a "while" statement. Output.Write("while ("); GenerateExpression(e.TestExpression); Output.Write(")"); StartBlock(); GenerateStatements(e.Statements); EndBlock(); } else { // Output a "for" statement. Output.Write("for ("); outputForInit = true; if(e.InitStatement != null) { GenerateStatement(e.InitStatement); } Output.Write("; "); if(e.TestExpression != null) { GenerateExpression(e.TestExpression); } Output.Write("; "); if(e.IncrementStatement != null) { GenerateStatement(e.IncrementStatement); } outputForInit = false; Output.Write(")"); StartBlock(); GenerateStatements(e.Statements); EndBlock(); } } protected override void GenerateLabeledStatement (CodeLabeledStatement e) { Indent -= 1; Output.Write(e.Label); Output.WriteLine(":"); Indent += 1; GenerateStatement(e.Statement); } protected override void GenerateMethodReturnStatement (CodeMethodReturnStatement e) { if(e.Expression != null) { Output.Write("return "); GenerateExpression(e.Expression); Output.WriteLine(";"); } else { Output.WriteLine("return;"); } } protected override void GenerateRemoveEventStatement (CodeRemoveEventStatement e) { GenerateExpression(e.Event); Output.Write(" -= "); GenerateExpression(e.Listener); Output.WriteLine(";"); } protected override void GenerateThrowExceptionStatement (CodeThrowExceptionStatement e) { if(e.ToThrow != null) { Output.Write("throw "); GenerateExpression(e.ToThrow); Output.WriteLine(";"); } else { Output.WriteLine("throw;"); } } protected override void GenerateTryCatchFinallyStatement (CodeTryCatchFinallyStatement e) { Output.Write("try"); StartBlock(); GenerateStatements(e.TryStatements); EndBlock(); CodeCatchClauseCollection clauses = e.CatchClauses; if(clauses.Count > 0) { foreach(CodeCatchClause clause in clauses) { if(clause.CatchExceptionType != null) { Output.Write("catch ("); OutputType(clause.CatchExceptionType); if(clause.LocalName != null) { Output.Write(" "); OutputIdentifier(clause.LocalName); } Output.Write(")"); } else { Output.Write("catch"); } StartBlock(); GenerateStatements(clause.Statements); EndBlock(); } } CodeStatementCollection fin = e.FinallyStatements; if(fin.Count > 0) { Output.Write("finally"); StartBlock(); GenerateStatements(fin); EndBlock(); } } protected override void GenerateVariableDeclarationStatement (CodeVariableDeclarationStatement e) { OutputTypeNamePair(e.Type, e.Name); if(e.InitExpression != null) { Output.Write(" = "); GenerateExpression(e.InitExpression); } if(!outputForInit) { Output.WriteLine(";"); } } // Generate various declaration categories. protected override void GenerateAttributeDeclarationsStart (CodeAttributeDeclarationCollection attributes) { Output.Write("["); } protected override void GenerateAttributeDeclarationsEnd (CodeAttributeDeclarationCollection attributes) { Output.Write("]"); } protected override void GenerateConstructor (CodeConstructor e, CodeTypeDeclaration c) { // Bail out if not a class or struct. if(!IsCurrentClass && !IsCurrentStruct) { return; } // Output the attributes and constructor signature. OutputAttributeDeclarations(e.CustomAttributes); OutputMemberAccessModifier(e.Attributes); OutputIdentifier(CurrentTypeName); Output.Write("("); OutputParameters(e.Parameters); Output.Write(")"); // Output the ": base" or ": this" expressions. if(e.BaseConstructorArgs.Count > 0) { Output.WriteLine(" : "); Indent += 2; Output.Write("base("); OutputExpressionList(e.BaseConstructorArgs); Output.Write(")"); Indent -= 2; } if(e.ChainedConstructorArgs.Count > 0) { Output.WriteLine(" : "); Indent += 2; Output.Write("base("); OutputExpressionList(e.ChainedConstructorArgs); Output.Write(")"); Indent -= 2; } // Output the body of the constructor. StartBlock(); GenerateStatements(e.Statements); EndBlock(); } protected override void GenerateEntryPointMethod (CodeEntryPointMethod e, CodeTypeDeclaration c) { Output.Write("public static void Main()"); StartBlock(); GenerateStatements(e.Statements); EndBlock(); } protected override void GenerateEvent (CodeMemberEvent e, CodeTypeDeclaration c) { // Bail out if not a class, struct, or interface. if(!IsCurrentClass && !IsCurrentStruct && !IsCurrentInterface) { return; } // Output the event definition. OutputAttributeDeclarations(e.CustomAttributes); if(e.PrivateImplementationType == null) { OutputMemberAccessModifier(e.Attributes); OutputMemberScopeModifier(e.Attributes); Output.Write("event "); OutputTypeNamePair(e.Type, e.Name); } else { Output.Write("event "); OutputTypeNamePair (e.Type, e.PrivateImplementationType + "." + e.Name); } Output.WriteLine(";"); } protected override void GenerateField(CodeMemberField e) { // Bail out if not a class, struct, or enum. if(!IsCurrentClass && !IsCurrentStruct && !IsCurrentEnum) { return; } // Generate information about the field. if(!IsCurrentEnum) { OutputAttributeDeclarations(e.CustomAttributes); OutputMemberAccessModifier(e.Attributes); OutputFieldScopeModifier(e.Attributes); OutputTypeNamePair(e.Type, e.Name); if(e.InitExpression != null) { Output.Write(" = "); GenerateExpression(e.InitExpression); } Output.WriteLine(";"); } else { OutputAttributeDeclarations(e.CustomAttributes); OutputIdentifier(e.Name); if(e.InitExpression != null) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?