<PackageReference Include="Microsoft.CSharp" Version="4.6.0" />

ExprMethodInfo

sealed class ExprMethodInfo : ExprWithType
using System; using System.Reflection; namespace Microsoft.CSharp.RuntimeBinder.Semantics { internal sealed class ExprMethodInfo : ExprWithType { public MethWithInst Method { get; } public MethodInfo MethodInfo { get { AggregateType ats = Method.Ats; MethodSymbol methodSymbol = Method.Meth(); TypeArray typeArray = TypeManager.SubstTypeArray(methodSymbol.Params, ats, methodSymbol.typeVars); CType cType = TypeManager.SubstType(methodSymbol.RetType, ats, methodSymbol.typeVars); Type type = ats.AssociatedSystemType; MethodInfo methodInfo = methodSymbol.AssociatedMemberInfo as MethodInfo; if (!type.IsGenericType && !type.IsNested) type = methodInfo.DeclaringType; foreach (MethodInfo runtimeMethod in type.GetRuntimeMethods()) { if (RuntimeBinderExtensions.HasSameMetadataDefinitionAs(runtimeMethod, methodInfo)) { bool flag = true; ParameterInfo[] parameters = runtimeMethod.GetParameters(); for (int i = 0; i < typeArray.Count; i++) { if (!ExprWithType.TypesAreEqual(parameters[i].ParameterType, typeArray[i].AssociatedSystemType)) { flag = false; break; } } if (flag) { if (!runtimeMethod.IsGenericMethod) return runtimeMethod; int num = Method.TypeArgs?.Count ?? 0; Type[] array = new Type[num]; if (num > 0) { for (int j = 0; j < Method.TypeArgs.Count; j++) { array[j] = Method.TypeArgs[j].AssociatedSystemType; } } return runtimeMethod.MakeGenericMethod(array); } } } throw Error.InternalCompilerError(); } } public ConstructorInfo ConstructorInfo { get { AggregateType ats = Method.Ats; MethodSymbol methodSymbol = Method.Meth(); TypeArray typeArray = TypeManager.SubstTypeArray(methodSymbol.Params, ats); Type type = ats.AssociatedSystemType; ConstructorInfo constructorInfo = (ConstructorInfo)methodSymbol.AssociatedMemberInfo; if (!type.IsGenericType && !type.IsNested) type = constructorInfo.DeclaringType; ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (ConstructorInfo constructorInfo2 in constructors) { if (RuntimeBinderExtensions.HasSameMetadataDefinitionAs(constructorInfo2, constructorInfo)) { bool flag = true; ParameterInfo[] parameters = constructorInfo2.GetParameters(); for (int j = 0; j < typeArray.Count; j++) { if (!ExprWithType.TypesAreEqual(parameters[j].ParameterType, typeArray[j].AssociatedSystemType)) { flag = false; break; } } if (flag) return constructorInfo2; } } throw Error.InternalCompilerError(); } } public override object Object => MethodInfo; public ExprMethodInfo(CType type, MethodSymbol method, AggregateType methodType, TypeArray methodParameters) : base(ExpressionKind.MethodInfo, type) { Method = new MethWithInst(method, methodType, methodParameters); } } }