示例#1
0
            public InterfaceBuilder(Type tInterface)
            {
                this.tInterface = tInterface;
                methods         = tInterface.getMethodsWithoutProperties().ToArray();
                Type[] tDelegates = NativeDelegates.buildDelegates(tInterface);
                Debug.Assert(methods.Length == tDelegates.Length);
                prefabs = new iMethodPrefab[methods.Length];

                var conventions = tInterface.GetCustomAttribute <CustomConventionsAttribute>();

                for (int i = 0; i < methods.Length; i++)
                {
                    MethodInfo mi = methods[i];
                    // Check if any C# arguments need custom marshallers
                    bool anyCustom = mi.GetParameters().Any(Marshallers.hasCustomMarshaller);
                    // If the method has [RetValIndex], it also counts.
                    if (mi.hasRetValIndex())
                    {
                        anyCustom = true;
                    }

                    if (anyCustom)
                    {
                        try
                        {
                            prefabs[i] = new CustomMarshallerMethod(mi, tDelegates[i], i, conventions);
                        }
                        catch (Exception ex)
                        {
                            throw new SerializationException($"Error building custom callable proxy method {tInterface.FullName}.{mi.Name}", ex);
                        }
                    }
                    else
                    {
                        try
                        {
                            prefabs[i] = new ProxyMethod(mi, tDelegates[i]);
                        }
                        catch (Exception ex)
                        {
                            throw new SerializationException($"Error building callable proxy method {tInterface.FullName}.{mi.Name}", ex);
                        }
                    }
                }
            }
示例#2
0
            public InterfaceBuilder(Type tInterface)
            {
                this.tInterface = tInterface;
                methods         = tInterface.GetMethods();
                Type[] tDelegates = NativeDelegates.buildDelegates(tInterface);
                Debug.Assert(methods.Length == tDelegates.Length);
                prefabs = new iMethodPrefab[methods.Length];

                for (int i = 0; i < methods.Length; i++)
                {
                    MethodInfo mi        = methods[i];
                    bool       anyCustom = mi.GetParameters().Any(Marshallers.hasCustomMarshaller);
                    if (anyCustom)
                    {
                        prefabs[i] = new CustomMarshallerMethod(mi, tDelegates[i], i);
                    }
                    else
                    {
                        prefabs[i] = new ProxyMethod(mi, tDelegates[i]);
                    }
                }
            }