public static void AsTextPropertyInfo(CodeWriter writer, PropertyInfo propertyInfo, RenderFlags flags) { RenderFlags passFlags = flags & ~RenderFlags.Description; if (!flags.HasFlag(RenderFlags.NoPreAnnotations)) { Attribute.AsTextAttributes(writer, propertyInfo); } writer.Write(ModifiersHelpers.AsString(GetPropertyModifiers(propertyInfo))); Type propertyType = propertyInfo.PropertyType; TypeRefBase.AsTextType(writer, propertyType, passFlags); writer.Write(" "); TypeRefBase.AsTextType(writer, propertyInfo.DeclaringType, passFlags); Dot.AsTextDot(writer); if (PropertyInfoUtil.IsIndexed(propertyInfo)) { // Display the actual name instead of 'this' - it will usually be 'Item', but not always, // plus it might have a prefix (if it's an explicit interface implementation). writer.Write(propertyInfo.Name + IndexerDecl.ParseTokenStart); MethodRef.AsTextParameters(writer, propertyInfo.GetIndexParameters(), flags); writer.Write(IndexerDecl.ParseTokenEnd); } else { writer.Write(propertyInfo.Name); } }
public static void AsTextEventInfo(CodeWriter writer, EventInfo eventInfo, RenderFlags flags) { RenderFlags passFlags = flags & ~RenderFlags.Description; if (!flags.HasFlag(RenderFlags.NoPreAnnotations)) { Attribute.AsTextAttributes(writer, eventInfo); } writer.Write(ModifiersHelpers.AsString(GetEventModifiers(eventInfo))); TypeRefBase.AsTextType(writer, eventInfo.EventHandlerType, passFlags); writer.Write(" "); TypeRefBase.AsTextType(writer, eventInfo.DeclaringType, passFlags); writer.Write(Dot.ParseToken + eventInfo.Name); }
/// <summary> /// Parse a <see cref="PropertyDecl"/> or <see cref="EventDecl"/>. /// </summary> public static PropertyDeclBase Parse(Parser parser, CodeObject parent, ParseFlags flags) { // If our parent is a TypeDecl, verify that we have an unused Expression (it can be either an // identifier or a Dot operator for explicit interface implementations). Otherwise, require a // possible type in addition to the Expression. // If it doesn't seem to match the proper pattern, abort so that other types can try parsing it. if ((parent is TypeDecl && parser.HasUnusedExpression) || parser.HasUnusedTypeRefAndExpression) { // If we have an unused 'event' modifier, it's an event, otherwise treat it as a property string eventModifier = ModifiersHelpers.AsString(Modifiers.Event).Trim(); bool isEvent = (Enumerable.Any(parser.Unused, delegate(ParsedObject parsedObject) { return(parsedObject is Token && ((Token)parsedObject).Text == eventModifier); })); return(isEvent ? (PropertyDeclBase) new EventDecl(parser, parent) : new PropertyDecl(parser, parent)); } return(null); }
public static void AsTextConstructorInfo(CodeWriter writer, ConstructorInfo constructorInfo, RenderFlags flags) { RenderFlags passFlags = flags & ~RenderFlags.Description; if (!flags.HasFlag(RenderFlags.NoPreAnnotations)) { Attribute.AsTextAttributes(writer, constructorInfo); } writer.Write(ModifiersHelpers.AsString(GetMethodModifiers(constructorInfo))); Type declaringType = constructorInfo.DeclaringType; AsTextType(writer, declaringType, passFlags); Dot.AsTextDot(writer); if (declaringType != null) { writer.WriteName(declaringType.IsGenericType ? TypeUtil.NonGenericName(declaringType) : declaringType.Name, passFlags); } AsTextMethodParameters(writer, constructorInfo, flags); }
public static void AsTextFieldInfo(CodeWriter writer, FieldInfo fieldInfo, RenderFlags flags) { RenderFlags passFlags = flags & ~RenderFlags.Description; // Skip all details for enum members, including the declaring type since it will always be on the left of the dot if (!(fieldInfo.IsLiteral && fieldInfo.FieldType.IsEnum)) { if (!flags.HasFlag(RenderFlags.NoPreAnnotations)) { Attribute.AsTextAttributes(writer, fieldInfo); } writer.Write(ModifiersHelpers.AsString(GetFieldModifiers(fieldInfo))); Type fieldType = fieldInfo.FieldType; TypeRefBase.AsTextType(writer, fieldType, passFlags); writer.Write(" "); TypeRefBase.AsTextType(writer, fieldInfo.DeclaringType, passFlags); Dot.AsTextDot(writer); } writer.Write(fieldInfo.Name); }