/// <summary> /// Returns the string indicator for the specified CRef type. /// </summary> /// <param name="type">The type to return the indicator for.</param> /// <returns>The indicator.</returns> /// <exception cref="NotImplementedException"> /// The provided constant in the enumeration <paramref name="type"/> has /// not been implemented. /// </exception> public static string GetIndicatorFor(CRefTypes type) { switch (type) { case CRefTypes.Field: return(CRefConstants.FieldTypeIndicator); case CRefTypes.Method: return(CRefConstants.MethodTypeIndicator); case CRefTypes.Property: return(CRefConstants.PropertyTypeIndicator); case CRefTypes.Type: return(CRefConstants.TypeIndicator); case CRefTypes.Event: return(CRefConstants.EventTypeIndicator); case CRefTypes.Namespace: return(CRefConstants.NamespaceTypeIndicator); case CRefTypes.Error: return(CRefConstants.ErrorTypeIndicator); default: NotImplementedException ex = new NotImplementedException( string.Format(Reflection.Resources.ExceptionMessages.Ex_CRefConstants_NotImplemented, type.ToString()) ); ex.Data["type"] = type; throw ex; } }
// TODO: Implement Events, Delegates /// <summary> /// Private constructor initialises a new instance of the CRefPath class. /// </summary> /// <param name="crefPathType">The cref path type.</param> /// <param name="type">The type information.</param> /// <param name="element">The element name for the path.</param> private CRefPath(CRefTypes crefPathType, TypeRef type, string element) { this.PathType = crefPathType; this.ElementName = element; this.TypeName = type.Name; // work out the namespace if (type is TypeDef) { List <string> elements = new List <string>(); TypeDef container = null; if (((TypeDef)type).ContainingClass != null) { container = (TypeDef)type; do { container = container.ContainingClass; elements.Add(container.Name); } while(container.ContainingClass != null); } if (container != null) { elements.Add(container.Namespace); } else { elements.Add(type.Namespace); } elements.Reverse(); this.Namespace = string.Join(".", elements.ToArray()); } else { this.Namespace = type.Namespace; } }
/// <summary> /// Returns the string indicator for the specified CRef type. /// </summary> /// <param name="type">The type to return the indicator for.</param> /// <returns>The indicator.</returns> /// <exception cref="NotImplementedException"> /// The provided constant in the enumeration <paramref name="type"/> has /// not been implemented. /// </exception> public static string GetIndicatorFor(CRefTypes type) { switch (type) { case CRefTypes.Field: return(CRefConstants.FieldTypeIndicator); case CRefTypes.Method: return(CRefConstants.MethodTypeIndicator); case CRefTypes.Property: return(CRefConstants.PropertyTypeIndicator); case CRefTypes.Type: return(CRefConstants.TypeIndicator); case CRefTypes.Event: return(CRefConstants.EventTypeIndicator); case CRefTypes.Namespace: return(CRefConstants.NamespaceTypeIndicator); case CRefTypes.Error: return(CRefConstants.ErrorTypeIndicator); default: NotImplementedException ex = new NotImplementedException(); ex.Data["type"] = type; throw ex; } }
public void PathTypesShouldBeSetCorrectly(string path, CRefTypes expectedType) { CRefPath converted = CRefPath.Parse(path); Assert.AreEqual(expectedType, converted.PathType); }