private void AppendProperty(DescriptionBuilder sb, NetBrowserManager manager, PropertyInfo property) { // Properties have many of the same attributes as methods, but these attributes are declared // on the accessors, not on the properties themselves. MethodInfo[] accessors = property.GetAccessors(true); Debug.Assert(accessors.Length > 0, "Unable to get the accessors for property '" + property.DeclaringType.ToString() + "." + property.Name + "' - this property should not have been displayed."); AppendMethodAttributes(sb, accessors[0]); NetTypeBrowserInfo.AppendParameterTypeDisplayName(manager, sb, property.PropertyType, false, true); sb.Append(" "); sb.AppendName(property.Name); if (property.CanRead) { if (property.CanWrite) { sb.Append(" [ get, set ]"); } else { sb.Append(" [ get ]"); } } else if (property.CanWrite) { sb.Append(" [ set ]"); } else { Debug.Fail("Property '" + property.Name + "' is not readable and not writeable."); } // Show indexer parameters as well (which the VS.NET object browser doesn't do). ParameterInfo[] indexers = property.GetIndexParameters(); if (indexers.Length > 0) { sb.Append(" ( "); AppendParameters(sb, manager, indexers); sb.Append(" )"); } }
public void BuilString(DescriptionBuilder context) { context.Append(ToString()); }
internal static void AppendParameterTypeDisplayName(NetBrowserManager manager, DescriptionBuilder sb, Type type, bool ignoreRef, bool link) { NetBrowserSettings settings = (NetBrowserSettings)manager.Settings; if (type.HasElementType) { if (type.IsByRef) { if (!ignoreRef) { sb.Append(settings.GetKeyword("Type.IsByRef")); sb.Append(" "); } AppendParameterTypeDisplayName(manager, sb, type.GetElementType(), ignoreRef, link); } else if (type.IsArray) { AppendParameterTypeDisplayName(manager, sb, type.GetElementType(), ignoreRef, link); sb.Append(settings.GetKeyword(NetBrowserSettings.KeywordArrayStart)); int dimensions = type.GetArrayRank(); for (int index = 1; index < dimensions; index++) { sb.Append(","); } sb.Append(settings.GetKeyword(NetBrowserSettings.KeywordArrayEnd)); } else if (type.IsPointer) { AppendParameterTypeDisplayName(manager, sb, type.GetElementType(), ignoreRef, link); sb.Append(" *"); } else { throw new ApplicationException("Type '" + type.Name + "' has element type, but is not a" + " reference type, array or pointer."); } } else { string keyword = ((NetBrowserSettings)manager.Settings).GetKeyword(type.AssemblyQualifiedName); if (keyword == null) { if (link) { sb.AppendLink(GetTypeDisplayFullName(type), manager.GetTypeInfoForLink( type.Assembly.Location, type.FullName)); } else { sb.Append(GetTypeDisplayFullName(type)); } } else { sb.Append(keyword); // We don't want to make keywords into links } } }
private DescriptionText GetDescription() { try { DescriptionBuilder sb = new DescriptionBuilder(true); IntPtr ptr = IntPtr.Zero; m_typeInfo.ComType.GetTypeAttr(out ptr); try { TYPEATTR typeAttr = (TYPEATTR)Marshal.PtrToStructure(ptr, typeof(TYPEATTR)); // Type GUID and attributes. sb.Append("[ uuid("); sb.Append(typeAttr.guid.ToString().ToUpper()); sb.Append(")"); AppendTypeAttribute(sb, typeAttr, TYPEFLAGS.TYPEFLAG_FAGGREGATABLE); AppendTypeAttribute(sb, typeAttr, TYPEFLAGS.TYPEFLAG_FAPPOBJECT); AppendTypeAttribute(sb, typeAttr, TYPEFLAGS.TYPEFLAG_FCONTROL); AppendTypeAttribute(sb, typeAttr, TYPEFLAGS.TYPEFLAG_FLICENSED); AppendTypeAttribute(sb, typeAttr, TYPEFLAGS.TYPEFLAG_FHIDDEN); AppendTypeAttribute(sb, typeAttr, TYPEFLAGS.TYPEFLAG_FNONEXTENSIBLE); AppendTypeAttribute(sb, typeAttr, TYPEFLAGS.TYPEFLAG_FOLEAUTOMATION); AppendTypeAttribute(sb, typeAttr, TYPEFLAGS.TYPEFLAG_FRESTRICTED); sb.Append(" ]"); sb.EndLine(); // Object type (including interface type for an interface). ObjectType objectType = GetObjectType(typeAttr); if (objectType == ObjectType.Interface) { sb.Append(ComBrowserSettings.GetKeyword(GetInterfaceType(typeAttr))); } else { sb.Append(ComBrowserSettings.GetKeyword(objectType)); } sb.Append(" "); } finally { m_typeInfo.ComType.ReleaseTypeAttr(ptr); } // Name and description. sb.AppendName(Marshal.GetTypeInfoName(m_typeInfo.ComType)); sb.EndFirstLine(); sb.Append(@" Member of "); sb.AppendLink(Namespace.NodeText, Namespace); sb.EndLine(); string description = GetDocString(); if (description != null && description.Length != 0) { sb.AppendHeading("Description:"); sb.Append(description); } return(sb.GetText()); } catch (System.Exception ex) { throw new ApplicationException("Failed to write the type declaration for type '" + Marshal.GetTypeInfoName(m_typeInfo.ComType) + "'.", ex); } }