/// <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 Event data. /// </summary> /// <param name="memberElement">Expects tag name "member".</param> /// <example><![CDATA[<member name="E:Namespace.Type.EventName"></member>]]></example> public static new DotNetEvent FromVisualStudioXml(XElement memberElement) { DotNetQualifiedName name = DotNetQualifiedName.FromVisualStudioXml(memberElement.GetAttributeValue("name")); DotNetEvent eventMember = new DotNetEvent(name); eventMember.ParseVisualStudioXmlDocumentation(memberElement); return eventMember; }
/// <summary> /// Returns a new name object which has been localized to the provided other name. The current object is not altered. /// </summary> public virtual DotNetQualifiedName GetLocalized(DotNetQualifiedName other) { DotNetQualifiedName clone = this.Clone(); clone.Localize(other); return(clone); }
/// <inheritdoc/> public new DotNetReferenceMethodGeneric GetLocalized(DotNetQualifiedName other) { DotNetReferenceMethodGeneric clone = this.Clone(); clone.Localize(other); return(clone); }
/// <summary> /// Returns true if these types match. Does not look at aliases. /// </summary> public bool MatchesSignature(DotNetQualifiedName other) { if (!(other is DotNetReferenceMethodGeneric)) { return(false); } return(genericTypeIndex == (other as DotNetReferenceMethodGeneric).genericTypeIndex); }
/// <summary></summary> public DotNetBaseType(Type type) { Name = DotNetQualifiedName.FromAssemblyInfo(type); if (type.BaseType != null) { BaseType = new DotNetBaseType(type.BaseType); } }
/// <summary> /// Returns true if this member's name matches the provided name. /// </summary> public bool Is(DotNetQualifiedName name) { if (!(name is DotNetQualifiedMethodName)) { return(false); } return(this.MethodName.MatchesSignature(name as DotNetQualifiedMethodName)); }
/// <summary> /// Parse .Net XML documentation for Field data. /// </summary> /// <param name="memberElement">Expects tag name "member".</param> /// <example><![CDATA[<member name="F:Namespace.Type.FieldName"></member>]]></example> public static DotNetField FromVisualStudioXml(XElement memberElement) { DotNetQualifiedName name = DotNetQualifiedName.FromVisualStudioXml(memberElement.GetAttributeValue("name")); DotNetField field = new DotNetField(name); field.ParseVisualStudioXmlDocumentation(memberElement); return(field); }
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)); }
/// <summary>Parses .Net XML documentation cref.</summary> public static new DotNetCommentQualifiedLink FromVisualStudioXml(string cref) { int divider = cref.IndexOf("("); if (divider > -1 || cref.StartsWith("M:")) { return(DotNetCommentMethodLink.FromVisualStudioXml(cref)); } return(new DotNetCommentQualifiedLink(DotNetQualifiedName.FromVisualStudioXml(cref))); }
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); }
/// <inheritdoc /> /// <remarks> /// All generic parameters are also localized. /// </remarks> public override void Localize(DotNetQualifiedName other) { if (FullNamespace == null || other == null) { return; } base.Localize(other); foreach (DotNetQualifiedTypeName p in GenericTypeParameters) { p.Localize(other); } }
/// <summary>Returns true if this Name is nested inside the other Name.</summary> /// <example>"System.Text.RegularExpressions" is within "System.Text" and "System".</example> /// <example>"System" is not within null or empty Name.</example> public bool IsWithin(DotNetQualifiedName other) { if (this.FullNamespace == null || other == null) { return(false); } if (this.FullNamespace == other) { return(true); } return(this.FullNamespace.IsWithin(other)); }
/// <duplicate cref='CompareTo(object)' /> /// With protection against either object being null. public static int Compare(DotNetQualifiedName a, DotNetQualifiedName b) { if (a > b) { return(1); } if (a < b) { return(-1); } return(0); }
/// <summary> /// Names are sorted alphabetically, per namespace, starting with the root. /// </summary> /// <remarks>Explicit interface implementations are considered only as a last resort.</remarks> public virtual int CompareTo(object b) { if (!(b is DotNetQualifiedName)) { return(-1); } if (this.Equals(b)) { return(0); } if (object.ReferenceEquals(this, null)) { return(-1); } if (object.ReferenceEquals(b, null)) { return(1); } DotNetQualifiedName other = (b as DotNetQualifiedName); string[] thisNames = this.ToString().SplitIgnoreNested('.'); string[] otherNames = other.ToString().SplitIgnoreNested('.'); for (int i = 0; i < thisNames.Length; i++) { if (i >= otherNames.Length) { return(1); } if (thisNames[i] == otherNames[i]) { continue; } return(thisNames[i].CompareTo(otherNames[i])); } if (thisNames.Length < otherNames.Length) { return(-1); } if (this.ExplicitInterface != null) { return(this.ExplicitInterface.CompareTo(other.ExplicitInterface)); } if (other.ExplicitInterface != null) { return(-1); } return(0); }
/// <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)); }
/// <summary> /// Parse .Net XML documentation for Indexer data. /// </summary> /// <param name="memberElement">Expects tag name "member".</param> /// <example><![CDATA[<member name="P:Namespace.Type.Item(System.Int32)"></member>]]></example> public static new DotNetIndexer FromVisualStudioXml(XElement memberElement) { string xmlName = memberElement.GetAttributeValue("name"); string xmlParameters = xmlName.Substring(xmlName.IndexOf("(")); xmlName = xmlName.Substring(0, xmlName.IndexOf("(")); DotNetQualifiedName name = DotNetQualifiedName.FromVisualStudioXml(xmlName); List <DotNetParameter> parameters = DotNetQualifiedMethodName.ParametersFromVisualStudioXml(xmlParameters); DotNetIndexer indexer = new DotNetIndexer(name, parameters); indexer.ParseVisualStudioXmlDocumentation(memberElement); return(indexer); }
/// <summary> /// Returns the selected field/property/event/method/delegate/type from this type. /// </summary> private DotNetMember GetDirectChild(DotNetQualifiedName name) { if (name is DotNetQualifiedMethodName) { foreach (DotNetMethod method in Methods) { if (method.MatchesSignature(name as DotNetQualifiedMethodName)) { return(method); } } foreach (DotNetDelegate _delegate in Delegates) { if (_delegate.MatchesSignature(name as DotNetQualifiedMethodName)) { return(_delegate); } } } foreach (DotNetField field in Fields) { if (field.Name.LocalName == name.LocalName) { return(field); } } foreach (DotNetField property in Properties) { if (property.Name.LocalName == name.LocalName) { return(property); } } foreach (DotNetField _event in Events) { if (_event.Name.LocalName == name.LocalName) { return(_event); } } foreach (DotNetType nestedType in NestedTypes) { if (nestedType.Is(name)) { return(nestedType); } } return(null); }
/// <summary> /// Parse .Net XML documentation for Property data. /// </summary> /// <param name="memberElement">Expects tag name "member".</param> /// <example><![CDATA[<member name="P:Namespace.Type.PropertyName"></member>]]></example> public static new DotNetProperty FromVisualStudioXml(XElement memberElement) { string xmlName = memberElement.GetAttributeValue("name"); if (xmlName.IndexOf("(") > -1) { return(DotNetIndexer.FromVisualStudioXml(memberElement)); } DotNetQualifiedName name = DotNetQualifiedName.FromVisualStudioXml(xmlName); DotNetProperty property = new DotNetProperty(name); property.ParseVisualStudioXmlDocumentation(memberElement); return(property); }
/// <summary> /// Returns true if this qualified name is defined within this type or any of its nested type dscendents. /// </summary> public bool Owns(DotNetQualifiedName name) { if (Name.FullName == name.FullNamespace) { return(true); } foreach (DotNetType nestedType in NestedTypes) { if (nestedType.Owns(name)) { return(true); } } return(false); }
/// <summary> /// Simplifies this qualified name based on the <paramref name='other'/> name. /// In other words, removes the portion of the namespace that this and the <paramref name='other'/> have in common. /// Alters the current object. /// </summary> /// <remarks>Will always keep at least the LocalName.</remarks> /// <remarks>Preserves explicit interface implementations.</remarks> /// <example>"System.Collections.Generic.List".Localize("System.Collections") returns "Generic.List".</example> /// <example>"System.Collections.Generic.List".Localize("System.Collections.Standard.List") returns "Standard.List".</example> /// <example>"System.Collections.Generic.List".Localize("System.Collections.Generic.List") returns "List".</example> public virtual void Localize(DotNetQualifiedName other) { if (FullNamespace == null || other == null) { return; } if (FullNamespace == other || other.IsWithin(FullNamespace)) { FullNamespace = null; } else { FullNamespace.Localize(other); } }
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> /// Load additional documentation information from the assembly itself for this type or one of its nested type descendents. /// </summary> public void AddAssemblyInfo(Type type, DotNetQualifiedName name) { if (this.Is(name)) { AddAssemblyInfo(type); return; } foreach (DotNetType nestedType in NestedTypes) { if (nestedType.Is(name) || nestedType.Owns(name)) { nestedType.AddAssemblyInfo(type, name); return; } } //no error if type is not found }
/// <summary> /// Returns deep clone of qualified name. /// </summary> public virtual DotNetQualifiedName Clone() { DotNetQualifiedName clonedFullNamespace = null; if (FullNamespace != null) { clonedFullNamespace = FullNamespace.Clone(); } DotNetQualifiedName clonedExplicitInterface = null; if (ExplicitInterface != null) { clonedExplicitInterface = ExplicitInterface.Clone(); } return(new DotNetQualifiedName(localName, clonedFullNamespace, clonedExplicitInterface)); }
/// <summary> /// Returns the specified member from this type of its nested type descendents. Can return a field, property, event, method, delegate, or type. /// </summary> public DotNetMember FindMember(DotNetQualifiedName name) { if (this.Is(name)) { return(this); } if (IsDirectChild(name)) { return(GetDirectChild(name)); } foreach (DotNetType nestedType in NestedTypes) { if (nestedType.Is(name) || nestedType.Owns(name)) { return(nestedType.FindMember(name)); } } return(null); }
/// <summary>Names converted to strings must match exactly to be considered equal.</summary> public override bool Equals(Object b) { if (!(b is DotNetQualifiedName)) { return(false); } if (object.ReferenceEquals(this, null) && object.ReferenceEquals(b, null)) { return(true); } if (object.ReferenceEquals(this, null) || object.ReferenceEquals(b, null)) { return(false); } DotNetQualifiedName other = (b as DotNetQualifiedName); return(this.LocalName == other.LocalName && this.FullNamespace == other.FullNamespace && this.ExplicitInterface == other.ExplicitInterface); }
/// <summary> /// Parses a .Net XML documentation member name. /// </summary> /// <remarks> /// There is no support for generic types here because .Net XMl documentation does not include member types, just the names. /// </remarks> /// <remarks> /// Does not parse method names; use DotNetQualifiedMethodName.FromVisualStudioXml(string) instead. /// </remarks> /// <example> /// Expected formats: /// - "F:NamespaceA.NamespaceB.MemberC" /// - "P:NamespaceA.NamespaceB.MemberC" /// - "E:NamespaceA.NamespaceB.MemberC" /// - "NamespaceA.NamespaceB.MemberC" /// - "NamespaceA.NamespaceB.InterfaceNamespace#Interface#MemberC" /// </example> /// <param name="name">Name may or may not start with /[FPE]:/</param> private static DotNetQualifiedName MemberNameFromVisualStudioXml(string name) { if (name.StartsWith("F:")) { name = name.Substring(2); } if (name.StartsWith("P:")) { name = name.Substring(2); } if (name.StartsWith("E:")) { name = name.Substring(2); } int divider = name.LastIndexOf('.'); string localName = name; string fullNamespace = null; if (divider != -1) { localName = name.Substring(divider + 1); fullNamespace = name.Substring(0, divider); } DotNetQualifiedName explicitInterface = null; if (localName.Contains("#")) { int lastIndex = localName.LastIndexOf("#"); string interfaceName = localName.Substring(0, lastIndex).Replace("#", "."); explicitInterface = DotNetQualifiedName.FromVisualStudioXml(interfaceName); localName = localName.Substring(lastIndex + 1); } if (String.IsNullOrEmpty(fullNamespace)) { return(new DotNetQualifiedName(localName, explicitInterface)); } return(new DotNetQualifiedName(localName, DotNetQualifiedClassName.FromVisualStudioXml(fullNamespace), explicitInterface)); }
/// <summary></summary> public DotNetDelegate(DotNetQualifiedName name) : base(new DotNetQualifiedMethodName(name)) { Category = MethodCategory.Delegate; }
/// <summary></summary> public DotNetProperty(DotNetQualifiedName name) : base(name) { }