示例#1
0
        private void ReadProxyBehaviorFromConfig(ComponentModel model, ComponentProxyBehaviorAttribute behavior)
        {
            if (model.Configuration == null)
            {
                return;
            }
#if !SILVERLIGHT
            var mbrProxy = model.Configuration.Attributes["marshalByRefProxy"];
            if (mbrProxy != null)
            {
                behavior.UseMarshalByRefProxy = converter.PerformConversion <bool?>(mbrProxy).GetValueOrDefault(false);
            }
#endif
            var interfaces = model.Configuration.Children["additionalInterfaces"];
            if (interfaces == null)
            {
                return;
            }
            var list = new List <Type>(behavior.AdditionalInterfaces);
            foreach (var node in interfaces.Children)
            {
                var interfaceTypeName = node.Attributes["interface"];
                var @interface        = converter.PerformConversion <Type>(interfaceTypeName);
                list.Add(@interface);
            }
            behavior.AdditionalInterfaces = list.ToArray();
        }
        private static void ApplyProxyBehavior(ComponentProxyBehaviorAttribute behavior, ComponentModel model)
        {
            var options = model.ObtainProxyOptions();

#if !SILVERLIGHT
            if (behavior.UseMarshalByRefProxy)
            {
                EnsureComponentRegisteredWithInterface(model);
            }
            options.UseMarshalByRefAsBaseClass = behavior.UseMarshalByRefProxy;
#endif
            options.AddAdditionalInterfaces(behavior.AdditionalInterfaces);
        }
示例#3
0
        /// <summary>
        ///   Reads the proxy behavior associated with the
        ///   component configuration/type and applies it to the model.
        /// </summary>
        /// <exception cref = "System.Exception">
        ///   If the conversion fails
        /// </exception>
        /// <param name = "kernel"></param>
        /// <param name = "model"></param>
        protected virtual void ReadProxyBehavior(IKernel kernel, ComponentModel model)
        {
            var proxyBehaviorAttribute = ReadProxyBehaviorFromType(model.Implementation);

            if (proxyBehaviorAttribute == null)
            {
                proxyBehaviorAttribute = new ComponentProxyBehaviorAttribute();
            }

            ReadProxyBehaviorFromConfig(model, proxyBehaviorAttribute);

            ApplyProxyBehavior(proxyBehaviorAttribute, model);
        }
示例#4
0
        private static void ApplyProxyBehavior(ComponentProxyBehaviorAttribute behavior, ComponentModel model)
        {
            var options = model.ObtainProxyOptions();

#if FEATURE_REMOTING
            if (behavior.UseMarshalByRefProxy)
            {
                EnsureComponentRegisteredWithInterface(model);
            }
            options.UseMarshalByRefAsBaseClass = behavior.UseMarshalByRefProxy;
#endif
            options.AddAdditionalInterfaces(behavior.AdditionalInterfaces);
            if (model.Implementation.GetTypeInfo().IsInterface)
            {
                options.OmitTarget = true;
            }
        }