///// <summary> ///// Called indirectly from the InterceptedBy extension method. ///// Adds services to the componenent's list of interceptors, activating the need for dynamic proxy ///// </summary> //public void AddInterceptorService<TLimit>(RegistrationData registrationData, params Service[] interceptorServices) //{ // AddProxy(typeof(TLimit)); // var interceptorServicesConcat = Enumerable.Empty<Service>(); // object value; // if (registrationData.Metadata.TryGetValue(InterceptorServicesKey, out value)) // { // interceptorServicesConcat = (IEnumerable<Service>)value; // } // registrationData.Metadata[InterceptorServicesKey] = interceptorServicesConcat.Concat(interceptorServices ).Distinct().ToArray(); //} /// <summary> /// Ensures that a proxy has been generated for the particular type in this context /// </summary> public void AddProxy(Type type) { Type proxyType; if (_cache.TryGetValue(type, out proxyType)) { return; } lock (_cache) { if (_cache.TryGetValue(type, out proxyType)) { return; } _cache[type] = _proxyBuilder.CreateClassProxyType(type, new Type[0], ProxyGenerationOptions.Default); } }
private Type GetProxyType(CompositeType compositeType) { if (compositeType == null) { throw new ArgumentNullException("compositeType"); } if (!CachedProxyTypes.ContainsKey(compositeType)) { Type[] additionalInterfaceTypes = BuildAdditionalTypeArrayForProxyType(compositeType); Type proxyType; /* ^ */ var _typeInfo = compositeType.PrimaryType.GetTypeInfo(); /* [email protected] ^ */ if (/* ^ */ _typeInfo.IsClass /* [email protected] ^ */) { if (/* ^ */ _typeInfo.IsSealed /* [email protected] ^ */) { throw new ArgumentException("Cannot mock sealed classes."); } proxyType = ProxyBuilder.CreateClassProxyType(compositeType.PrimaryType, additionalInterfaceTypes, ProxyGenerationOptions.Default); } else { proxyType = ProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(compositeType.PrimaryType, additionalInterfaceTypes, new ProxyGenerationOptions { BaseTypeForInterfaceProxy = typeof(InterfaceMockBase) }); } lock (locker) { if (!CachedProxyTypes.ContainsKey(compositeType)) { CachedProxyTypes[compositeType] = proxyType; } } return(proxyType); } return(CachedProxyTypes[compositeType]); }
Type GetProxyTypeFor <T>() where T : ICommand { if (ProxyTypePerCommand <T> .ProxyType == null) { var interfaceForCommandType = _proxying.BuildInterfaceWithPropertiesFrom(typeof(T)); var options = new ProxyGenerationOptions(); ProxyTypePerCommand <T> .ProxyType = _proxyBuilder.CreateClassProxyType( typeof(CommandProxyInstance), new[] { typeof(ICommandFor <T>), interfaceForCommandType, typeof(ICommandProcess), typeof(ICanProcessCommandProcess), typeof(System.Windows.Input.ICommand), typeof(INotifyDataErrorInfo), typeof(IHoldCommandInstance) }, options); } return(ProxyTypePerCommand <T> .ProxyType); }