using System.Linq; namespace OpenTap { /// /// The default display attribute is used to mark when the display attribute is not specifically added, but just autogenerated /// instead of putting a null value. /// class DefaultDisplayAttribute : DisplayAttribute { static string getMemberName(IReflectionData mem) { // mem.Name has to be something fully qualifiable, but the display attribute name should be something more human friendly. var name = mem.Name; if (name.EndsWith("]]")) { // This is probably a generic C# type. These have the format Namespace.TypeName`N[[assemblyQualifiedNameOfFirstGenericArgument][assemblyQualifiedNameOfSecondGenericArgument]...] var idx = name.LastIndexOf("[["); if(idx >= 0) name = name.Substring(0, idx); } return name.Split('.').Last().Split('+').Last(); } /// Always true for this class. public override bool IsDefaultAttribute() => true; internal static DisplayAttribute GetUntranslatedDisplayAttribute(IReflectionData mem) { DisplayAttribute attr; if (mem is TypeData td) attr = td.Display; else attr = mem.GetAttribute(); if (attr != null) return attr; // auto-generate a display attribute. return new DefaultDisplayAttribute(mem); } public DefaultDisplayAttribute(IReflectionData mem) : base(getMemberName(mem)) { } } }