private static void ctx_InterfaceMappingLoadEvent(object sender, ExplicitMethodImplementationLoadArgs e)
 {
     e.ExplicitlyImplementedMethods = e.Type.GetInterfaces()
                                      .Select(iFace => e.Type.GetInterfaceMap(iFace))
                                      .SelectMany(map => map.TargetMethods.Select((tMethod, idx) => Tuple.Create(tMethod, map.InterfaceMethods[idx])))
                                      .GroupBy(tuple => tuple.Item1)
                                      .ToDictionary(grp => grp.Key, grp => grp.Select(tuple => tuple.Item2).ToArray());
 }
Exemple #2
0
        internal CILMethodImpl(
            CILReflectionContextImpl ctx,
            Int32 anID,
            System.Reflection.MethodInfo method
            )
            : base(ctx, anID, method)
        {
            var nGDef = method.IsGenericMethodDefinition ? method : null;

            var dllImportAttr = method.GetCustomAttributes(typeof(System.Runtime.InteropServices.DllImportAttribute), true).FirstOrDefault() as System.Runtime.InteropServices.DllImportAttribute;

            InitFields(
                ref this.name,
                ref this.returnParameter,
                ref this.gArgs,
                ref this.gArgsLock,
                ref this.gDef,
                ref this.overriddenMethods,
                ref this.overriddenMethodsLock,
                ref this.pInvokeAttributes,
                ref this.pInvokeName,
                ref this.pInvokeModule,
                new SettableValueForClasses <String>(method.Name),
                () => ctx.Cache.GetOrAdd(method.ReturnParameter),
                () => ctx.CollectionsFactory.NewListProxy <CILTypeBase>(method.GetGenericArguments().Select(gArg => ctx.Cache.GetOrAdd(gArg)).ToList()),
                () => ctx.Cache.GetOrAdd(nGDef),
                () =>
            {
                var result = this.context.CollectionsFactory.NewListProxy <CILMethod>();

                if (!method.DeclaringType
#if WINDOWS_PHONE_APP
                    .GetTypeInfo()
#endif
                    .IsInterface&& !method.IsPublic)
                {
                    var args = new ExplicitMethodImplementationLoadArgs(method.DeclaringType);
                    ctx.LaunchInterfaceMappingLoadEvent(args);
                    System.Reflection.MethodInfo[] resultNMethods;
                    if (args.ExplicitlyImplementedMethods.TryGetValue(method, out resultNMethods))
                    {
                        result.AddRange(resultNMethods.Select(nMethod => ctx.Cache.GetOrAdd(nMethod)));
                    }
                }
                return(result);
            },
                new SettableValueForEnums <PInvokeAttributes>(dllImportAttr == null ? (PInvokeAttributes)0 : dllImportAttr.GetCorrespondingPInvokeAttributes()),
                new SettableValueForClasses <String>(dllImportAttr == null ? null : dllImportAttr.EntryPoint),
                new SettableValueForClasses <String>(dllImportAttr == null ? null : dllImportAttr.Value),
                true
                );
        }