/// <summary> /// Determines if the specified type is a ResourceManager type that can /// be handled by this resolver. /// </summary> /// <param name="type">The type that will be checked if it is a ResourceManager.</param> /// <param name="sourceFileName">The name of the source code file where the reference to this type occurs.</param> static bool IsResourceManager(IReturnType type, string sourceFileName) { IProject p = ProjectFileDictionaryService.GetProjectForFile(sourceFileName); IProjectContent pc; if (p == null) { pc = ParserService.CurrentProjectContent; } else { pc = ResourceResolverService.GetProjectContent(p); } if (pc == null) { return(false); } IClass c = type.GetUnderlyingClass(); if (c == null) { return(false); } IClass resourceManager = pc.GetClass("System.Resources.ResourceManager", 0); if (resourceManager == null) { return(false); } return(c.CompareTo(resourceManager) == 0 || c.IsTypeInInheritanceTree(resourceManager)); }
/// <summary> /// Gets the type parameter that was passed to a certain base class. /// For example, when <paramref name="returnType"/> is Dictionary(of string, int) /// this method will return KeyValuePair(of string, int) /// </summary> public static IReturnType GetTypeParameterPassedToBaseClass(IReturnType parentType, IClass baseClass, int baseClassTypeParameterIndex) { if (!parentType.IsConstructedReturnType) { return(null); } ConstructedReturnType returnType = parentType.CastToConstructedReturnType(); IClass c = returnType.GetUnderlyingClass(); if (c == null) { return(null); } if (baseClass.CompareTo(c) == 0) { if (baseClassTypeParameterIndex >= returnType.TypeArguments.Count) { return(null); } return(returnType.TypeArguments[baseClassTypeParameterIndex]); } foreach (IReturnType baseType in c.BaseTypes) { if (baseClass.CompareTo(baseType.GetUnderlyingClass()) == 0) { if (!baseType.IsConstructedReturnType) { return(null); } ConstructedReturnType baseTypeCRT = baseType.CastToConstructedReturnType(); if (baseClassTypeParameterIndex >= baseTypeCRT.TypeArguments.Count) { return(null); } IReturnType result = baseTypeCRT.TypeArguments[baseClassTypeParameterIndex]; if (returnType.TypeArguments != null) { result = ConstructedReturnType.TranslateType(result, returnType.TypeArguments, false); } return(result); } } return(null); }
/// <summary> /// Gets the type parameter that was passed to a certain base class. /// For example, when <paramref name="returnType"/> is Dictionary(of string, int) /// this method will return KeyValuePair(of string, int) /// </summary> public static IReturnType GetTypeParameterPassedToBaseClass(IReturnType parentType, IClass baseClass, int baseClassTypeParameterIndex) { foreach (IReturnType rt in GetTypeInheritanceTree(parentType)) { ConstructedReturnType crt = rt.CastToConstructedReturnType(); if (crt != null && baseClass.CompareTo(rt.GetUnderlyingClass()) == 0) { if (baseClassTypeParameterIndex < crt.TypeArguments.Count) { return(crt.TypeArguments[baseClassTypeParameterIndex]); } } } return(null); }
/// <summary> /// Gets the type parameter that was passed to a certain base class. /// For example, when <paramref name="returnType"/> is Dictionary(of string, int) /// this method will return KeyValuePair(of string, int) /// </summary> public static IReturnType GetTypeParameterPassedToBaseClass(IReturnType parentType, IClass baseClass, int baseClassTypeParameterIndex) { if (!parentType.IsConstructedReturnType) return null; ConstructedReturnType returnType = parentType.CastToConstructedReturnType(); IClass c = returnType.GetUnderlyingClass(); if (c == null) return null; if (baseClass.CompareTo(c) == 0) { if (baseClassTypeParameterIndex >= returnType.TypeArguments.Count) return null; return returnType.TypeArguments[baseClassTypeParameterIndex]; } foreach (IReturnType baseType in c.BaseTypes) { if (baseClass.CompareTo(baseType.GetUnderlyingClass()) == 0) { if (!baseType.IsConstructedReturnType) return null; ConstructedReturnType baseTypeCRT = baseType.CastToConstructedReturnType(); if (baseClassTypeParameterIndex >= baseTypeCRT.TypeArguments.Count) return null; IReturnType result = baseTypeCRT.TypeArguments[baseClassTypeParameterIndex]; if (returnType.TypeArguments != null) { result = ConstructedReturnType.TranslateType(result, returnType.TypeArguments, false); } return result; } } return null; }