/// <summary> /// Tests whether the specified type is the same type /// as the CodeTypeInfo parameter describes. /// </summary> static bool Is(IType t, CodeTypeInfo cti) { ITypeReference r = t as ITypeReference; if (r != null) { return(Is(r, cti)); } IArrayType a = t as IArrayType; if (a != null && cti != null) { return(Is(a.ElementType, cti.ArrayElementType) && (a.Dimensions.Count == cti.ArrayDimensions || (a.Dimensions.Count == 0 && cti.ArrayDimensions == 1))); } IReferenceType rt = t as IReferenceType; if (rt != null) { return(Is(rt.ElementType, cti)); } IGenericArgument ga = t as IGenericArgument; if (ga != null) { return(true); } return(false); }
/// <summary> /// Tests whether the specified type is the same type /// as the CodeTypeInfo parameter describes. /// </summary> static bool Is(ITypeReference r, CodeTypeInfo cti) { if (r == null || cti == null) { return(false); } int index = cti.TypeNames.Length - 1; do { if (index < 0 || !String.Equals(r.Name, cti.TypeNames[index], StringComparison.InvariantCulture) || r.GenericArguments.Count != cti.TypeArgumentCount[index]) { return(false); } --index; ITypeReference next = r.Owner as ITypeReference; if (next == null) { if (!String.Equals(r.Namespace, cti.Namespace, StringComparison.InvariantCulture)) { return(false); } break; } else { r = next; } } while (true); return(index == -1); }
/// <summary> /// Tests whether the specified type declaration is the same type /// as the CodeTypeInfo parameter describes /// (except for the namespace, which is tested before). /// </summary> static bool Is(ITypeDeclaration t, CodeTypeInfo cti) { if (t == null || cti == null) { return(false); } int index = cti.TypeNames.Length - 1; do { if (index < 0 || !String.Equals(t.Name, cti.TypeNames[index], StringComparison.InvariantCulture) || t.GenericArguments.Count != cti.TypeArgumentCount[index]) { return(false); } --index; } while ((t = t.Owner as ITypeDeclaration) != null); return(index == -1); }