vbcodecompiler.cs
来自「没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没」· CS 代码 · 共 1,281 行 · 第 1/3 页
CS
1,281 行
String sep = " Inherits "; bool needeol = false; foreach(CodeTypeReference type in e.BaseTypes) { Output.Write(sep); OutputType(type); if(sep == " Inherits ") { Output.WriteLine(); sep = "Implements "; } else { sep = ", "; needeol = true; } } if(needeol) { Output.WriteLine(); } --Indent; } 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) { Output.Write("Function "); OutputType(d.ReturnType); } else { Output.Write("Sub "); } OutputIdentifier(d.Name); Output.Write("("); OutputParameters(d.Parameters); Output.Write(")"); if(d.ReturnType != null) { Output.Write(" As "); OutputType(d.ReturnType); Output.WriteLine(); Output.WriteLine("End Function"); } else { Output.WriteLine(); Output.WriteLine("End Sub"); } } } protected override void GenerateTypeEnd(CodeTypeDeclaration e) { if(IsCurrentClass) { --Indent; Output.WriteLine("End Class"); } else if(IsCurrentStruct) { --Indent; Output.WriteLine("End Structure"); } else if(IsCurrentInterface) { --Indent; Output.WriteLine("End Interface"); } else if(IsCurrentEnum) { --Indent; Output.WriteLine("End Enum"); } } // Generate various misc categories. protected override void GenerateComment(CodeComment e) { String text = e.Text; 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("'"); Output.WriteLine(text.Substring(posn, end - posn)); posn = next + 1; } } protected override void GenerateLinePragmaStart(CodeLinePragma e) { Output.WriteLine(); Output.Write("#ExternalSource(\""); Output.Write(e.FileName); Output.Write(","); Output.Write(e.LineNumber); Output.WriteLine(")"); } protected override void GenerateLinePragmaEnd(CodeLinePragma e) { Output.WriteLine(); Output.WriteLine("#End ExternalSource"); } 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; } switch(value[value.Length - 1]) { case '%': case '&': case '@': case '!': case '#': case '$': { // Strip the type suffix character from the identifier. value = value.Substring(0, value.Length - 1); if(value.Length == 0) { return false; } } break; default: break; } if(Array.IndexOf(reservedWords, value.ToLower (CultureInfo.InvariantCulture)) != -1) { return false; } else { return IsValidLanguageIndependentIdentifier(value); } } // Generate a direction expression. protected override void GenerateDirectionExpression (CodeDirectionExpression e) { if(e.Direction == FieldDirection.Out || e.Direction == FieldDirection.Ref) { Output.Write("AddressOf "); } GenerateExpression(e.Expression); } // Output a field direction value. protected override void OutputDirection(FieldDirection dir) { if(dir == FieldDirection.Out) { Output.Write("ByRef "); } else if(dir == FieldDirection.Ref) { Output.Write("ByRef "); } else { Output.Write("ByVal "); } } // Output a field scope modifier. protected override void OutputFieldScopeModifier (MemberAttributes attributes) { if((attributes & MemberAttributes.VTableMask) == MemberAttributes.New) { Output.Write("Shadows "); } if((attributes & MemberAttributes.ScopeMask) == MemberAttributes.Static) { Output.Write("Shared "); } else if((attributes & MemberAttributes.ScopeMask) == MemberAttributes.Const) { Output.Write("Const "); } } // Output a member access modifier. protected override void OutputMemberAccessModifier (MemberAttributes attributes) { String access; switch(attributes & MemberAttributes.AccessMask) { case MemberAttributes.Assembly: case MemberAttributes.FamilyAndAssembly: access = "Friend "; break; case MemberAttributes.Family: access = "Protected "; break; case MemberAttributes.FamilyOrAssembly: access = "Protected Friend "; break; case MemberAttributes.Private: access = "Private "; break; case MemberAttributes.Public: access = "Public "; break; default: return; } Output.Write(access); } // Output a member scope modifier. protected override void OutputMemberScopeModifier (MemberAttributes attributes) { if((attributes & MemberAttributes.VTableMask) == MemberAttributes.New) { Output.Write("Shadows "); } switch(attributes & MemberAttributes.ScopeMask) { case MemberAttributes.Abstract: Output.Write("MustOverride "); break;; case MemberAttributes.Final: break;; case MemberAttributes.Static: Output.Write("Shared "); break;; case MemberAttributes.Override: Output.Write("Overrides "); break;; default: { if((attributes & MemberAttributes.AccessMask) == MemberAttributes.Public || (attributes & MemberAttributes.AccessMask) == MemberAttributes.Family) { Output.Write("Overridable "); } } break; } } // Output a binary operator. protected override void OutputOperator(CodeBinaryOperatorType op) { String oper; switch(op) { case CodeBinaryOperatorType.Add: oper = "+"; break; case CodeBinaryOperatorType.Subtract: oper = "-"; break; case CodeBinaryOperatorType.Multiply: oper = "*"; break; case CodeBinaryOperatorType.Divide: oper = "/"; break; case CodeBinaryOperatorType.Modulus: oper = "Mod"; break; case CodeBinaryOperatorType.Assign: oper = "="; break; case CodeBinaryOperatorType.IdentityInequality: oper = "<>"; break; case CodeBinaryOperatorType.IdentityEquality: oper = "=="; break; case CodeBinaryOperatorType.ValueEquality: oper = "="; break; case CodeBinaryOperatorType.BitwiseOr: oper = "Or"; break; case CodeBinaryOperatorType.BitwiseAnd: oper = "And"; break; case CodeBinaryOperatorType.BooleanOr: oper = "AndAlso"; break; case CodeBinaryOperatorType.BooleanAnd: oper = "OrElse"; break; case CodeBinaryOperatorType.LessThan: oper = "<"; break; case CodeBinaryOperatorType.LessThanOrEqual: oper = "<="; break; case CodeBinaryOperatorType.GreaterThan: oper = ">"; break; case CodeBinaryOperatorType.GreaterThanOrEqual: oper = ">="; break; default: return; } Output.Write(oper); } // Output a type. protected override void OutputType(CodeTypeReference typeRef) { Output.Write(GetTypeOutput(typeRef)); } // Output the attributes for a type. protected override void OutputTypeAttributes (TypeAttributes attributes, bool isStruct, bool isEnum) { switch(attributes & TypeAttributes.VisibilityMask) { case TypeAttributes.NestedPrivate: Output.Write("Private "); break; case TypeAttributes.Public: case TypeAttributes.NestedPublic: Output.Write("Public "); break; } if(isStruct) { Output.Write("Structure "); } else if(isEnum) { Output.Write("Enum "); } else { if((attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface) { Output.Write("Interface "); } else { if((attributes & TypeAttributes.Sealed) != 0) { Output.Write("NotInheritable "); } if((attributes & TypeAttributes.Abstract) != 0) { Output.Write("MustInherit "); } Output.Write("Class "); } } } // Output a type name pair. protected override void OutputTypeNamePair (CodeTypeReference typeRef, String name) { OutputIdentifier(name); Output.Write(" As "); OutputType(typeRef); } // Quote a snippet string. protected override String QuoteSnippetString(String value) { return "\"" + value.Replace("\"", "\"\"") + "\""; } // Determine if this code generator supports a particular // set of generator options. protected override bool Supports(GeneratorSupport supports) { return ((supports & (GeneratorSupport)0x001FFFFF) == supports); }}; // class VBCodeCompiler#endif // CONFIG_CODEDOM}; // namespace System.CodeDom.Compiler
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?