/// <summary> /// Converts the selected type into a delegate, transfering all applicable data. /// </summary> /// <remarks> /// If the <paramref name="name"/> refers to a nested type descendent, that type is the one converted. /// The nested type is removed from its parent and the new delegate is added in its place /// </remarks> /// <param name="name">The fully qualified name of the delegate.</param> /// <returns>The new delegate, or null if the type is not found.</returns> public DotNetDelegate ToDelegate(DotNetQualifiedName name) { if (Is(name)) { return(ToDelegate()); } else if (IsDirectChild(name)) { DotNetType subtype = (DotNetType)GetDirectChild(name); DotNetDelegate _delegate = subtype.ToDelegate(); NestedTypes.Remove(subtype); Delegates.Add(_delegate); return(_delegate); } else { foreach (DotNetType nestedType in NestedTypes) { if (nestedType.Owns(name)) { return(nestedType.ToDelegate(name)); } } } return(null); }
/// <summary> /// Parse .Net XML documentation for Type data. /// </summary> /// <param name="memberElement">Expects tag name "member".</param> /// <example><![CDATA[<member name="T:Namespace.Type"></member>]]></example> public static DotNetType FromVisualStudioXml(XElement memberElement) { DotNetQualifiedClassName name = DotNetQualifiedClassName.FromVisualStudioXml(memberElement.GetAttributeValue("name")); DotNetType type = new DotNetType(name); type.ParseVisualStudioXmlDocumentation(memberElement); return(type); }
private DotNetMember FindMember(DotNetQualifiedName name) { DotNetType type = Types.FirstOrDefault(x => x.Is(name) || x.Owns(name)); if (type == null) { return(Delegates.FirstOrDefault(x => x.Is(name))); } return(type.FindMember(name)); }
private DotNetType FindType(DotNetQualifiedName name) { DotNetType type = Types.FirstOrDefault(x => x.Is(name) || x.Owns(name)); if (type == null) { return(null); } return(type.FindType(name)); }
private void LoadMembersInfoFromXml(XDocument document) { XElement membersElement = document.Root.Elements("members").FirstOrDefault(); if (membersElement == null) { return; } foreach (XElement memberElement in membersElement.Elements("member")) { XAttribute nameAttribute = memberElement.Attribute("name"); if (nameAttribute == null) { continue; } switch (nameAttribute.Value.Substring(0, 2)) { case "T:": DotNetType type = DotNetType.FromVisualStudioXml(memberElement); if (IsNestedType(type)) { AddMemberToType(type); } else { Types.Add(type); } break; case "M:": DotNetMethod method = DotNetMethod.FromVisualStudioXml(memberElement); AddMemberToType(method); break; case "F:": DotNetField field = DotNetField.FromVisualStudioXml(memberElement); AddMemberToType(field); break; case "P:": DotNetProperty property = DotNetProperty.FromVisualStudioXml(memberElement); AddMemberToType(property); break; case "E:": DotNetEvent eventMember = DotNetEvent.FromVisualStudioXml(memberElement); AddMemberToType(eventMember); break; } } }
/// <summary> /// Returns the selected type, whether it is the current type or one of its nested type descendents. Returns null if the type is not found. /// </summary> public DotNetType FindType(DotNetQualifiedName name) { if (this.Is(name)) { return(this); } DotNetType type = NestedTypes.FirstOrDefault(x => x.Is(name) || x.Owns(name)); if (type == null) { return(null); } return(type.FindType(name)); }
private void AddAssemblyInfoToType(Type type) { DotNetQualifiedName qualifiedName = DotNetQualifiedName.FromAssemblyInfo(type); DotNetType dotNetType = Types.FirstOrDefault(x => x.Is(qualifiedName) || x.Owns(qualifiedName)); if (dotNetType == null) { return; //no error if type is not found } if (type.IsDelegate()) { ConvertTypeToDelegate(type, qualifiedName, dotNetType); return; } dotNetType.AddAssemblyInfo(type, qualifiedName); }
/// <summary> /// Returns the selected method, if it exists in this type. /// </summary> /// <param name="FindType">Function that returns the selected type from all known types in the assembly.</param> /// <param name="methodName">Name of method, local to this type.</param> public DotNetMethod FindInheritedMethod(Func <DotNetQualifiedName, DotNetType> FindType, DotNetQualifiedMethodName methodName) { DotNetMethod method = Methods.FirstOrDefault(m => m.MatchesLocalSignature(methodName)); if (method != null) { return(method); } if (BaseType != null) { DotNetType baseType = FindType(BaseType.Name); if (baseType != null) { return(baseType.FindInheritedMethod(FindType, methodName)); } } return(null); }
/// <summary> /// Returns the selected event, if it exists in this type. /// </summary> /// <param name="FindType">Function that returns the selected type from all known types in the assembly.</param> /// <param name="localName">Name of event, local to this type.</param> public DotNetEvent FindInheritedEvent(Func <DotNetQualifiedName, DotNetType> FindType, string localName) { DotNetEvent _event = Events.FirstOrDefault(e => e.Name.LocalName == localName); if (_event != null) { return(_event); } if (BaseType != null) { DotNetType baseType = FindType(BaseType.Name); if (baseType != null) { return(baseType.FindInheritedEvent(FindType, localName)); } } return(null); }
/// <summary> /// Returns the selected property, if it exists in this type. /// </summary> /// <param name="FindType">Function that returns the selected type from all known types in the assembly.</param> /// <param name="localName">Name of property, local to this type.</param> public DotNetProperty FindInheritedProperty(Func <DotNetQualifiedName, DotNetType> FindType, string localName) { DotNetProperty property = Properties.FirstOrDefault(p => p.Name.LocalName == localName); if (property != null) { return(property); } if (BaseType != null) { DotNetType baseType = FindType(BaseType.Name); if (baseType != null) { return(baseType.FindInheritedProperty(FindType, localName)); } } return(null); }
/// <summary> /// Returns the selected field, if it exists in this type. /// </summary> /// <param name="FindType">Function that returns the selected type from all known types in the assembly.</param> /// <param name="localName">Name of field, local to this type.</param> public DotNetField FindInheritedField(Func <DotNetQualifiedName, DotNetType> FindType, string localName) { DotNetField field = Fields.FirstOrDefault(f => f.Name.LocalName == localName); if (field != null) { return(field); } if (BaseType != null) { DotNetType baseType = FindType(BaseType.Name); if (baseType != null) { return(baseType.FindInheritedField(FindType, localName)); } } return(null); }
private void ConvertTypeToDelegate(Type type, DotNetQualifiedName qualifiedName, DotNetType dotNetType) { DotNetDelegate _delegate = dotNetType.ToDelegate(qualifiedName); if (dotNetType.Is(qualifiedName)) { Types.Remove(dotNetType); Delegates.Add(_delegate); } _delegate.AddAssemblyInfo(type); }
private bool IsNestedType(DotNetType type) { return(Types.Any(t => t.Owns(type))); }
/// <summary> /// For all "inheritdoc" comments, replace the inheritance comment with the inherited comments. /// </summary> /// <remarks> /// Classes can inherit from their base class (or the base class's base, etc). /// Interfaces can inherit from interfaces. /// Class members can inherit from their base class or from interfaces. /// </remarks> /// <param name="FindType">Function that returns the selected type from all known types in the assembly.</param> /// <param name="inheritancePath">List of types or members inheriting from each other, from top level to bottom level. Used to avoid loops.</param> public void ResolveInheritedComments(Func <DotNetQualifiedName, DotNetType> FindType, List <DotNetQualifiedName> inheritancePath = null) { if (inheritancePath == null) { inheritancePath = new List <DotNetQualifiedName>(); } if (inheritancePath.Contains(this.Name)) { return; //inheritance loop } DotNetType baseType = null; if (BaseType != null) { baseType = FindType(BaseType.Name); if (baseType != null && baseType.InheritsDocumentation) { List <DotNetQualifiedName> copiedInheritancePath = inheritancePath.Select(x => x).ToList(); copiedInheritancePath.Add(this.Name); baseType.ResolveInheritedComments(FindType, copiedInheritancePath); } } List <DotNetType> baseInterfaces = new List <DotNetType>(); foreach (DotNetBaseType implementedInterface in ImplementedInterfaces) { DotNetType baseInterface = FindType(implementedInterface.Name); if (baseInterface != null) { baseInterfaces.Add(baseInterface); if (baseInterface.InheritsDocumentation) { List <DotNetQualifiedName> copiedInheritancePath = inheritancePath.Select(x => x).ToList(); copiedInheritancePath.Add(this.Name); baseInterface.ResolveInheritedComments(FindType, copiedInheritancePath); } } } if (this.InheritsDocumentation && baseType != null) { this.CopyComments(baseType); } if (baseType != null) { foreach (DotNetField field in Fields) { if (!field.InheritsDocumentation) { continue; } DotNetField baseField = baseType.FindInheritedField(FindType, field.Name.LocalName); if (baseField != null) { field.CopyComments(baseField); } } } foreach (DotNetProperty property in Properties) { if (!property.InheritsDocumentation) { continue; } if (baseType != null) { DotNetProperty baseProperty = baseType.FindInheritedProperty(FindType, property.Name.LocalName); if (baseProperty != null) { property.CopyComments(baseProperty); continue; } } foreach (DotNetType baseInterface in baseInterfaces) { if (property.Name.ExplicitInterface != null && property.Name.ExplicitInterface != baseInterface.Name) { continue; } DotNetProperty baseProperty = baseInterface.FindInheritedProperty(FindType, property.Name.LocalName); if (baseProperty != null) { property.CopyComments(baseProperty); break; } } } foreach (DotNetEvent _event in Events) { if (!_event.InheritsDocumentation) { continue; } if (baseType != null) { DotNetEvent baseEvent = baseType.FindInheritedEvent(FindType, _event.Name.LocalName); if (baseEvent != null) { _event.CopyComments(baseEvent); continue; } } } foreach (DotNetMethod method in Methods) { if (!method.InheritsDocumentation) { continue; } if (baseType != null) { DotNetMethod baseMethod = baseType.FindInheritedMethod(FindType, method.MethodName); if (baseMethod != null) { method.CopyComments(baseMethod); continue; } } foreach (DotNetType baseInterface in baseInterfaces) { if (method.Name.ExplicitInterface != null && method.Name.ExplicitInterface != baseInterface.Name) { continue; } DotNetMethod baseMethod = baseInterface.FindInheritedMethod(FindType, method.MethodName); if (baseMethod != null) { method.CopyComments(baseMethod); break; } } } foreach (DotNetType nestedType in NestedTypes) { nestedType.ResolveInheritedComments(FindType); } }
/// <summary> /// Load additional information from the assembly for this type. /// </summary> private void AddAssemblyInfo(Type type) { if (type.Attributes.IsAbstract()) { Category = TypeCategory.Abstract; } if (type.Attributes.IsStatic()) { Category = TypeCategory.Static; } if (type.Attributes.IsInterface()) { Category = TypeCategory.Interface; } if (type.IsEnum()) { Category = TypeCategory.Enum; } if (type.IsException()) { Category = TypeCategory.Exception; } if (type.IsValueType && !type.IsEnum()) { Category = TypeCategory.Struct; } if (Category == TypeCategory.Unknown) { Category = TypeCategory.Normal; } IsSealed = type.IsSealed; ClassName.AddAssemblyInfo(type); if (type.BaseType != null) { BaseType = new DotNetBaseType(type.BaseType); } Type[] implementedInterfaces = type.GetInterfaces(); if (implementedInterfaces != null) { foreach (Type interfaceType in implementedInterfaces) { ImplementedInterfaces.Add(new DotNetBaseType(interfaceType)); } } foreach (FieldInfo fieldInfo in type.GetDeclaredFields()) { DotNetField field = Fields.FirstOrDefault(f => fieldInfo.Name == f.Name.LocalName); if (field == null) { continue; } field.AddAssemblyInfo(fieldInfo); } foreach (PropertyInfo propertyInfo in type.GetDeclaredProperties().Where(x => x.GetGetMethod() == null || x.GetGetMethod().GetParameters().Count() == 0)) { DotNetProperty property = Properties.FirstOrDefault(p => propertyInfo.Name == DotNetQualifiedName.Combine(p.Name.ExplicitInterface, p.Name.LocalName)); if (property == null) { continue; } property.AddAssemblyInfo(propertyInfo); } foreach (PropertyInfo propertyInfo in type.GetDeclaredProperties().Where(x => x.GetGetMethod() != null && x.GetGetMethod().GetParameters().Count() > 0)) { DotNetIndexer indexer = Properties.OfType <DotNetIndexer>().Cast <DotNetIndexer>().FirstOrDefault(i => i.MatchesSignature(propertyInfo.GetGetMethod())); if (indexer == null) { continue; } indexer.AddAssemblyInfo(propertyInfo); } foreach (MethodInfo methodInfo in type.GetDeclaredMethods()) { DotNetMethod method = Methods.FirstOrDefault(m => m.MatchesSignature(methodInfo)); if (method == null) { continue; } if (methodInfo.Attributes.IsPrivate() && method.Name.ExplicitInterface == null) { Methods.Remove(method); continue; } method.AddAssemblyInfo(methodInfo); } foreach (ConstructorInfo constructorInfo in type.GetDeclaredConstructors()) { DotNetMethodConstructor method = Methods.OfType <DotNetMethodConstructor>().Cast <DotNetMethodConstructor>().FirstOrDefault(m => m.MatchesArguments(constructorInfo.GetParameters())); if (method == null) { continue; } method.AddAssemblyInfo(constructorInfo); } foreach (EventInfo eventInfo in type.GetDeclaredEvents()) { DotNetEvent e = Events.FirstOrDefault(m => m.Name.LocalName == eventInfo.Name); if (e == null) { continue; } e.AddAssemblyInfo(eventInfo); } foreach (Type nestedType in type.GetDeclaredNestedTypes()) { DotNetQualifiedName qualifiedName = DotNetQualifiedName.FromAssemblyInfo(nestedType); DotNetType dotNetNestedType = NestedTypes.FirstOrDefault(x => x.Owns(qualifiedName)); if (dotNetNestedType == null) { continue; } dotNetNestedType.AddAssemblyInfo(type, qualifiedName); } PushGenericTypes(); }