/// <summary> /// The type of the parameter, which might be a generic type parameter (e.g. the T in List of T) /// </summary> /// <returns></returns> public MrType GetParameterType() { var parameterType = Method.MethodSignature.ParameterTypes[_parameterIndex]; if (parameterType.IsGenericParameter) { // E.g. this parameterType is the item's T for List<T>.Add(T item) // We want to get the method's type argument that correponds to this type parameter // Get the parameter type's unmodified name, as a string. // E.g. for the baz in Foo<T>.Bar(T& baz), return "T" var parameterTypeName = MrType.GetUnmodifiedTypeName( parameterType.GetName(), out var isArray, out var isReference, out var isPointer); // Find the method type argument with the same name as this parameter type. var typeArguments = this.Method.DeclaringType.GetGenericArguments(); foreach (var typeArgument in typeArguments) { if (typeArgument.TypeParameterName == parameterTypeName) { // Return the type argument, correctly modified ("T&" rather than "T") parameterType = MrType.Clone(typeArgument, isArray, isReference, isPointer); break; } } } return(parameterType); }
/// <summary> /// Try to find a type in any loaded assembly /// </summary> public bool TryFindMrType(string fullTypeName, out MrType mrType) { mrType = null; // Convert e.g. Byte[] into Byte fullTypeName = MrType.GetUnmodifiedTypeName(fullTypeName, out var arrayRank, out var isReference, out var isPointer); foreach (var assembly in _loadedAssemblies.Values.Union(_implicitAssemblies.Values)) { if (assembly.TryGetType(fullTypeName, out mrType)) { // Convert back if necessary, e.g. Byte into Byte[] if (arrayRank != null || isReference || isPointer) { mrType = MrType.Clone(mrType, arrayRank, isReference, isPointer); } return(true); } } return(false); }