How to use CheckNotGenericTypeDefinition method of Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator class

Best JustMockLite code snippet using Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator.CheckNotGenericTypeDefinition

ProxyGenerator.cs

Source:ProxyGenerator.cs Github

copy

Full Screen

...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 }541 if (interceptors == null)542 {543 throw new ArgumentNullException("interceptors");544 }545 if (!interfaceToProxy.GetTypeInfo().IsInterface)546 {547 throw new ArgumentException("Specified type is not an interface", "interfaceToProxy");548 }549 var isRemotingProxy = false;550#if FEATURE_REMOTING551 if (target != null)552 {553 isRemotingProxy = RemotingServices.IsTransparentProxy(target);554 if (!isRemotingProxy && Marshal.IsComObject(target))555 {556 var interfaceId = interfaceToProxy.GUID;557 if (interfaceId != Guid.Empty)558 {559 var iUnknown = Marshal.GetIUnknownForObject(target); // Increment the reference count560 var interfacePointer = IntPtr.Zero;561 var result = Marshal.QueryInterface(iUnknown, ref interfaceId, out interfacePointer); // Increment the reference count562 var isInterfacePointerNull = interfacePointer == IntPtr.Zero;563 Marshal.Release(iUnknown); // Decrement the reference count564 if (!isInterfacePointerNull)565 {566 Marshal.Release(interfacePointer); // Decrement the reference count567 }568 if (result == 0 && isInterfacePointerNull)569 {570 throw new ArgumentException("Target COM object does not implement interface " + interfaceToProxy.FullName,571 "target");572 }573 }574 }575 }576#endif577 CheckNotGenericTypeDefinition(interfaceToProxy, "interfaceToProxy");578 CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, "additionalInterfacesToProxy");579 var generatedType = CreateInterfaceProxyTypeWithTargetInterface(interfaceToProxy, additionalInterfacesToProxy,580 options);581 var arguments = GetConstructorArguments(target, interceptors, options);582 if (isRemotingProxy)583 {584 var constructors = generatedType.GetConstructors();585 // one .ctor to rule them all586 Debug.Assert(constructors.Length == 1, "constructors.Length == 1");587 return constructors[0].Invoke(arguments.ToArray());588 }589 return Activator.CreateInstance(generatedType, arguments.ToArray());590 }591 /// <summary>592 /// Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on target object generated at runtime with given <paramref593 /// name = "interceptor" />.594 /// </summary>595 /// <typeparam name = "TInterface">Type of the interface which will be proxied.</typeparam>596 /// <param name = "interceptor">The interceptors called during the invocation of proxied methods.</param>597 /// <returns>598 /// Object proxying calls to members of <typeparamref name = "TInterface" /> types on generated target object.599 /// </returns>600 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptor" /> array is a null reference (Nothing in Visual Basic).</exception>601 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" /> is not an interface type.</exception>602 /// <remarks>603 /// Since this method uses an empty-shell implementation of interfaces to proxy generated at runtime, the actual implementation of proxied methods must be provided by given <see604 /// cref = "IInterceptor" /> implementations.605 /// They are responsible for setting return value (and out parameters) on proxied methods. It is also illegal for an interceptor to call <see606 /// cref = "IInvocation.Proceed" />, since there's no actual implementation to proceed with.607 /// As a result of that also at least one <see cref = "IInterceptor" /> implementation must be provided.608 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.609 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.610 /// </remarks>611 public TInterface CreateInterfaceProxyWithoutTarget<TInterface>(IInterceptor interceptor)612 where TInterface : class613 {614 return (TInterface)CreateInterfaceProxyWithoutTarget(typeof(TInterface), interceptor);615 }616 /// <summary>617 /// Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on target object generated at runtime with given <paramref618 /// name = "interceptors" />.619 /// </summary>620 /// <typeparam name = "TInterface">Type of the interface which will be proxied.</typeparam>621 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>622 /// <returns>623 /// Object proxying calls to members of <typeparamref name = "TInterface" /> types on generated target object.624 /// </returns>625 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>626 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" /> is not an interface type.</exception>627 /// <remarks>628 /// Since this method uses an empty-shell implementation of interfaces to proxy generated at runtime, the actual implementation of proxied methods must be provided by given <see629 /// cref = "IInterceptor" /> implementations.630 /// They are responsible for setting return value (and out parameters) on proxied methods. It is also illegal for an interceptor to call <see631 /// cref = "IInvocation.Proceed" />, since there's no actual implementation to proceed with.632 /// As a result of that also at least one <see cref = "IInterceptor" /> implementation must be provided.633 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.634 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.635 /// </remarks>636 public TInterface CreateInterfaceProxyWithoutTarget<TInterface>(params IInterceptor[] interceptors)637 where TInterface : class638 {639 return (TInterface)CreateInterfaceProxyWithoutTarget(typeof(TInterface), interceptors);640 }641 /// <summary>642 /// Creates proxy object intercepting calls to members of interface <typeparamref name = "TInterface" /> on target object generated at runtime with given <paramref643 /// name = "interceptors" />.644 /// </summary>645 /// <typeparam name = "TInterface">Type of the interface which will be proxied.</typeparam>646 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>647 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>648 /// <returns>649 /// Object proxying calls to members of <typeparamref name = "TInterface" /> types on generated target object.650 /// </returns>651 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>652 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TInterface" /> is not an interface type.</exception>653 /// <remarks>654 /// Since this method uses an empty-shell implementation of interfaces to proxy generated at runtime, the actual implementation of proxied methods must be provided by given <see655 /// cref = "IInterceptor" /> implementations.656 /// They are responsible for setting return value (and out parameters) on proxied methods. It is also illegal for an interceptor to call <see657 /// cref = "IInvocation.Proceed" />, since there's no actual implementation to proceed with.658 /// As a result of that also at least one <see cref = "IInterceptor" /> implementation must be provided.659 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.660 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.661 /// </remarks>662 public TInterface CreateInterfaceProxyWithoutTarget<TInterface>(ProxyGenerationOptions options,663 params IInterceptor[] interceptors)664 where TInterface : class665 {666 return (TInterface)CreateInterfaceProxyWithoutTarget(typeof(TInterface), Type.EmptyTypes, options, interceptors);667 }668 /// <summary>669 /// Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on target object generated at runtime with given <paramref670 /// name = "interceptor" />.671 /// </summary>672 /// <param name = "interfaceToProxy">Type of the interface which will be proxied.</param>673 /// <param name = "interceptor">The interceptors called during the invocation of proxied methods.</param>674 /// <returns>675 /// Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on generated target object.676 /// </returns>677 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>678 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptor" /> array is a null reference (Nothing in Visual Basic).</exception>679 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>680 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>681 /// <remarks>682 /// Since this method uses an empty-shell implementation of interfaces to proxy generated at runtime, the actual implementation of proxied methods must be provided by given <see683 /// cref = "IInterceptor" /> implementations.684 /// They are responsible for setting return value (and out parameters) on proxied methods. It is also illegal for an interceptor to call <see685 /// cref = "IInvocation.Proceed" />, since there's no actual implementation to proceed with.686 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.687 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.688 /// </remarks>689 public object CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, IInterceptor interceptor)690 {691 return CreateInterfaceProxyWithoutTarget(interfaceToProxy, Type.EmptyTypes, ProxyGenerationOptions.Default,692 interceptor);693 }694 /// <summary>695 /// Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on target object generated at runtime with given <paramref696 /// name = "interceptors" />.697 /// </summary>698 /// <param name = "interfaceToProxy">Type of the interface which will be proxied.</param>699 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>700 /// <returns>701 /// Object proxying calls to members of <paramref name = "interfaceToProxy" /> type on generated target object.702 /// </returns>703 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>704 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>705 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>706 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>707 /// <remarks>708 /// Since this method uses an empty-shell implementation of interfaces to proxy generated at runtime, the actual implementation of proxied methods must be provided by given <see709 /// cref = "IInterceptor" /> implementations.710 /// They are responsible for setting return value (and out parameters) on proxied methods. It is also illegal for an interceptor to call <see711 /// cref = "IInvocation.Proceed" />, since there's no actual implementation to proceed with.712 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.713 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.714 /// </remarks>715 public object CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, params IInterceptor[] interceptors)716 {717 return CreateInterfaceProxyWithoutTarget(interfaceToProxy, Type.EmptyTypes, ProxyGenerationOptions.Default,718 interceptors);719 }720 /// <summary>721 /// Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on target object generated at runtime with given <paramref722 /// name = "interceptors" />.723 /// </summary>724 /// <param name = "interfaceToProxy">Type of the interface which will be proxied.</param>725 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>726 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>727 /// <returns>728 /// Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref729 /// name = "additionalInterfacesToProxy" /> types on generated target object.730 /// </returns>731 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>732 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>733 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref734 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>735 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>736 /// <remarks>737 /// Since this method uses an empty-shell implementation of interfaces to proxy generated at runtime, the actual implementation of proxied methods must be provided by given <see738 /// cref = "IInterceptor" /> implementations.739 /// They are responsible for setting return value (and out parameters) on proxied methods. It is also illegal for an interceptor to call <see740 /// cref = "IInvocation.Proceed" />, since there's no actual implementation to proceed with.741 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.742 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.743 /// </remarks>744 public object CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,745 params IInterceptor[] interceptors)746 {747 return CreateInterfaceProxyWithoutTarget(interfaceToProxy, additionalInterfacesToProxy,748 ProxyGenerationOptions.Default, interceptors);749 }750 /// <summary>751 /// Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on target object generated at runtime with given <paramref752 /// name = "interceptors" />.753 /// </summary>754 /// <param name = "interfaceToProxy">Type of the interface which will be proxied.</param>755 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>756 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>757 /// <returns>758 /// Object proxying calls to members of <paramref name = "interfaceToProxy" /> on generated target object.759 /// </returns>760 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>761 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>762 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is a generic type definition.</exception>763 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>764 /// <remarks>765 /// They are responsible for setting return value (and out parameters) on proxied methods. It is also illegal for an interceptor to call <see766 /// cref = "IInvocation.Proceed" />, since there's no actual implementation to proceed with.767 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.768 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.769 /// </remarks>770 public object CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, ProxyGenerationOptions options,771 params IInterceptor[] interceptors)772 {773 return CreateInterfaceProxyWithoutTarget(interfaceToProxy, Type.EmptyTypes, options, interceptors);774 }775 /// <summary>776 /// Creates proxy object intercepting calls to members of interface <paramref name = "interfaceToProxy" /> on target object generated at runtime with given <paramref777 /// name = "interceptors" />.778 /// </summary>779 /// <param name = "interfaceToProxy">Type of the interface which will be proxied.</param>780 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>781 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>782 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>783 /// <returns>784 /// Object proxying calls to members of <paramref name = "interfaceToProxy" /> and <paramref785 /// name = "additionalInterfacesToProxy" /> types on generated target object.786 /// </returns>787 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interfaceToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>788 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "interceptors" /> array is a null reference (Nothing in Visual Basic).</exception>789 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> or any of <paramref790 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>791 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "interfaceToProxy" /> is not an interface type.</exception>792 /// <remarks>793 /// Since this method uses an empty-shell implementation of <paramref name = "additionalInterfacesToProxy" /> to proxy generated at runtime, the actual implementation of proxied methods must be provided by given <see794 /// cref = "IInterceptor" /> implementations.795 /// They are responsible for setting return value (and out parameters) on proxied methods. It is also illegal for an interceptor to call <see796 /// cref = "IInvocation.Proceed" />, since there's no actual implementation to proceed with.797 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.798 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.799 /// </remarks>800 public virtual object CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,801 ProxyGenerationOptions options,802 params IInterceptor[] interceptors)803 {804 if (interfaceToProxy == null)805 {806 throw new ArgumentNullException("interfaceToProxy");807 }808 if (interceptors == null)809 {810 throw new ArgumentNullException("interceptors");811 }812 if (!interfaceToProxy.GetTypeInfo().IsInterface)813 {814 throw new ArgumentException("Specified type is not an interface", "interfaceToProxy");815 }816 CheckNotGenericTypeDefinition(interfaceToProxy, "interfaceToProxy");817 CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, "additionalInterfacesToProxy");818 var generatedType = CreateInterfaceProxyTypeWithoutTarget(interfaceToProxy, additionalInterfacesToProxy, options);819 var arguments = GetConstructorArguments(null, interceptors, options);820 return Activator.CreateInstance(generatedType, arguments.ToArray());821 }822 /// <summary>823 /// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref824 /// name = "interceptors" />.825 /// </summary>826 /// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>827 /// <param name = "target">The target object, calls to which will be intercepted.</param>828 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>829 /// <returns>830 /// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref831 /// name = "TClass" /> type.832 /// </returns>833 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>834 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <typeparamref name = "TClass" />.</exception>835 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>836 /// <remarks>837 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.838 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.839 /// </remarks>840 public TClass CreateClassProxyWithTarget<TClass>(TClass target, params IInterceptor[] interceptors)841 where TClass : class842 {843 return (TClass)CreateClassProxyWithTarget(typeof(TClass),844 Type.EmptyTypes,845 target,846 ProxyGenerationOptions.Default,847 new object[0],848 interceptors);849 }850 /// <summary>851 /// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref852 /// name = "interceptors" />.853 /// </summary>854 /// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>855 /// <param name = "target">The target object, calls to which will be intercepted.</param>856 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>857 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>858 /// <returns>859 /// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref860 /// name = "TClass" /> type.861 /// </returns>862 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>863 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <typeparamref name = "TClass" />.</exception>864 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>865 /// <remarks>866 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.867 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.868 /// </remarks>869 public TClass CreateClassProxyWithTarget<TClass>(TClass target, ProxyGenerationOptions options,870 params IInterceptor[] interceptors) where TClass : class871 {872 return (TClass)CreateClassProxyWithTarget(typeof(TClass),873 Type.EmptyTypes,874 target,875 options,876 new object[0],877 interceptors);878 }879 /// <summary>880 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref881 /// name = "interceptors" />.882 /// </summary>883 /// <param name = "classToProxy">Type of class which will be proxied.</param>884 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>885 /// <param name = "target">The target object, calls to which will be intercepted.</param>886 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>887 /// <returns>888 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref889 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.890 /// </returns>891 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>892 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref893 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>894 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>895 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>896 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>897 /// <remarks>898 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.899 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.900 /// </remarks>901 public object CreateClassProxyWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy, object target,902 params IInterceptor[] interceptors)903 {904 return CreateClassProxyWithTarget(classToProxy,905 additionalInterfacesToProxy,906 target,907 ProxyGenerationOptions.Default,908 new object[0],909 interceptors);910 }911 /// <summary>912 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref913 /// name = "interceptors" />.914 /// </summary>915 /// <param name = "classToProxy">Type of class which will be proxied.</param>916 /// <param name = "target">The target object, calls to which will be intercepted.</param>917 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>918 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>919 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>920 /// <returns>921 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref922 /// name = "classToProxy" /> type.923 /// </returns>924 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>925 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>926 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>927 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref928 /// name = "constructorArguments" />.</exception>929 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>930 /// <remarks>931 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.932 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.933 /// </remarks>934 public object CreateClassProxyWithTarget(Type classToProxy, object target, ProxyGenerationOptions options,935 object[] constructorArguments, params IInterceptor[] interceptors)936 {937 return CreateClassProxyWithTarget(classToProxy,938 Type.EmptyTypes,939 target,940 options,941 constructorArguments,942 interceptors);943 }944 /// <summary>945 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref946 /// name = "interceptors" />.947 /// </summary>948 /// <param name = "classToProxy">Type of class which will be proxied.</param>949 /// <param name = "target">The target object, calls to which will be intercepted.</param>950 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>951 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>952 /// <returns>953 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref954 /// name = "classToProxy" /> type.955 /// </returns>956 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>957 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>958 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>959 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref960 /// name = "constructorArguments" />.</exception>961 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>962 /// <remarks>963 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.964 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.965 /// </remarks>966 public object CreateClassProxyWithTarget(Type classToProxy, object target, object[] constructorArguments,967 params IInterceptor[] interceptors)968 {969 return CreateClassProxyWithTarget(classToProxy,970 Type.EmptyTypes,971 target,972 ProxyGenerationOptions.Default,973 constructorArguments,974 interceptors);975 }976 /// <summary>977 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref978 /// name = "interceptors" />.979 /// </summary>980 /// <param name = "classToProxy">Type of class which will be proxied.</param>981 /// <param name = "target">The target object, calls to which will be intercepted.</param>982 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>983 /// <returns>984 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref985 /// name = "classToProxy" /> type.986 /// </returns>987 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>988 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>989 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>990 /// <exception cref = "ArgumentException">Thrown when no parameterless constructor exists on type <paramref991 /// name = "classToProxy" />.</exception>992 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>993 /// <remarks>994 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.995 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.996 /// </remarks>997 public object CreateClassProxyWithTarget(Type classToProxy, object target, params IInterceptor[] interceptors)998 {999 return CreateClassProxyWithTarget(classToProxy,1000 Type.EmptyTypes,1001 target,1002 ProxyGenerationOptions.Default,1003 new object[0],1004 interceptors);1005 }1006 /// <summary>1007 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1008 /// name = "interceptors" />.1009 /// </summary>1010 /// <param name = "classToProxy">Type of class which will be proxied.</param>1011 /// <param name = "target">The target object, calls to which will be intercepted.</param>1012 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1013 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1014 /// <returns>1015 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1016 /// name = "classToProxy" /> type.1017 /// </returns>1018 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1019 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>1020 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>1021 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1022 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>1023 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1024 /// <remarks>1025 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1026 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1027 /// </remarks>1028 public object CreateClassProxyWithTarget(Type classToProxy, object target, ProxyGenerationOptions options,1029 params IInterceptor[] interceptors)1030 {1031 return CreateClassProxyWithTarget(classToProxy,1032 Type.EmptyTypes,1033 target,1034 options,1035 new object[0],1036 interceptors);1037 }1038 /// <summary>1039 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1040 /// name = "interceptors" />.1041 /// </summary>1042 /// <param name = "classToProxy">Type of class which will be proxied.</param>1043 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>1044 /// <param name = "target">The target object, calls to which will be intercepted.</param>1045 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1046 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1047 /// <returns>1048 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1049 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.1050 /// </returns>1051 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1052 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>1053 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref1054 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>1055 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1056 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>1057 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1058 /// <remarks>1059 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1060 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1061 /// </remarks>1062 public object CreateClassProxyWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy, object target,1063 ProxyGenerationOptions options, params IInterceptor[] interceptors)1064 {1065 return CreateClassProxyWithTarget(classToProxy,1066 additionalInterfacesToProxy,1067 target,1068 options,1069 new object[0],1070 interceptors);1071 }1072 /// <summary>1073 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1074 /// name = "interceptors" />.1075 /// </summary>1076 /// <param name = "classToProxy">Type of class which will be proxied.</param>1077 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>1078 /// <param name = "target">The target object, calls to which will be intercepted.</param>1079 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1080 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>1081 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1082 /// <returns>1083 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1084 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.1085 /// </returns>1086 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1087 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>1088 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref1089 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>1090 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1091 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref1092 /// name = "constructorArguments" />.</exception>1093 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1094 /// <remarks>1095 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1096 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1097 /// </remarks>1098 public virtual object CreateClassProxyWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy, object target,1099 ProxyGenerationOptions options, object[] constructorArguments,1100 params IInterceptor[] interceptors)1101 {1102 if (classToProxy == null)1103 {1104 throw new ArgumentNullException("classToProxy");1105 }1106 if (options == null)1107 {1108 throw new ArgumentNullException("options");1109 }1110 if (!classToProxy.GetTypeInfo().IsClass)1111 {1112 throw new ArgumentException("'classToProxy' must be a class", "classToProxy");1113 }1114 CheckNotGenericTypeDefinition(classToProxy, "classToProxy");1115 CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, "additionalInterfacesToProxy");1116 var proxyType = CreateClassProxyTypeWithTarget(classToProxy, additionalInterfacesToProxy, options);1117 // create constructor arguments (initialized with mixin implementations, interceptors and target type constructor arguments)1118 var arguments = BuildArgumentListForClassProxyWithTarget(target, options, interceptors);1119 if (constructorArguments != null && constructorArguments.Length != 0)1120 {1121 arguments.AddRange(constructorArguments);1122 }1123 return CreateClassProxyInstance(proxyType, arguments, classToProxy, constructorArguments);1124 }1125 /// <summary>1126 /// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref1127 /// name = "interceptors" />.1128 /// </summary>1129 /// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>1130 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1131 /// <returns>1132 /// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref1133 /// name = "TClass" /> type.1134 /// </returns>1135 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>1136 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <typeparamref name = "TClass" />.</exception>1137 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>1138 /// <remarks>1139 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1140 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1141 /// </remarks>1142 public TClass CreateClassProxy<TClass>(params IInterceptor[] interceptors) where TClass : class1143 {1144 return (TClass)CreateClassProxy(typeof(TClass), ProxyGenerationOptions.Default, interceptors);1145 }1146 /// <summary>1147 /// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref1148 /// name = "interceptors" />.1149 /// </summary>1150 /// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>1151 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1152 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1153 /// <returns>1154 /// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref1155 /// name = "TClass" /> type.1156 /// </returns>1157 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>1158 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <typeparamref name = "TClass" />.</exception>1159 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>1160 /// <remarks>1161 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1162 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1163 /// </remarks>1164 public TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, params IInterceptor[] interceptors)1165 where TClass : class1166 {1167 return (TClass)CreateClassProxy(typeof(TClass), options, interceptors);1168 }1169 /// <summary>1170 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1171 /// name = "interceptors" />.1172 /// </summary>1173 /// <param name = "classToProxy">Type of class which will be proxied.</param>1174 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>1175 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1176 /// <returns>1177 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1178 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.1179 /// </returns>1180 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1181 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref1182 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>1183 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1184 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>1185 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1186 /// <remarks>1187 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1188 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1189 /// </remarks>1190 public object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy,1191 params IInterceptor[] interceptors)1192 {1193 return CreateClassProxy(classToProxy, additionalInterfacesToProxy, ProxyGenerationOptions.Default, interceptors);1194 }1195 /// <summary>1196 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1197 /// name = "interceptors" />.1198 /// </summary>1199 /// <param name = "classToProxy">Type of class which will be proxied.</param>1200 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1201 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>1202 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1203 /// <returns>1204 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1205 /// name = "classToProxy" /> type.1206 /// </returns>1207 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1208 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>1209 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1210 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref1211 /// name = "constructorArguments" />.</exception>1212 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1213 /// <remarks>1214 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1215 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1216 /// </remarks>1217 public object CreateClassProxy(Type classToProxy, ProxyGenerationOptions options, object[] constructorArguments,1218 params IInterceptor[] interceptors)1219 {1220 return CreateClassProxy(classToProxy, null, options, constructorArguments, interceptors);1221 }1222 /// <summary>1223 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1224 /// name = "interceptors" />.1225 /// </summary>1226 /// <param name = "classToProxy">Type of class which will be proxied.</param>1227 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>1228 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1229 /// <returns>1230 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1231 /// name = "classToProxy" /> type.1232 /// </returns>1233 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1234 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>1235 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1236 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref1237 /// name = "constructorArguments" />.</exception>1238 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1239 /// <remarks>1240 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1241 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1242 /// </remarks>1243 public object CreateClassProxy(Type classToProxy, object[] constructorArguments, params IInterceptor[] interceptors)1244 {1245 return CreateClassProxy(classToProxy, null, ProxyGenerationOptions.Default, constructorArguments, interceptors);1246 }1247 /// <summary>1248 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1249 /// name = "interceptors" />.1250 /// </summary>1251 /// <param name = "classToProxy">Type of class which will be proxied.</param>1252 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1253 /// <returns>1254 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1255 /// name = "classToProxy" /> type.1256 /// </returns>1257 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1258 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>1259 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1260 /// <exception cref = "ArgumentException">Thrown when no parameterless constructor exists on type <paramref1261 /// name = "classToProxy" />.</exception>1262 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1263 /// <remarks>1264 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1265 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1266 /// </remarks>1267 public object CreateClassProxy(Type classToProxy, params IInterceptor[] interceptors)1268 {1269 return CreateClassProxy(classToProxy, null, ProxyGenerationOptions.Default,1270 null, interceptors);1271 }1272 /// <summary>1273 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1274 /// name = "interceptors" />.1275 /// </summary>1276 /// <param name = "classToProxy">Type of class which will be proxied.</param>1277 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1278 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1279 /// <returns>1280 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1281 /// name = "classToProxy" /> type.1282 /// </returns>1283 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1284 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>1285 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>1286 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1287 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>1288 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1289 /// <remarks>1290 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1291 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1292 /// </remarks>1293 public object CreateClassProxy(Type classToProxy, ProxyGenerationOptions options, params IInterceptor[] interceptors)1294 {1295 return CreateClassProxy(classToProxy, null, options, interceptors);1296 }1297 /// <summary>1298 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1299 /// name = "interceptors" />.1300 /// </summary>1301 /// <param name = "classToProxy">Type of class which will be proxied.</param>1302 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>1303 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1304 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1305 /// <returns>1306 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1307 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.1308 /// </returns>1309 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1310 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>1311 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref1312 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>1313 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1314 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>1315 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1316 /// <remarks>1317 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1318 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1319 /// </remarks>1320 public object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options,1321 params IInterceptor[] interceptors)1322 {1323 return CreateClassProxy(classToProxy, additionalInterfacesToProxy, options, null, interceptors);1324 }1325 /// <summary>1326 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref1327 /// name = "interceptors" />.1328 /// </summary>1329 /// <param name = "classToProxy">Type of class which will be proxied.</param>1330 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>1331 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>1332 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>1333 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>1334 /// <returns>1335 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref1336 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.1337 /// </returns>1338 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>1339 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>1340 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref1341 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>1342 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>1343 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref1344 /// name = "constructorArguments" />.</exception>1345 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>1346 /// <remarks>1347 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.1348 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.1349 /// </remarks>1350 public virtual object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy,1351 ProxyGenerationOptions options,1352 object[] constructorArguments, params IInterceptor[] interceptors)1353 {1354 if (classToProxy == null)1355 {1356 throw new ArgumentNullException("classToProxy");1357 }1358 if (options == null)1359 {1360 throw new ArgumentNullException("options");1361 }1362 if (!classToProxy.GetTypeInfo().IsClass)1363 {1364 throw new ArgumentException("'classToProxy' must be a class", "classToProxy");1365 }1366 CheckNotGenericTypeDefinition(classToProxy, "classToProxy");1367 CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, "additionalInterfacesToProxy");1368 var proxyType = CreateClassProxyType(classToProxy, additionalInterfacesToProxy, options);1369 // create constructor arguments (initialized with mixin implementations, interceptors and target type constructor arguments)1370 var arguments = BuildArgumentListForClassProxy(options, interceptors);1371 if (constructorArguments != null && constructorArguments.Length != 0)1372 {1373 arguments.AddRange(constructorArguments);1374 }1375 return CreateClassProxyInstance(proxyType, arguments, classToProxy, constructorArguments);1376 }1377 protected object CreateClassProxyInstance(Type proxyType, List<object> proxyArguments, Type classToProxy,1378 object[] constructorArguments)1379 {1380 try1381 {1382 return proxyType.CreateObject(proxyArguments.ToArray());1383 }1384 catch (MissingMethodException)1385 {1386 var message = new StringBuilder();1387 message.AppendFormat("Can not instantiate proxy of class: {0}.", classToProxy.FullName);1388 message.AppendLine();1389 if (constructorArguments == null || constructorArguments.Length == 0)1390 {1391 message.Append("Could not find a parameterless constructor.");1392 }1393 else1394 {1395 message.AppendLine("Could not find a constructor that would match given arguments:");1396 foreach (var argument in constructorArguments)1397 {1398 var argumentText = argument == null ? "<null>" : argument.GetType().ToString();1399 message.AppendLine(argumentText);1400 }1401 }1402 throw new InvalidProxyConstructorArgumentsException(message.ToString(),proxyType,classToProxy);1403 }1404 }1405 protected void CheckNotGenericTypeDefinition(Type type, string argumentName)1406 {1407 if (type != null && type.GetTypeInfo().IsGenericTypeDefinition)1408 {1409 throw new GeneratorException(string.Format("Can not create proxy for type {0} because it is an open generic type.",1410 type.GetBestName()));1411 }1412 }1413 protected void CheckNotGenericTypeDefinitions(IEnumerable<Type> types, string argumentName)1414 {1415 if (types == null)1416 {1417 return;1418 }1419 foreach (var t in types)1420 {1421 CheckNotGenericTypeDefinition(t, argumentName);1422 }1423 }1424 protected List<object> BuildArgumentListForClassProxyWithTarget(object target, ProxyGenerationOptions options,1425 IInterceptor[] interceptors)1426 {1427 var arguments = new List<object>();1428 arguments.Add(target);1429 arguments.AddRange(options.MixinData.Mixins);1430 arguments.Add(interceptors);1431 if (options.Selector != null)1432 {1433 arguments.Add(options.Selector);1434 }1435 return arguments;...

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Telerik.JustMock.Core;7using Telerik.JustMock.Core.Castle.DynamicProxy;8using Telerik.JustMock.Helpers;9{10 {11 void Method();12 }13 {14 public void Method()15 {16 Console.WriteLine("Hello World");17 }18 }19 {20 static void Main(string[] args)21 {22 var mock = Mock.Create<IInterface>();23 var proxyGen = new ProxyGenerator();24 proxyGen.CheckNotGenericTypeDefinition(typeof(Class1));25 Mock.Arrange(() => mock.Method()).DoInstead(() => Console.WriteLine("Hello World"));26 mock.Method();27 }28 }29}30using System;31using System.Collections.Generic;32using System.Linq;33using System.Text;34using System.Threading.Tasks;35using Telerik.JustMock.Core;36using Telerik.JustMock.Core.Castle.DynamicProxy;37using Telerik.JustMock.Helpers;38{39 {40 void Method();41 }42 {43 public void Method()44 {45 Console.WriteLine("Hello World");46 }47 }48 {49 static void Main(string[] args)50 {51 var mock = Mock.Create<IInterface>();52 var proxyGen = new ProxyGenerator();53 var type = typeof(Class1);54 if (!type.IsGenericTypeDefinition)55 {56 proxyGen.CheckNotGenericTypeDefinition(type);57 }58 Mock.Arrange(() => mock.Method()).DoInstead(() => Console.WriteLine("Hello World"));59 mock.Method();60 }61 }62}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

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 static void Main(string[] args)10 {11 var proxyGenerator = new ProxyGenerator();12 var result = proxyGenerator.CheckNotGenericTypeDefinition(typeof(int));13 Console.WriteLine(result);14 }15 }16}17CheckNotGenericTypeDefinition Method (Type, string)

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Telerik.JustMock;7using Telerik.JustMock.Core.Castle.DynamicProxy;8{9 {10 public Class1()11 {12 var proxyGenerator = new ProxyGenerator();13 proxyGenerator.CheckNotGenericTypeDefinition(typeof(List<>));14 }15 }16}17 at Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator.EnsureNotGenericTypeDefinition(Type type, String argumentName)18 at Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator.CheckNotGenericTypeDefinition(Type type)19 at JustMockUnitTestProject1.Class1..ctor() in C:\Users\username\Documents\Visual Studio 2015\Projects\JustMockUnitTestProject1\JustMockUnitTestProject1\Class1.cs:line 17

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Telerik.JustMock;7using Telerik.JustMock.Core;8using Telerik.JustMock.Helpers;9{10 {11 public void Method()12 {13 var mock = Mock.Create<Interface1>();14 Mock.Arrange(() => mock.Method1(Arg.IsAny<int>())).DoNothing();15 mock.Method1(1);16 }17 }18 {19 void Method1(int i);20 }21}22using System;23using System.Collections.Generic;24using System.Linq;25using System.Text;26using System.Threading.Tasks;27using Telerik.JustMock;28using Telerik.JustMock.Core;29using Telerik.JustMock.Helpers;30{31 {32 public void Method()33 {34 var mock = Mock.Create<Interface1>();35 Mock.Arrange(() => mock.Method1(Arg.IsAny<int>())).DoNothing();36 mock.Method1(1);37 }38 }39 {40 void Method1(int i);41 }42}43using System;44using System.Collections.Generic;45using System.Linq;46using System.Text;47using System.Threading.Tasks;48using Telerik.JustMock;49using Telerik.JustMock.Core;50using Telerik.JustMock.Helpers;51{52 {53 public void Method()54 {55 var mock = Mock.Create<Interface1>();56 Mock.Arrange(() => mock.Method1(Arg.IsAny<int>())).DoNothing();57 mock.Method1(1);58 }59 }60 {61 void Method1(int i);62 }63}64using System;65using System.Collections.Generic;66using System.Linq;67using System.Text;68using System.Threading.Tasks;69using Telerik.JustMock;70using Telerik.JustMock.Core;71using Telerik.JustMock.Helpers;72{

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock.Core.Castle.DynamicProxy;3{4 {5 static void Main(string[] args)6 {7 ProxyGenerator proxyGenerator = new ProxyGenerator();8 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");9 }10 }11 {12 }13}14using System;15using Telerik.JustMock.Core.Castle.DynamicProxy;16{17 {18 static void Main(string[] args)19 {20 ProxyGenerator proxyGenerator = new ProxyGenerator();21 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");22 }23 }24 {25 }26}27using System;28using Telerik.JustMock.Core.Castle.DynamicProxy;29{30 {31 static void Main(string[] args)32 {33 ProxyGenerator proxyGenerator = new ProxyGenerator();34 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");35 }36 }37 {38 }39}40using System;41using Telerik.JustMock.Core.Castle.DynamicProxy;42{43 {44 static void Main(string[] args)45 {46 ProxyGenerator proxyGenerator = new ProxyGenerator();47 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");48 }49 }50 {51 }52}53using System;54using Telerik.JustMock.Core.Castle.DynamicProxy;55{56 {57 static void Main(string[] args)58 {59 ProxyGenerator proxyGenerator = new ProxyGenerator();60 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");61 }62 }63 {64 }65}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using Telerik.JustMock;6using Telerik.JustMock.Core.Castle.DynamicProxy;7using Telerik.JustMock.Helpers;8{9 {10 public void TestMethod()11 {12 var mock = Mock.Create<TestClass>();13 var proxyGenerator = Mock.Create<ProxyGenerator>();14 Mock.Arrange(() => proxyGenerator.CheckNotGenericTypeDefinition(Arg.AnyType, Arg.AnyString)).OccursOnce();15 }16 }17 {18 }19}20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using Telerik.JustMock;25using Telerik.JustMock.Core.Castle.DynamicProxy;26using Telerik.JustMock.Helpers;27{28 {29 public void TestMethod()30 {31 var mock = Mock.Create<TestClass>();32 var proxyGenerator = Mock.Create<ProxyGenerator>();33 Mock.Arrange(() => proxyGenerator.CheckNotGenericTypeDefinition(Arg.AnyType, Arg.AnyString)).OccursOnce();34 }35 }36 {37 }38}39using System;40using System.Collections.Generic;41using System.Linq;42using System.Text;43using Telerik.JustMock;44using Telerik.JustMock.Core.Castle.DynamicProxy;45using Telerik.JustMock.Helpers;46{47 {48 public void TestMethod()49 {50 var mock = Mock.Create<TestClass>();51 var proxyGenerator = Mock.Create<ProxyGenerator>();52 Mock.Arrange(() => proxyGenerator.CheckNotGenericTypeDefinition(Arg.AnyType, Arg.AnyString)).OccursOnce();53 }54 }55 {56 }57}58using System;59using System.Collections.Generic;60using System.Linq;61using System.Text;62using Telerik.JustMock;63using Telerik.JustMock.Core.Castle.DynamicProxy;64using Telerik.JustMock.Helpers;

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock.Core;3{4 {5 public void Method1()6 {7 var proxyGenerator = new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator();8 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1));9 }10 }11}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

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 static void Main(string[] args)10 {11 ProxyGenerator proxyGenerator = new ProxyGenerator();12 Type type = typeof(List<>);13 Console.WriteLine(proxyGenerator.CheckNotGenericTypeDefinition(type));14 Console.ReadKey();15 }16 }17}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

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 static void Main(string[] args)10 {11 ProxyGenerator proxyGenerator = new ProxyGenerator();12 var result = proxyGenerator.CheckNotGenericTypeDefinition(typeof(List<>));13 Console.WriteLine(result);14 }15 }16}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock;3{4 {5 string Get();6 }7 {8 public IMyInterface MyProperty { get; set; }9 }10 {11 public MyType MyProperty { get; set; }12 }13 {14 public MyOtherType MyProperty { get; set; }15 }16 {17 public MyOtherOtherType MyProperty { get; set; }18 }19 {20 public MyOtherOtherOtherType MyProperty { get; set; }21 }22 {23 public MyOtherOtherOtherOtherType MyProperty { get; set; }24 }25 {26 public MyOtherOtherOtherOtherOtherType MyProperty { get; set; }27 }28 {29 public MyOtherOtherOtherOtherOtherOtherType MyProperty { get; set; }30 }31 {32 public MyOtherOtherOtherOtherOtherOtherOtherType MyProperty { get; set; }33 }34 {35 public MyOtherOtherOtherOtherOtherOtherOtherOtherType MyProperty { get; set; }36 }

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock.Core.Castle.DynamicProxy;3{4 {5 static void Main(string[] args)6 {7 ProxyGenerator proxyGenerator = new ProxyGenerator();8 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");9 }10 }11 {12 }13}14using System;15using Telerik.JustMock.Core.Castle.DynamicProxy;16{17 {18 static void Main(string[] args)19 {20 ProxyGenerator proxyGenerator = new ProxyGenerator();21 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");22 }23 }24 {25 }26}27 }28 }29 {30 }31}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using Telerik.JustMock;6using Telerik.JustMock.Core.Castle.DynamicProxy;7using Telerik.JustMock.Helpers;8{9 {10 public void TestMethod()11 {12 var mock = Mock.Create<TestClass>();13 var proxyGenerator = Mock.Create<ProxyGenerator>();14 Mock.Arrange(() => proxyGenerator.CheckNotGenericTypeDefinition(Arg.AnyType, Arg.AnyString)).OccursOnce();15 }16 }17 {18 }19}20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using Telerik.JustMock;25using Telerik.JustMock.Core.Castle.DynamicProxy;26using Telerik.JustMock.Helpers;27{28 {29 public void TestMethod()30 {31 var mock = Mock.Create<TestClass>(32 Mock.Arrange(() => proxyGenerator.CheckNotGenericTypeDefinition(Arg.AnyType, Arg.AnyString)).OccursOnce();33 {34 }35}36using System;37using System.Collections.Generic;38using System.Linq; System;39usinguSystem.Text;40usingsTelerik.JustMock;41usingiTelerik.JustMock.Core.Castle.DynamicProxy;42usingnTelerik.JustMock.Helpers;43{44 puTelerik.JustMock.Core.Castle.DynamicProxy;45 public void TestMethod()46 {47 var mock = Mock.Create<TestClass>();pace JustMockUnitTest48 { var proxyGenerator = Mock.Create<ProxyGenerator>();49 Mock.Arrange(() => proxyGenerator.CheckNotGenericTypeDefinition(Arg.AnyType, Arg.AnyString)).OccursOnce();50 public class TestClass {51 {52 }53}54using System;55using System.Collections.Generic;56using System.Linq;57using System.Text;58using Telerik.JustMock;59using Telerik.JustMock.Core.Castle.DynamicProxy;60using Telerik.JustMock.Helpers;61namespace JustMockUnitTeststatic void Main(string[] args)62 {63 ProxyGenerator proxyGenerator = new ProxyGenerator();64 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");65 }66 }67 {68 }69}70using System;71using Telerik.JustMock.Core.Castle.DynamicProxy;72{73 {74 static void Main(string[] args)75 {76 ProxyGenerator proxyGenerator = new ProxyGenerator();77 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");78 }79 }80 {81 }82}83using System;84using Telerik.JustMock.Core.Castle.DynamicProxy;85{86 {87 static void Main(string[] args)88 {89 ProxyGenerator proxyGenerator = new ProxyGenerator();90 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");91 }92 }93 {94 }95}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using Telerik.JustMock;6using Telerik.JustMock.Core.Castle.DynamicProxy;7using Telerik.JustMock.Helpers;8{9 {10 public void TestMethod()11 {12 var mock = Mock.Create<TestClass>();13 var proxyGenerator = Mock.Create<ProxyGenerator>();14 Mock.Arrange(() => proxyGenerator.CheckNotGenericTypeDefinition(Arg.AnyType, Arg.AnyString)).OccursOnce();15 }16 }17 {18 }19}20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using Telerik.JustMock;25using Telerik.JustMock.Core.Castle.DynamicProxy;26using Telerik.JustMock.Helpers;27{28 {29 public void TestMethod()30 {31 var mock = Mock.Create<TestClass>();32 var proxyGenerator = Mock.Create<ProxyGenerator>();33 Mock.Arrange(() => proxyGenerator.CheckNotGenericTypeDefinition(Arg.AnyType, Arg.AnyString)).OccursOnce();34 }35 }36 {37 }38}39using System;40using System.Collections.Generic;41using System.Linq;42using System.Text;43using Telerik.JustMock;44using Telerik.JustMock.Core.Castle.DynamicProxy;45using Telerik.JustMock.Helpers;46{47 {48 public void TestMethod()49 {50 var mock = Mock.Create<TestClass>();51 var proxyGenerator = Mock.Create<ProxyGenerator>();52 Mock.Arrange(() => proxyGenerator.CheckNotGenericTypeDefinition(Arg.AnyType, Arg.AnyString)).OccursOnce();53 }54 }55 {56 }57}58using System;59using System.Collections.Generic;60using System.Linq;61using System.Text;62using Telerik.JustMock;63using Telerik.JustMock.Core.Castle.DynamicProxy;64using Telerik.JustMock.Helpers;

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock.Core;3{4 {5 public void Method1()6 {7 var proxyGenerator = new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator();8 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1));9 }10 }11}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock.Core.Castle.DynamicProxy;3{4 {5 static void Main(string[] args)6 {7 ProxyGenerator proxyGenerator = new ProxyGenerator();8 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");9 }10 }11 {12 }13}14using System;15using Telerik.JustMock.Core.Castle.DynamicProxy;16{17 {18 static void Main(string[] args)19 {20 ProxyGenerator proxyGenerator = new ProxyGenerator();21 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");22 }23 }24 {25 }26}27using System;28using Telerik.JustMock.Core.Castle.DynamicProxy;29{30 {31 static void Main(string[] args)32 {33 ProxyGenerator proxyGenerator = new ProxyGenerator();34 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");35 }36 }37 {38 }39}40using System;41using Telerik.JustMock.Core.Castle.DynamicProxy;42{43 {44 static void Main(string[] args)45 {46 ProxyGenerator proxyGenerator = new ProxyGenerator();47 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");48 }49 }50 {51 }52}53using System;54using Telerik.JustMock.Core.Castle.DynamicProxy;55{56 {57 static void Main(string[] args)58 {59 ProxyGenerator proxyGenerator = new ProxyGenerator();60 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1), "test");61 }62 }63 {64 }65}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock.Core;3{4 {5 public void Method1()6 {7 var proxyGenerator = new Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator();8 proxyGenerator.CheckNotGenericTypeDefinition(typeof(Class1));9 }10 }11}

Full Screen

Full Screen

CheckNotGenericTypeDefinition

Using AI Code Generation

copy

Full Screen

1using System;2using Telerik.JustMock;3{4 {5 string Get();6 }7 {8 public IMyInterface MyProperty { get; set; }9 }10 {11 public MyType MyProperty { get; set; }12 }13 {14 public MyOtherType MyProperty { get; set; }15 }16 {17 public MyOtherOtherType MyProperty { get; set; }18 }19 {20 public MyOtherOtherOtherType MyProperty { get; set; }21 }22 {23 public MyOtherOtherOtherOtherType MyProperty { get; set; }24 }25 {26 public MyOtherOtherOtherOtherOtherType MyProperty { get; set; }27 }28 {29 public MyOtherOtherOtherOtherOtherOtherType MyProperty { get; set; }30 }31 {32 public MyOtherOtherOtherOtherOtherOtherOtherType MyProperty { get; set; }33 }34 {35 public MyOtherOtherOtherOtherOtherOtherOtherOtherType MyProperty { get; set; }36 }

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful