//------------------------------------------------------------ // ReflectionUtil.GetConstructedMethodInfo // /// <summary></summary> /// <param name="compiler"></param> /// <param name="methodSym"></param> /// <param name="aggTypeSym"></param> /// <param name="methTypeArguments"></param> /// <returns></returns> //------------------------------------------------------------ internal static MethodInfo GetConstructedMethodInfo( COMPILER compiler, METHSYM methodSym, AGGTYPESYM aggTypeSym, TypeArray methTypeArguments) { DebugUtil.Assert(compiler != null && compiler.Emitter != null); EMITTER emitter = compiler.Emitter; DebugUtil.Assert(emitter != null && methodSym != null && aggTypeSym != null); SymUtil.EmitParentSym(emitter, aggTypeSym); SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null); emitter.EmitMethodDef(methodSym); Type parentType = aggTypeSym.Type; MethodInfo methodDefInfo = methodSym.MethodInfo; bool isGenericType = parentType.IsGenericType; bool isGenericMethod = methodDefInfo.IsGenericMethod; //-------------------------------------------------------- // (1-1) Non-generic Type, non-generic method //-------------------------------------------------------- if (!isGenericType && !isGenericMethod) { return(methodDefInfo); } //-------------------------------------------------------- // Parameter types //-------------------------------------------------------- TypeArray paramTypeArray = methodSym.ParameterTypes; TypeArray paramTypeArray2 = null; Type[] paramTypes = null; if (paramTypeArray != null && paramTypeArray.Count > 0) { paramTypeArray2 = compiler.MainSymbolManager.SubstTypeArray( paramTypeArray, aggTypeSym.AllTypeArguments, methTypeArguments, SubstTypeFlagsEnum.NormNone); paramTypes = SymUtil.GetSystemTypesFromTypeArray( paramTypeArray2, methodSym.ClassSym, methodSym); } else { paramTypes = Type.EmptyTypes; } //-------------------------------------------------------- // (1-2) Non-generic Type, generic method //-------------------------------------------------------- if (!isGenericType) { DebugUtil.Assert(methTypeArguments != null); Exception ex = null; Type[] typeArgs = SymUtil.GetSystemTypesFromTypeArray( methTypeArguments, methodSym.ClassSym, methodSym); return(ReflectionUtil.GetGenericMethod( methodDefInfo, typeArgs, out ex)); } //-------------------------------------------------------- // (2) Generic Type //-------------------------------------------------------- else { string methodName = methodDefInfo.Name; MethodInfo cstrMethInfo = null; Exception ex = null; try { cstrMethInfo = parentType.GetMethod(methodName, paramTypes); } catch (NotSupportedException) { cstrMethInfo = GetMethodInfo(parentType, methodDefInfo, out ex); } if (!isGenericMethod) { return(cstrMethInfo); } DebugUtil.Assert(methTypeArguments != null); Type[] typeArgs = SymUtil.GetSystemTypesFromTypeArray( methTypeArguments, methodSym.ClassSym, methodSym); return(ReflectionUtil.GetGenericMethod( cstrMethInfo, typeArgs, out ex)); } }
//------------------------------------------------------------ // ReflectionUtil.GetConstructedConstructorInfo // /// <summary></summary> /// <param name="compiler"></param> /// <param name="methodSym"></param> /// <param name="aggTypeSym"></param> /// <returns></returns> //------------------------------------------------------------ internal static ConstructorInfo GetConstructedConstructorInfo( COMPILER compiler, METHSYM methodSym, AGGTYPESYM aggTypeSym) { DebugUtil.Assert(compiler != null && compiler.Emitter != null); EMITTER emitter = compiler.Emitter; DebugUtil.Assert(emitter != null && methodSym != null && aggTypeSym != null); SymUtil.EmitParentSym(emitter, aggTypeSym); SymUtil.GetSystemTypeFromSym(aggTypeSym, null, null); emitter.EmitMethodDef(methodSym); Type parentType = aggTypeSym.Type; ConstructorInfo cnstrDefInfo = methodSym.ConstructorInfo; DebugUtil.Assert(cnstrDefInfo != null); bool isGenericType = parentType.IsGenericType; //-------------------------------------------------------- // (1) Non-generic Type //-------------------------------------------------------- if (!isGenericType) { return(cnstrDefInfo); } //-------------------------------------------------------- // (2) Generic Type //-------------------------------------------------------- TypeArray paramTypeArray = methodSym.ParameterTypes; TypeArray paramTypeArray2 = null; Type[] paramTypes = null; if (paramTypeArray != null && paramTypeArray.Count > 0) { paramTypeArray2 = compiler.MainSymbolManager.SubstTypeArray( paramTypeArray, aggTypeSym.AllTypeArguments, null, SubstTypeFlagsEnum.NormNone); paramTypes = SymUtil.GetSystemTypesFromTypeArray( paramTypeArray2, methodSym.ClassSym, methodSym); } else { paramTypes = Type.EmptyTypes; } ConstructorInfo constructedInfo = null; Exception ex = null; try { constructedInfo = parentType.GetConstructor(paramTypes); } catch (NotSupportedException) { constructedInfo = GetConstructorInfo(parentType, cnstrDefInfo, out ex); } return(constructedInfo); }