Best JustMockLite code snippet using Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithTargetInterface
ProxyGenerator.cs
Source:ProxyGenerator.cs  
...107		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref108		///    name = "target" /> throws an exception.</exception>109		/// <remarks>110		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target111		///   use <see cref = "CreateInterfaceProxyWithTargetInterface{TInterface}(TInterface,IInterceptor[])" /> method.112		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.113		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.114		/// </remarks>115		public TInterface CreateInterfaceProxyWithTarget<TInterface>(TInterface target, params IInterceptor[] interceptors)116			where TInterface : class117		{118			// NOTE: we don't need to document exception case where interface type is null, since it can never be for a generic method.119			// If we leave target as being of type TInterface we also have covered exception where target does not implement TInterface.120			// NOTE: Can any other Activator.CreateInstance exception be thrown in this context?121			return122				(TInterface)123				CreateInterfaceProxyWithTarget(typeof(TInterface), target, ProxyGenerationOptions.Default, interceptors);124		}125		/// <summary>126		///   Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on <paramref127		///    name = "target" /> object with given <paramref name = "interceptors" />.128		/// </summary>129		/// <typeparam name = "TInterface">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</typeparam>130		/// <param name = "target">The target object, calls to which will be intercepted.</param>131		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>132		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>133		/// <returns>134		///   Object proxying calls to members of <typeparamref name = "TInterface" /> on <paramref name = "target" /> object.135		/// </returns>136		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>137		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>138		/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" />is not an interface type.</exception>139		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref140		///    name = "target" /> object.</exception>141		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref142		///    name = "target" /> throws an exception.</exception>143		/// <remarks>144		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target145		///   use <see146		///    cref = "CreateInterfaceProxyWithTargetInterface{TInterface}(TInterface,Castle.DynamicProxy.ProxyGenerationOptions,IInterceptor[])" /> method.147		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.148		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.149		/// </remarks>150		public TInterface CreateInterfaceProxyWithTarget<TInterface>(TInterface target, ProxyGenerationOptions options,151		                                                             params IInterceptor[] interceptors)152			where TInterface : class153		{154			return (TInterface)CreateInterfaceProxyWithTarget(typeof(TInterface), target, options, interceptors);155		}156		/// <summary>157		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref158		///    name = "target" /> object with given <paramref name = "interceptors" />.159		/// </summary>160		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>161		/// <param name = "target">The target object, calls to which will be intercepted.</param>162		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>163		/// <returns>164		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on <paramref name = "target" /> object.165		/// </returns>166		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>167		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>168		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>169		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>170		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>171		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref172		///    name = "interfaceToProxy" /> interface.</exception>173		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref174		///    name = "target" /> object.</exception>175		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref176		///    name = "target" /> throws an exception.</exception>177		/// <remarks>178		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target179		///   use <see cref = "CreateInterfaceProxyWithTargetInterface(Type,object,IInterceptor[])" /> method.180		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.181		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.182		/// </remarks>183		public object CreateInterfaceProxyWithTarget(Type interfaceToProxy, object target, params IInterceptor[] interceptors)184		{185			return CreateInterfaceProxyWithTarget(interfaceToProxy, target, ProxyGenerationOptions.Default, interceptors);186		}187		/// <summary>188		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref189		///    name = "target" /> object with given <paramref name = "interceptors" />.190		/// </summary>191		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>192		/// <param name = "target">The target object, calls to which will be intercepted.</param>193		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>194		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>195		/// <returns>196		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on <paramref name = "target" /> object.197		/// </returns>198		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>199		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>200		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>201		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>202		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>203		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref204		///    name = "interfaceToProxy" /> interface.</exception>205		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref206		///    name = "target" /> object.</exception>207		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref208		///    name = "target" /> throws an exception.</exception>209		/// <remarks>210		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target211		///   use <see cref = "CreateInterfaceProxyWithTargetInterface(Type,object,ProxyGenerationOptions,IInterceptor[])" /> method.212		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.213		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.214		/// </remarks>215		public object CreateInterfaceProxyWithTarget(Type interfaceToProxy, object target, ProxyGenerationOptions options,216		                                             params IInterceptor[] interceptors)217		{218			return CreateInterfaceProxyWithTarget(interfaceToProxy, null, target, options, interceptors);219		}220		/// <summary>221		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref222		///    name = "target" /> object with given <paramref name = "interceptors" />.223		/// </summary>224		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>225		/// <param name = "target">The target object, calls to which will be intercepted.</param>226		/// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>227		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>228		/// <returns>229		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref230		///    name = "additionalInterfacesToProxy" /> types  on <paramref name = "target" /> object.231		/// </returns>232		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>233		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>234		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>235		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref236		///    name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>237		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>238		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref239		///    name = "interfaceToProxy" /> interface.</exception>240		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref241		///    name = "target" /> object.</exception>242		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref243		///    name = "target" /> throws an exception.</exception>244		/// <remarks>245		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target246		///   use <see cref = "CreateInterfaceProxyWithTargetInterface(Type,Type[],object,IInterceptor[])" /> method.247		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.248		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.249		/// </remarks>250		public object CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, object target,251		                                             params IInterceptor[] interceptors)252		{253			return CreateInterfaceProxyWithTarget(interfaceToProxy, additionalInterfacesToProxy, target,254			                                      ProxyGenerationOptions.Default, interceptors);255		}256		/// <summary>257		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref258		///    name = "target" /> object with given <paramref name = "interceptors" />.259		/// </summary>260		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>261		/// <param name = "target">The target object, calls to which will be intercepted.</param>262		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>263		/// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>264		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>265		/// <returns>266		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref267		///    name = "additionalInterfacesToProxy" /> types on <paramref name = "target" /> object.268		/// </returns>269		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>270		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>271		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>272		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref273		///    name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>274		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>275		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref276		///    name = "interfaceToProxy" /> interface.</exception>277		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref278		///    name = "target" /> object.</exception>279		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref280		///    name = "target" /> throws an exception.</exception>281		/// <remarks>282		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target283		///   use <see cref = "CreateInterfaceProxyWithTargetInterface(Type,Type[],object,ProxyGenerationOptions,IInterceptor[])" /> method.284		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.285		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.286		/// </remarks>287		public virtual object CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,288		                                                     object target,289		                                                     ProxyGenerationOptions options,290		                                                     params IInterceptor[] interceptors)291		{292			if (interfaceToProxy == null)293			{294				throw new ArgumentNullException("interfaceToProxy");295			}296			if (target == null)297			{298				throw new ArgumentNullException("target");299			}300			if (interceptors == null)301			{302				throw new ArgumentNullException("interceptors");303			}304			if (!interfaceToProxy.GetTypeInfo().IsInterface)305			{306				throw new ArgumentException("Specified type is not an interface", "interfaceToProxy");307			}308			var targetType = target.GetType();309			if (!interfaceToProxy.IsAssignableFrom(targetType))310			{311				throw new ArgumentException("Target does not implement interface " + interfaceToProxy.FullName, "target");312			}313			CheckNotGenericTypeDefinition(interfaceToProxy, "interfaceToProxy");314			CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, "additionalInterfacesToProxy");315			var generatedType = CreateInterfaceProxyTypeWithTarget(interfaceToProxy, additionalInterfacesToProxy, targetType,316			                                                       options);317			var arguments = GetConstructorArguments(target, interceptors, options);318			return Activator.CreateInstance(generatedType, arguments.ToArray());319		}320		protected List<object> GetConstructorArguments(object target, IInterceptor[] interceptors,321		                                               ProxyGenerationOptions options)322		{323			// create constructor arguments (initialized with mixin implementations, interceptors and target type constructor arguments)324			var arguments = new List<object>(options.MixinData.Mixins) { interceptors, target };325			if (options.Selector != null)326			{327				arguments.Add(options.Selector);328			}329			return arguments;330		}331		/// <summary>332		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref333		///    name = "target" /> object with given <paramref name = "interceptors" />.334		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref335		///    name = "target" />.336		/// </summary>337		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>338		/// <param name = "target">The target object, calls to which will be intercepted.</param>339		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>340		/// <returns>341		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.342		/// </returns>343		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>344		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>345		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>346		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>347		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>348		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref349		///    name = "interfaceToProxy" /> interface.</exception>350		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref351		///    name = "target" /> object.</exception>352		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref353		///    name = "target" /> throws an exception.</exception>354		/// <remarks>355		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.356		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.357		/// </remarks>358		public object CreateInterfaceProxyWithTargetInterface(Type interfaceToProxy, object target,359		                                                      params IInterceptor[] interceptors)360		{361			return CreateInterfaceProxyWithTargetInterface(interfaceToProxy, target, ProxyGenerationOptions.Default, interceptors);362		}363		/// <summary>364		///   Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on <paramref365		///    name = "target" /> object with given <paramref name = "interceptors" />.366		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref367		///    name = "target" />.368		/// </summary>369		/// <typeparam name = "TInterface">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</typeparam>370		/// <param name = "target">The target object, calls to which will be intercepted.</param>371		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>372		/// <returns>373		///   Object proxying calls to members of <typeparamref name = "TInterface" /> type on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.374		/// </returns>375		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>376		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>377		/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" /> is not an interface type.</exception>378		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref379		///    name = "target" /> object.</exception>380		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref381		///    name = "target" /> throws an exception.</exception>382		/// <remarks>383		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.384		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.385		/// </remarks>386		public TInterface CreateInterfaceProxyWithTargetInterface<TInterface>(TInterface target,387		                                                                      params IInterceptor[] interceptors)388			where TInterface : class389		{390			return (TInterface)CreateInterfaceProxyWithTargetInterface(typeof(TInterface),391			                                                           target,392			                                                           ProxyGenerationOptions.Default,393			                                                           interceptors);394		}395		/// <summary>396		///   Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on <paramref397		///    name = "target" /> object with given <paramref name = "interceptors" />.398		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref399		///    name = "target" />.400		/// </summary>401		/// <typeparam name = "TInterface">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</typeparam>402		/// <param name = "target">The target object, calls to which will be intercepted.</param>403		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>404		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>405		/// <returns>406		///   Object proxying calls to members of <typeparamref name = "TInterface" /> type on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.407		/// </returns>408		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>409		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>410		/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" /> is not an interface type.</exception>411		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref412		///    name = "target" /> object.</exception>413		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref414		///    name = "target" /> throws an exception.</exception>415		/// <remarks>416		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.417		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.418		/// </remarks>419		public TInterface CreateInterfaceProxyWithTargetInterface<TInterface>(TInterface target,420		                                                                      ProxyGenerationOptions options,421		                                                                      params IInterceptor[] interceptors)422			where TInterface : class423		{424			return (TInterface)CreateInterfaceProxyWithTargetInterface(typeof(TInterface),425			                                                           target,426			                                                           options,427			                                                           interceptors);428		}429		/// <summary>430		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref431		///    name = "target" /> object with given <paramref name = "interceptors" />.432		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref433		///    name = "target" />.434		/// </summary>435		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>436		/// <param name = "target">The target object, calls to which will be intercepted.</param>437		/// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>438		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>439		/// <returns>440		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref441		///    name = "additionalInterfacesToProxy" /> types on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.442		/// </returns>443		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>444		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>445		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>446		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref447		///    name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>448		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>449		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref450		///    name = "interfaceToProxy" /> interface.</exception>451		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref452		///    name = "target" /> object.</exception>453		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref454		///    name = "target" /> throws an exception.</exception>455		/// <remarks>456		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.457		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.458		/// </remarks>459		public object CreateInterfaceProxyWithTargetInterface(Type interfaceToProxy, Type[] additionalInterfacesToProxy,460		                                                      object target, params IInterceptor[] interceptors)461		{462			return CreateInterfaceProxyWithTargetInterface(interfaceToProxy, additionalInterfacesToProxy, target,463			                                               ProxyGenerationOptions.Default, interceptors);464		}465		/// <summary>466		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref467		///    name = "target" /> object with given <paramref name = "interceptors" />.468		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref469		///    name = "target" />.470		/// </summary>471		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>472		/// <param name = "target">The target object, calls to which will be intercepted.</param>473		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>474		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>475		/// <returns>476		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.477		/// </returns>478		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>479		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>480		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>481		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>482		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>483		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref484		///    name = "interfaceToProxy" /> interface.</exception>485		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref486		///    name = "target" /> object.</exception>487		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref488		///    name = "target" /> throws an exception.</exception>489		/// <remarks>490		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.491		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.492		/// </remarks>493		public object CreateInterfaceProxyWithTargetInterface(Type interfaceToProxy, object target,494		                                                      ProxyGenerationOptions options,495		                                                      params IInterceptor[] interceptors)496		{497			return CreateInterfaceProxyWithTargetInterface(interfaceToProxy, null, target, options, interceptors);498		}499		/// <summary>500		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref name = "target" /> object with given <paramref name = "interceptors" />.501		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref name = "target" />.502		/// </summary>503		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>504		/// <param name = "target">The target object, calls to which will be intercepted.</param>505		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>506		/// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>507		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>508		/// <returns>509		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.510		/// </returns>511		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>512		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>513		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>514		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>515		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>516		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref name = "interfaceToProxy" /> interface.</exception>517		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref name = "target" /> object.</exception>518		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref name = "target" /> throws an exception.</exception>519		/// <remarks>520		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.521		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.522		/// </remarks>523#if FEATURE_SECURITY_PERMISSIONS && DOTNET40524		[SecuritySafeCritical]525#endif526		public virtual object CreateInterfaceProxyWithTargetInterface(Type interfaceToProxy,527		                                                              Type[] additionalInterfacesToProxy,528		                                                              object target, ProxyGenerationOptions options,529		                                                              params IInterceptor[] interceptors)530		{531			//TODO: add <example> to xml comments to show how to use IChangeProxyTarget532			if (interfaceToProxy == null)533			{534				throw new ArgumentNullException("interfaceToProxy");535			}536			// In the case of a transparent proxy, the call to IsInstanceOfType was executed on the real object.537			if (target != null && interfaceToProxy.IsInstanceOfType(target) == false)538			{539				throw new ArgumentException("Target does not implement interface " + interfaceToProxy.FullName, "target");540			}...IProxyGenerator.cs
Source:IProxyGenerator.cs  
...47		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref48		///    name = "target" /> throws an exception.</exception>49		/// <remarks>50		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target51		///   use <see cref = "CreateInterfaceProxyWithTargetInterface{TInterface}(TInterface,IInterceptor[])" /> method.52		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.53		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.54		/// </remarks>55		TInterface CreateInterfaceProxyWithTarget<TInterface>(TInterface target, params IInterceptor[] interceptors)56			where TInterface : class;57		/// <summary>58		///   Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on <paramref59		///    name = "target" /> object with given <paramref name = "interceptors" />.60		/// </summary>61		/// <typeparam name = "TInterface">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</typeparam>62		/// <param name = "target">The target object, calls to which will be intercepted.</param>63		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>64		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>65		/// <returns>66		///   Object proxying calls to members of <typeparamref name = "TInterface" /> on <paramref name = "target" /> object.67		/// </returns>68		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>69		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>70		/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" />is not an interface type.</exception>71		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref72		///    name = "target" /> object.</exception>73		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref74		///    name = "target" /> throws an exception.</exception>75		/// <remarks>76		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target77		///   use <see78		///    cref = "CreateInterfaceProxyWithTargetInterface{TInterface}(TInterface,Castle.DynamicProxy.ProxyGenerationOptions,IInterceptor[])" /> method.79		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.80		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.81		/// </remarks>82		TInterface CreateInterfaceProxyWithTarget<TInterface>(TInterface target, ProxyGenerationOptions options,83		                                                      params IInterceptor[] interceptors)84			where TInterface : class;85		/// <summary>86		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref87		///    name = "target" /> object with given <paramref name = "interceptors" />.88		/// </summary>89		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>90		/// <param name = "target">The target object, calls to which will be intercepted.</param>91		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>92		/// <returns>93		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on <paramref name = "target" /> object.94		/// </returns>95		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>96		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>97		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>98		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>99		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>100		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref101		///    name = "interfaceToProxy" /> interface.</exception>102		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref103		///    name = "target" /> object.</exception>104		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref105		///    name = "target" /> throws an exception.</exception>106		/// <remarks>107		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target108		///   use <see cref = "CreateInterfaceProxyWithTargetInterface(Type,object,IInterceptor[])" /> method.109		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.110		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.111		/// </remarks>112		object CreateInterfaceProxyWithTarget(Type interfaceToProxy, object target, params IInterceptor[] interceptors);113		/// <summary>114		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref115		///    name = "target" /> object with given <paramref name = "interceptors" />.116		/// </summary>117		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>118		/// <param name = "target">The target object, calls to which will be intercepted.</param>119		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>120		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>121		/// <returns>122		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on <paramref name = "target" /> object.123		/// </returns>124		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>125		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>126		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>127		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>128		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>129		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref130		///    name = "interfaceToProxy" /> interface.</exception>131		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref132		///    name = "target" /> object.</exception>133		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref134		///    name = "target" /> throws an exception.</exception>135		/// <remarks>136		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target137		///   use <see cref = "CreateInterfaceProxyWithTargetInterface(Type,object,ProxyGenerationOptions,IInterceptor[])" /> method.138		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.139		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.140		/// </remarks>141		object CreateInterfaceProxyWithTarget(Type interfaceToProxy, object target, ProxyGenerationOptions options,142		                                      params IInterceptor[] interceptors);143		/// <summary>144		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref145		///    name = "target" /> object with given <paramref name = "interceptors" />.146		/// </summary>147		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>148		/// <param name = "target">The target object, calls to which will be intercepted.</param>149		/// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>150		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>151		/// <returns>152		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref153		///    name = "additionalInterfacesToProxy" /> types  on <paramref name = "target" /> object.154		/// </returns>155		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>156		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>157		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>158		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref159		///    name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>160		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>161		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref162		///    name = "interfaceToProxy" /> interface.</exception>163		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref164		///    name = "target" /> object.</exception>165		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref166		///    name = "target" /> throws an exception.</exception>167		/// <remarks>168		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target169		///   use <see cref = "CreateInterfaceProxyWithTargetInterface(Type,Type[],object,IInterceptor[])" /> method.170		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.171		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.172		/// </remarks>173		object CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, object target,174		                                      params IInterceptor[] interceptors);175		/// <summary>176		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref177		///    name = "target" /> object with given <paramref name = "interceptors" />.178		/// </summary>179		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>180		/// <param name = "target">The target object, calls to which will be intercepted.</param>181		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>182		/// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>183		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>184		/// <returns>185		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref186		///    name = "additionalInterfacesToProxy" /> types on <paramref name = "target" /> object.187		/// </returns>188		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>189		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>190		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>191		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref192		///    name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>193		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>194		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref195		///    name = "interfaceToProxy" /> interface.</exception>196		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref197		///    name = "target" /> object.</exception>198		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref199		///    name = "target" /> throws an exception.</exception>200		/// <remarks>201		///   This method generates new proxy type for each type of <paramref name = "target" />, which affects performance. If you don't want to proxy types differently depending on the type of the target202		///   use <see cref = "CreateInterfaceProxyWithTargetInterface(Type,Type[],object,ProxyGenerationOptions,IInterceptor[])" /> method.203		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.204		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.205		/// </remarks>206		object CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,207		                                      object target,208		                                      ProxyGenerationOptions options,209		                                      params IInterceptor[] interceptors);210		/// <summary>211		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref212		///    name = "target" /> object with given <paramref name = "interceptors" />.213		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref214		///    name = "target" />.215		/// </summary>216		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>217		/// <param name = "target">The target object, calls to which will be intercepted.</param>218		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>219		/// <returns>220		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.221		/// </returns>222		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>223		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>224		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>225		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>226		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>227		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref228		///    name = "interfaceToProxy" /> interface.</exception>229		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref230		///    name = "target" /> object.</exception>231		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref232		///    name = "target" /> throws an exception.</exception>233		/// <remarks>234		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.235		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.236		/// </remarks>237		object CreateInterfaceProxyWithTargetInterface(Type interfaceToProxy, object target,238		                                               params IInterceptor[] interceptors);239		/// <summary>240		///   Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on <paramref241		///    name = "target" /> object with given <paramref name = "interceptors" />.242		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref243		///    name = "target" />.244		/// </summary>245		/// <typeparam name = "TInterface">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</typeparam>246		/// <param name = "target">The target object, calls to which will be intercepted.</param>247		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>248		/// <returns>249		///   Object proxying calls to members of <typeparamref name = "TInterface" /> type on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.250		/// </returns>251		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>252		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>253		/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" /> is not an interface type.</exception>254		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref255		///    name = "target" /> object.</exception>256		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref257		///    name = "target" /> throws an exception.</exception>258		/// <remarks>259		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.260		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.261		/// </remarks>262		TInterface CreateInterfaceProxyWithTargetInterface<TInterface>(TInterface target,263		                                                               params IInterceptor[] interceptors)264			where TInterface : class;265		/// <summary>266		///   Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on <paramref267		///    name = "target" /> object with given <paramref name = "interceptors" />.268		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref269		///    name = "target" />.270		/// </summary>271		/// <typeparam name = "TInterface">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</typeparam>272		/// <param name = "target">The target object, calls to which will be intercepted.</param>273		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>274		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>275		/// <returns>276		///   Object proxying calls to members of <typeparamref name = "TInterface" /> type on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.277		/// </returns>278		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>279		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>280		/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" /> is not an interface type.</exception>281		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref282		///    name = "target" /> object.</exception>283		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref284		///    name = "target" /> throws an exception.</exception>285		/// <remarks>286		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.287		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.288		/// </remarks>289		TInterface CreateInterfaceProxyWithTargetInterface<TInterface>(TInterface target,290		                                                               ProxyGenerationOptions options,291		                                                               params IInterceptor[] interceptors)292			where TInterface : class;293		/// <summary>294		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref295		///    name = "target" /> object with given <paramref name = "interceptors" />.296		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref297		///    name = "target" />.298		/// </summary>299		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>300		/// <param name = "target">The target object, calls to which will be intercepted.</param>301		/// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>302		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>303		/// <returns>304		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref305		///    name = "additionalInterfacesToProxy" /> types on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.306		/// </returns>307		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>308		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>309		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>310		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref311		///    name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>312		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>313		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref314		///    name = "interfaceToProxy" /> interface.</exception>315		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref316		///    name = "target" /> object.</exception>317		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref318		///    name = "target" /> throws an exception.</exception>319		/// <remarks>320		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.321		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.322		/// </remarks>323		object CreateInterfaceProxyWithTargetInterface(Type interfaceToProxy, Type[] additionalInterfacesToProxy,324		                                               object target, params IInterceptor[] interceptors);325		/// <summary>326		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref327		///    name = "target" /> object with given <paramref name = "interceptors" />.328		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref329		///    name = "target" />.330		/// </summary>331		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>332		/// <param name = "target">The target object, calls to which will be intercepted.</param>333		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>334		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>335		/// <returns>336		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.337		/// </returns>338		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>339		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>340		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>341		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>342		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>343		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref344		///    name = "interfaceToProxy" /> interface.</exception>345		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref346		///    name = "target" /> object.</exception>347		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref348		///    name = "target" /> throws an exception.</exception>349		/// <remarks>350		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.351		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.352		/// </remarks>353		object CreateInterfaceProxyWithTargetInterface(Type interfaceToProxy, object target,354		                                               ProxyGenerationOptions options,355		                                               params IInterceptor[] interceptors);356		/// <summary>357		///   Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on <paramref name = "target" /> object with given <paramref name = "interceptors" />.358		///   Interceptors can use <see cref = "IChangeProxyTarget" /> interface to provide other target for method invocation than default <paramref name = "target" />.359		/// </summary>360		/// <param name = "interfaceToProxy">Type of the interface implemented by <paramref name = "target" /> which will be proxied.</param>361		/// <param name = "target">The target object, calls to which will be intercepted.</param>362		/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>363		/// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>364		/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>365		/// <returns>366		///   Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types on <paramref name = "target" /> object or alternative implementation swapped at runtime by an interceptor.367		/// </returns>368		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>369		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "target" /> object is a null reference (Nothing in Visual Basic).</exception>370		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>371		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>372		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>373		/// <exception cref = "ArgumentException">Thrown when given <paramref name = "target" /> does not implement <paramref name = "interfaceToProxy" /> interface.</exception>374		/// <exception cref = "MissingMethodException">Thrown when no default constructor exists on actual type of <paramref name = "target" /> object.</exception>375		/// <exception cref = "TargetInvocationException">Thrown when default constructor of actual type of <paramref name = "target" /> throws an exception.</exception>376		/// <remarks>377		///   This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.378		///   As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.379		/// </remarks>380		object CreateInterfaceProxyWithTargetInterface(Type interfaceToProxy,381		                                               Type[] additionalInterfacesToProxy,382		                                               object target, ProxyGenerationOptions options,383		                                               params IInterceptor[] interceptors);384		/// <summary>385		///   Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on target object generated at runtime with given <paramref386		///    name = "interceptor" />.387		/// </summary>388		/// <typeparam name = "TInterface">Type of the interface which will be proxied.</typeparam>389		/// <param name = "interceptor">The interceptors called during the invocation of proxied methods.</param>390		/// <returns>391		///   Object proxying calls to members of <typeparamref name = "TInterface" /> types on generated target object.392		/// </returns>393		/// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptor" /> array is a null reference (Nothing in Visual Basic).</exception>394		/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" /> is not an interface type.</exception>...CreateInterfaceProxyWithTargetInterface
Using AI Code Generation
1using Telerik.JustMock;2using Telerik.JustMock.Core;3using Telerik.JustMock.Core.Castle.DynamicProxy;4using System;5using System.Collections.Generic;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9{10    {11        void Method1();12    }13    {14        public void Method1()15        {16        }17    }18    {19        public void Method1()20        {21            var myInterface = Mock.Create<IMyInterface>();22            var proxyGenerator = new ProxyGenerator();23            var proxy = proxyGenerator.CreateInterfaceProxyWithTargetInterface(myInterface, new MyInterfaceImpl());24            proxy.Method1();25        }26    }27}28using Telerik.JustMock;29using Telerik.JustMock.Core;30using Telerik.JustMock.Core.Castle.DynamicProxy;31using System;32using System.Collections.Generic;33using System.Linq;34using System.Text;35using System.Threading.Tasks;36{37    {38        void Method1();39    }40    {41        public void Method1()42        {43        }44    }45    {46        public void Method1()47        {48            var myInterface = Mock.Create<IMyInterface>();49            var proxyGenerator = new ProxyGenerator();50            var proxy = proxyGenerator.CreateInterfaceProxyWithTargetInterface(myInterface, new MyInterfaceImpl());51            proxy.Method1();52        }53    }54}CreateInterfaceProxyWithTargetInterface
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Telerik.JustMock.Core.Castle.DynamicProxy;7{8    {9        int Add(int a, int b);10        int Subtract(int a, int b);11    }12    {13        static void Main(string[] args)14        {15            var calculatorMock = Mock.Create<ICalculator>();16            Mock.Arrange(() => calculatorMock.Add(1, 2)).Returns(3);17            var calculatorProxy = Mock.CreateProxyWithTargetInterface<ICalculator>(calculatorMock);18            Console.WriteLine(calculatorProxy.Add(1, 2));19            Console.ReadLine();20        }21    }22}CreateInterfaceProxyWithTargetInterface
Using AI Code Generation
1using Telerik.JustMock.Core.Castle.DynamicProxy;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7using Telerik.JustMock.Core.Castle.Core.Interceptor;8{9    {10        static void Main(string[] args)11        {12            var proxyGenerator = new ProxyGenerator();13            var proxy = proxyGenerator.CreateInterfaceProxyWithTargetInterface(typeof(I1), new List<IInterceptor>() { new Interceptor() }, new Target());14            proxy.Foo();15        }16    }17    {18        public void Foo()19        {20            Console.WriteLine("Foo");21        }22    }23    {24        public void Intercept(IInvocation invocation)25        {26            Console.WriteLine("Before");27            invocation.Proceed();28            Console.WriteLine("After");29        }30    }31    {32        void Foo();33    }34}CreateInterfaceProxyWithTargetInterface
Using AI Code Generation
1using System;2using Telerik.JustMock.Core;3using Telerik.JustMock.Core.Castle.DynamicProxy;4using Telerik.JustMock.Helpers;5{6    {7        public static void Main()8        {9            var proxy = Mock.Create<InterfaceToMock>(Constructor.Mocked);10            var generator = new ProxyGenerator();11            var proxy2 = generator.CreateInterfaceProxyWithTargetInterface(typeof(InterfaceToMock), proxy, new ProxyGenerationOptions(), new object[] { 1 });12            proxy2.MethodWithParameters(2);13        }14        {15            void MethodWithParameters(int a);16        }17    }18}19using System;20using Telerik.JustMock;21using Telerik.JustMock.Castle.DynamicProxy;22using Telerik.JustMock.Helpers;23{24    {25        public static void Main()26        {27            var proxy = Mock.Create<InterfaceToMock>(Constructor.Mocked);28            var generator = new ProxyGenerator();29            var proxy2 = generator.CreateInterfaceProxyWithTargetInterface(typeof(InterfaceToMock), proxy, new ProxyGenerationOptions(), new object[] { 1 });30            proxy2.MethodWithParameters(2);31        }32        {33            void MethodWithParameters(int a);34        }CreateInterfaceProxyWithTargetInterface
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using Telerik.JustMock;6using Telerik.JustMock.Core.Castle.DynamicProxy;7using System.Reflection;8{9    {10        public void TestMethod()11        {12            var proxyGenerator = new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator();13            var target = new TestClass();14            var proxy = proxyGenerator.CreateInterfaceProxyWithTargetInterface(typeof(ITestInterface), target, new TestInterceptor());15            proxy.TestMethod();16            Assert.AreEqual("Test", target.TestValue);17        }18    }19    {20        public string TestValue { get; set; }21        public void TestMethod()22        {23            TestValue = "Test";24        }25    }26    {27        void TestMethod();28    }29    {30        public void Intercept(IInvocation invocation)31        {32            var methodInfo = invocation.MethodInvocationTarget;33            invocation.Proceed();34        }35    }36}CreateInterfaceProxyWithTargetInterface
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Telerik.JustMock.Core.Castle.DynamicProxy;7using Telerik.JustMock.Core;8{9    {10        int MyInt { get; set; }11        string MyString { get; set; }12        void MyMethod();13    }14    {15        public int MyInt { get; set; }16        public string MyString { get; set; }17        public void MyMethod()18        {19            Console.WriteLine("MyMethod");20        }21    }22    {23        static void Main(string[] args)24        {25            var myInterfaceImpl = new MyInterfaceImpl();26            var proxyGenerator = new ProxyGenerator();27            var proxy = proxyGenerator.CreateInterfaceProxyWithTargetInterface<IMyInterface>(myInterfaceImpl);28            proxy.MyInt = 10;29            proxy.MyString = "Test";30            proxy.MyMethod();31            Console.WriteLine(proxy.MyInt);32            Console.WriteLine(proxy.MyString);33        }34    }35}36using System;37using System.Collections.Generic;38using System.Linq;39using System.Text;40using System.Threading.Tasks;41using Telerik.JustMock.Core.Castle.DynamicProxy;42using Telerik.JustMock.Core;43{44    {45        int MyInt { get; set; }46        string MyString { get; set; }47        void MyMethod();48    }49    {50        static void Main(string[] args)51        {52            var proxyGenerator = new ProxyGenerator();53            var proxy = proxyGenerator.CreateInterfaceProxyWithoutTarget<IMyInterface>();54            proxy.MyInt = 10;55            proxy.MyString = "Test";56            proxy.MyMethod();57            Console.WriteLine(proxy.MyInt);58            Console.WriteLine(proxy.MyString);59        }60    }61}CreateInterfaceProxyWithTargetInterface
Using AI Code Generation
1using Telerik.JustMock.Core.Castle.DynamicProxy;2using System;3{4    {5        static void Main(string[] args)6        {7            var proxyGenerator = new ProxyGenerator();8            var interfaceProxyWithTarget = proxyGenerator.CreateInterfaceProxyWithTargetInterface(typeof(IInterface), new object[] { }, new InterfaceInterceptor());9            interfaceProxyWithTarget.Method();10        }11    }12    {13        void Method();14    }15    {16        public void Intercept(IInvocation invocation)17        {18            Console.WriteLine("Intercepted");19        }20    }21}22using Telerik.JustMock.Core.Castle.DynamicProxy;23using System;24{25    {26        static void Main(string[] args)27        {28            var proxyGenerator = new ProxyGenerator();29            var interfaceProxyWithTarget = proxyGenerator.CreateInterfaceProxyWithoutTarget(typeof(IInterface), new InterfaceInterceptor());30            interfaceProxyWithTarget.Method();31        }32    }33    {34        void Method();35    }36    {37        public void Intercept(IInvocation invocation)38        {39            Console.WriteLine("Intercepted");40        }41    }42}Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
