- Type dt = delegate_type;
- Type[] g_args = null;
- if (TypeManager.IsGenericType (delegate_type)) {
- g_args = TypeManager.GetTypeArguments (delegate_type);
- delegate_type = TypeManager.DropGenericTypeArguments (delegate_type);
- }
-
- Delegate d = TypeManager.LookupDelegate (delegate_type);
- if (d != null) {
- if (g_args != null)
- return TypeBuilder.GetConstructor (dt, d.Constructor.ConstructorBuilder);
-
- return d.Constructor.ConstructorBuilder;
- }
-
- Expression ml = Expression.MemberLookup (ctx, container_type,
- null, dt, ConstructorInfo.ConstructorName, MemberTypes.Constructor,
- BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly, Location.Null);
-
- MethodGroupExpr mg = ml as MethodGroupExpr;
- if (mg == null) {
- ctx.Report.Error (-100, Location.Null, "Internal error: could not find delegate constructor!");
- // FIXME: null will cause a crash later
- return null;
- }
-
- return (ConstructorInfo) mg.Methods[0];
+ var ctor = MemberCache.FindMember (delType, MemberFilter.Constructor (null), BindingRestriction.DeclaredOnly);
+ return (MethodSpec) ctor;