csharpcodecompiler.cs
来自「没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没」· CS 代码 · 共 1,254 行 · 第 1/3 页
CS
1,254 行
Output.Write(" = "); GenerateExpression(e.InitExpression); } Output.WriteLine(","); } } protected override void GenerateMethod (CodeMemberMethod e, CodeTypeDeclaration c) { // Bail out if not a class, struct, or interface. if(!IsCurrentClass && !IsCurrentStruct && !IsCurrentInterface) { return; } // Output the attributes and method signature. OutputAttributeDeclarations(e.CustomAttributes); if(e.ReturnTypeCustomAttributes.Count > 0) { OutputAttributeDeclarations ("return: ", e.ReturnTypeCustomAttributes); } if(!IsCurrentInterface) { if(e.PrivateImplementationType == null) { OutputMemberAccessModifier(e.Attributes); OutputMemberScopeModifier(e.Attributes); } } else if((e.Attributes & MemberAttributes.VTableMask) == MemberAttributes.New) { Output.Write("new "); } if(e.ReturnType != null) { OutputType(e.ReturnType); } else { Output.Write("void"); } Output.Write(" "); if(e.PrivateImplementationType != null && !IsCurrentInterface) { Output.Write(e.PrivateImplementationType.BaseType); Output.Write("."); } OutputIdentifier(e.Name); Output.Write("("); OutputParameters(e.Parameters); Output.Write(")"); // Output the body of the method. if(IsCurrentInterface || (e.Attributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract) { Output.WriteLine(";"); } else { StartBlock(); GenerateStatements(e.Statements); EndBlock(); } } protected override void GenerateProperty (CodeMemberProperty e, CodeTypeDeclaration c) { // Bail out if not a class, struct, or interface. if(!IsCurrentClass && !IsCurrentStruct && !IsCurrentInterface) { return; } // Output the attributes and property signature. OutputAttributeDeclarations(e.CustomAttributes); if(!IsCurrentInterface) { if(e.PrivateImplementationType == null) { OutputMemberAccessModifier(e.Attributes); OutputMemberScopeModifier(e.Attributes); } } else if((e.Attributes & MemberAttributes.VTableMask) == MemberAttributes.New) { Output.Write("new "); } OutputType(e.Type); Output.Write(" "); if(e.PrivateImplementationType != null && !IsCurrentInterface) { Output.Write(e.PrivateImplementationType.BaseType); Output.Write("."); } if(e.Parameters.Count == 0) { OutputIdentifier(e.Name); } else { Output.Write("this["); OutputParameters(e.Parameters); Output.Write("]"); } // Output the body of the property. StartBlock(); if(e.HasGet) { if(IsCurrentInterface || (e.Attributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract) { Output.WriteLine("get;"); } else { Output.Write("get"); StartBlock(); GenerateStatements(e.GetStatements); EndBlock(); } } if(e.HasSet) { if(IsCurrentInterface || (e.Attributes & MemberAttributes.ScopeMask) == MemberAttributes.Abstract) { Output.WriteLine("set;"); } else { Output.Write("set"); StartBlock(); GenerateStatements(e.SetStatements); EndBlock(); } } EndBlock(); } protected override void GenerateNamespaceStart(CodeNamespace e) { String name = e.Name; if(name != null && name.Length != 0) { Output.Write("namespace "); OutputIdentifier(name); StartBlock(); } } protected override void GenerateNamespaceEnd(CodeNamespace e) { String name = e.Name; if(name != null && name.Length != 0) { EndBlock(); } } protected override void GenerateNamespaceImport(CodeNamespaceImport e) { Output.Write("using "); OutputIdentifier(e.Namespace); Output.WriteLine(";"); } protected override void GenerateSnippetMember (CodeSnippetTypeMember e) { Output.Write(e.Text); } protected override void GenerateTypeConstructor (CodeTypeConstructor e) { Output.Write("static "); OutputIdentifier(CurrentTypeName); Output.Write("()"); StartBlock(); GenerateStatements(e.Statements); EndBlock(); } protected override void GenerateTypeStart(CodeTypeDeclaration e) { OutputAttributeDeclarations(e.CustomAttributes); if(!IsCurrentDelegate) { OutputTypeAttributes (e.TypeAttributes, IsCurrentStruct, IsCurrentEnum); OutputIdentifier(e.Name); String sep = " : "; foreach(CodeTypeReference type in e.BaseTypes) { Output.Write(sep); OutputType(type); sep = ","; } StartBlock(); } else { switch(e.TypeAttributes & TypeAttributes.VisibilityMask) { case TypeAttributes.NestedPrivate: Output.Write("private "); break; case TypeAttributes.Public: case TypeAttributes.NestedPublic: Output.Write("public "); break; } Output.Write("delegate "); CodeTypeDelegate d = (CodeTypeDelegate)e; if(d.ReturnType != null) { OutputType(d.ReturnType); } else { Output.Write("void"); } Output.Write(" "); OutputIdentifier(d.Name); Output.Write("("); OutputParameters(d.Parameters); Output.WriteLine(");"); } } protected override void GenerateTypeEnd(CodeTypeDeclaration e) { if(!IsCurrentDelegate) { EndBlock(); } } // Generate various misc categories. protected override void GenerateComment(CodeComment e) { String text = e.Text; String commentSeq = (e.DocComment ? "/// " : "// "); if(text == null) { return; } int posn = 0; int end, next; while(posn < text.Length) { end = posn; next = end; while(end < text.Length) { if(text[end] == '\r') { if((end + 1) < text.Length && text[end + 1] == '\n') { next = end + 1; } break; } else if(text[end] == '\n' || text[end] == '\u2028' || text[end] == '\u2029') { break; } ++end; next = end; } Output.Write(commentSeq); Output.WriteLine(text.Substring(posn, end - posn)); posn = next + 1; } } protected override void GenerateLinePragmaStart(CodeLinePragma e) { Output.WriteLine(); Output.WriteLine("#line {0} \"{1}\"", e.LineNumber, e.FileName); } protected override void GenerateLinePragmaEnd(CodeLinePragma e) { Output.WriteLine(); Output.WriteLine("#line default"); } protected override String GetTypeOutput(CodeTypeReference value) { String baseType; if(value.ArrayElementType != null) { baseType = GetTypeOutput(value.ArrayElementType); } else { baseType = value.BaseType; } baseType = NormalizeTypeName(baseType); int rank = value.ArrayRank; if(rank > 0) { baseType += "["; while(rank > 1) { baseType += ","; --rank; } baseType += "]"; } return baseType; } // Determine if "value" is a valid identifier. protected override bool IsValidIdentifier(String value) { if(value == null || value.Length == 0) { return false; } else if(Array.IndexOf(reservedWords, value) != -1) { return false; } else { return IsValidLanguageIndependentIdentifier(value); } } // Output an identifier. protected override void OutputIdentifier(String ident) { Output.Write(CreateEscapedIdentifier(ident)); } // Output a type. protected override void OutputType(CodeTypeReference typeRef) { Output.Write(GetTypeOutput(typeRef)); } // Hex characters for use in "QuoteSnippetString". private const String hexchars = "0123456789abcdef"; // Quote a snippet string. protected override String QuoteSnippetString(String value) { StringBuilder builder = new StringBuilder(value.Length + 16); builder.Append('"'); int length = 0; foreach(char ch in value) { if(ch == '\0') { builder.Append("\\0"); length += 2; } else if(ch == '\r') { builder.Append("\\r"); length += 2; } else if(ch == '\n') { builder.Append("\\n"); length += 2; } else if(ch == '\t') { builder.Append("\\t"); length += 2; } else if(ch == '\\' || ch == '"') { builder.Append('\\'); builder.Append(ch); length += 2; } else if(ch < 0x0020 || ch > 0x007E) { builder.Append('\\'); builder.Append('u'); builder.Append(hexchars[(ch >> 12) & 0x0F]); builder.Append(hexchars[(ch >> 8) & 0x0F]); builder.Append(hexchars[(ch >> 4) & 0x0F]); builder.Append(hexchars[ch & 0x0F]); length += 6; } else { builder.Append(ch); ++length; } if(length >= 60) { builder.Append("\" +" + Output.NewLine + "\""); length = 0; } } builder.Append('"'); return builder.ToString(); } // Determine if this code generator supports a particular // set of generator options. protected override bool Supports(GeneratorSupport supports) { return ((supports & (GeneratorSupport)0x001FFFFF) == supports); }}; // class CSharpCodeCompiler#endif // CONFIG_CODEDOM}; // namespace System.CodeDom.Compiler
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?