public static string ToCodeString(this TypeModifiers modifiers) { var segments = new List <string>(); if ((modifiers & TypeModifiers.Private) != 0) { segments.Add("private"); } if ((modifiers & TypeModifiers.Protected) != 0) { segments.Add("protected"); } if ((modifiers & TypeModifiers.Internal) != 0) { segments.Add("internal"); } if ((modifiers & TypeModifiers.Public) != 0) { segments.Add("public"); } if ((modifiers & TypeModifiers.Abstract) != 0) { segments.Add("abstract"); } if ((modifiers & TypeModifiers.Virtual) != 0) { segments.Add("virtual"); } if ((modifiers & TypeModifiers.Sealed) != 0) { segments.Add("sealed"); } return(string.Join(" ", segments)); }
public TypeReferenceNode(string name, TypeClassification classification, TypeModifiers modifiers, TypeReferenceNode inner, Token token, int tokenIndex) : base(token, tokenIndex) { Name = name; Classification = classification; Modifiers = modifiers; InnerType = inner; }
/// <summary> /// Parses a type definition. /// </summary> /// <param name="access">The access.</param> /// <param name="typeAttributes">The type attributes.</param> /// <param name="elementType">Type of the element.</param> /// <returns>A type code element.</returns> private TypeElement ParseType( CodeAccess access, TypeModifiers typeAttributes, TypeElementType elementType) { TypeElement typeElement = new TypeElement(); EatWhiteSpace(); string className = CaptureWord(); typeElement.Name = className; typeElement.Access = access; typeElement.Type = elementType; typeElement.TypeModifiers = typeAttributes; if (elementType == TypeElementType.Enum) { EatLineContinuation(); if (NextChar == VBKeyword.As[0]) { EatWord(VBKeyword.As); string interfaceName = CaptureTypeName(); InterfaceReference interfaceReference = new InterfaceReference(interfaceName, InterfaceReferenceType.None); typeElement.AddInterface(interfaceReference); } string enumText = ParseBlock(VBKeyword.Enumeration); // TODO: Parse enum values as fields typeElement.BodyText = enumText; } else { EatWhiteSpace(); bool isGeneric = TryReadChar(VBSymbol.BeginParameterList); if (isGeneric) { EatWord(VBKeyword.Of, "Expected Of"); this.ParseTypeParameters(typeElement); } EatWhiteSpace(); // // Parse child elements // List<ICodeElement> childElements = ParseElements(typeElement); foreach (ICodeElement childElement in childElements) { typeElement.AddChild(childElement); } EatWhiteSpace(); string elementTypeString = EnumUtilities.ToString(elementType); EatWord(elementTypeString, "Expected End " + elementTypeString); } return typeElement; }
/// <summary> /// Parses a type definition. /// </summary> /// <param name="access">Type accessibility.</param> /// <param name="typeAttributes">Type modifiers.</param> /// <param name="elementType">Type element type.</param> /// <returns>Type code element.</returns> private TypeElement ParseType( CodeAccess access, TypeModifiers typeAttributes, TypeElementType elementType) { TypeElement typeElement = new TypeElement(); EatWhiteSpace(); string className = CaptureWord(); typeElement.Name = className; typeElement.Access = access; typeElement.Type = elementType; typeElement.TypeModifiers = typeAttributes; EatWhiteSpace(); if (elementType == TypeElementType.Enum) { EatWhiteSpace(); if (NextChar == CSharpSymbol.TypeImplements) { TryReadChar(); string interfaceName = CaptureTypeName(); InterfaceReference interfaceReference = new InterfaceReference(interfaceName, InterfaceReferenceType.None); typeElement.AddInterface(interfaceReference); } string enumText = ParseBlock(true, typeElement); // TODO: Parse enum values as fields typeElement.BodyText = enumText; } else { bool isGeneric = TryReadChar(CSharpSymbol.BeginGeneric); if (isGeneric) { string[] typeParameterNames = ParseAliasList(); foreach (string typeParameterName in typeParameterNames) { TypeParameter typeParameter = new TypeParameter(); typeParameter.Name = typeParameterName; typeElement.AddTypeParameter(typeParameter); } EatWhiteSpace(); if (!TryReadChar(CSharpSymbol.EndGeneric)) { this.OnParseError("Expected " + CSharpSymbol.EndGeneric); } } EatWhiteSpace(); bool implements = TryReadChar(CSharpSymbol.TypeImplements); if (implements) { string[] typeList = ParseAliasList(); foreach (string type in typeList) { InterfaceReference interfaceReference = new InterfaceReference(type, InterfaceReferenceType.None); typeElement.AddInterface(interfaceReference); } } EatWhiteSpace(); ParseTypeParameterConstraints(typeElement); // Associate any additional comments in the type definition with the type. ReadOnlyCollection<ICommentElement> extraComments = ParseComments(); foreach (ICommentElement comment in extraComments) { typeElement.AddHeaderComment(comment); } EatChar(CSharpSymbol.BeginBlock); EatWhiteSpace(); if (NextChar != CSharpSymbol.EndBlock) { // // Parse child elements // List<ICodeElement> childElements = ParseElements(typeElement); foreach (ICodeElement childElement in childElements) { typeElement.AddChild(childElement); } } EatChar(CSharpSymbol.EndBlock); } // // Types allow a trailing semi-colon // EatTrailingEndOfStatement(); return typeElement; }
private void InitializeFromType(Type type) { Kind = GetTypeKind(type); Modifiers = GetTypeModifiers(type); }
/// <summary>Initializes a new instance of the <seealso cref="TypeDefinitionInfo"/> class from a type kind and the type modifiers.</summary> /// <param name="kind">The kind of the type.</param> /// <param name="modifiers">The modifiers of the type.</param> public TypeDefinitionInfo(TypeKind kind, TypeModifiers modifiers) { Kind = kind; Modifiers = modifiers; }