public static void WriteTo(this ITypeDefOrRef type, ITextOutput writer, ILNameSyntax syntax = ILNameSyntax.Signature) { if (type is TypeSpec) { WriteTo(((TypeSpec)type).TypeSig, writer, syntax); return; } string name = PrimitiveTypeName(type.FullName); if (syntax == ILNameSyntax.ShortTypeName) { if (name != null) { writer.Write(name); } else { writer.WriteReference(Escape(type.Name), type); } } else if ((syntax == ILNameSyntax.Signature || syntax == ILNameSyntax.SignatureNoNamedTypeParameters) && name != null) { writer.Write(name); } else { if (syntax == ILNameSyntax.Signature || syntax == ILNameSyntax.SignatureNoNamedTypeParameters) { writer.Write(type.IsValueType ? "valuetype " : "class "); } ITypeDefOrRef declType = type.GetDeclaringType(); if (declType != null) { declType.WriteTo(writer, ILNameSyntax.TypeName); writer.Write('/'); writer.WriteReference(Escape(type.Name), type); } else { if (!(type is TypeDef) && type.Scope != null) { writer.Write("[{0}]", Escape(type.Scope.GetScopeName())); } writer.WriteReference(Escape(type.FullName), type); } } }
public static bool IsReferencedBy(TypeDef type, ITypeDefOrRef typeRef) { // TODO: move it to a better place after adding support for more cases. if (type == null) { throw new ArgumentNullException("type"); } if (typeRef == null) { throw new ArgumentNullException("typeRef"); } if (type == typeRef) { return(true); } if (type.Name != typeRef.Name) { return(false); } if (type.Namespace != typeRef.Namespace) { return(false); } var declType = typeRef.GetDeclaringType(); if (type.DeclaringType != null || declType != null) { if (type.DeclaringType == null || declType == null) { return(false); } if (!IsReferencedBy(type.DeclaringType, declType)) { return(false); } } return(true); }