Ejemplo n.º 1
0
        private void CollectInterface(MethodSlotList slots, IType interfaceType)
        {
            var type = slots.Type;

            // Methods
            foreach (var interfaceBuildMethod in interfaceType.Methods)
            {
                var targetSlotMethod = slots.GetMethod(interfaceBuildMethod, true);

                if (targetSlotMethod.Depth == 0)
                {
                    // Root type overrides interface.
                    var targetBuildMethod    = targetSlotMethod.Method;
                    var targetMethodState    = _state.GetMethod(targetBuildMethod);
                    var interfaceMethodState = _state.GetMethod(interfaceBuildMethod);

                    if (NeedsInterfaceOverride(interfaceMethodState, targetMethodState))
                    {
                        targetMethodState.Overrides.Add(interfaceBuildMethod);
                    }
                }
                else
                {
                    // Base type overrides interface.
                    var typeState = _state.GetType(type);

                    var targetBuildMethod = targetSlotMethod.Method;

                    // If not overriden by root type, build proxy method and call base method.
                    if (typeState.Overrides.Contains(interfaceBuildMethod))
                    {
                        continue;
                    }

                    // If base method could not be called from this type, skip proxy method.
                    // If assembly is valid base method is always callable.
                    if (!CanCallMethod(type, targetBuildMethod))
                    {
                        continue;
                    }

                    // Add proxy method.
                    var proxy =
                        new ProxyBuildMethod()
                    {
                        OverridenMethod = interfaceBuildMethod,
                        CalledMethod    = targetBuildMethod,
                    };

                    typeState.ProxyMethods.Add(proxy);
                    typeState.Overrides.Add(interfaceBuildMethod);
                }
            }

            // Children
            foreach (var childInterfaceType in interfaceType.Interfaces)
            {
                CollectInterface(slots, childInterfaceType);
            }
        }
Ejemplo n.º 2
0
        public static void Analyze(BuildType type)
        {
            if (type.IsInterface)
            {
                return;
            }

            var slots = new MethodSlotList(type);

            foreach (var slot in slots)
            {
                Analyze(slot);
            }

            foreach (BuildType nestedType in type.NestedTypes)
            {
                Analyze(nestedType);
            }
        }
Ejemplo n.º 3
0
        private void CollectType(IType type)
        {
            if (type.IsInterface)
            {
                return;
            }

            var slots = new MethodSlotList(type);

            // Collect interfaces
            foreach (var interfaceType in type.Interfaces)
            {
                CollectInterface(slots, interfaceType);
            }

            // Collect slots
            foreach (var slot in slots)
            {
                CollectSlot(slot);
            }
        }