Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CreateClassProxy overloads using typeparams #636

Merged
merged 5 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ref/Castle.Core-net462.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2568,6 +2568,10 @@ TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[] interc
where TClass : class;
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
object CreateClassProxyWithTarget(System.Type classToProxy, object target, params Castle.DynamicProxy.IInterceptor[] interceptors);
object CreateClassProxyWithTarget(System.Type classToProxy, object target, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors);
object CreateClassProxyWithTarget(System.Type classToProxy, object target, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors);
Expand Down Expand Up @@ -2690,6 +2694,10 @@ public TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[]
where TClass : class { }
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List<object> proxyArguments, System.Type classToProxy, object[] constructorArguments) { }
protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
Expand Down
8 changes: 8 additions & 0 deletions ref/Castle.Core-net6.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2536,6 +2536,10 @@ TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[] interc
where TClass : class;
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
object CreateClassProxyWithTarget(System.Type classToProxy, object target, params Castle.DynamicProxy.IInterceptor[] interceptors);
object CreateClassProxyWithTarget(System.Type classToProxy, object target, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors);
object CreateClassProxyWithTarget(System.Type classToProxy, object target, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors);
Expand Down Expand Up @@ -2646,6 +2650,10 @@ public TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[]
where TClass : class { }
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List<object> proxyArguments, System.Type classToProxy, object[] constructorArguments) { }
protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
Expand Down
8 changes: 8 additions & 0 deletions ref/Castle.Core-netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,10 @@ TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[] interc
where TClass : class;
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
object CreateClassProxyWithTarget(System.Type classToProxy, object target, params Castle.DynamicProxy.IInterceptor[] interceptors);
object CreateClassProxyWithTarget(System.Type classToProxy, object target, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors);
object CreateClassProxyWithTarget(System.Type classToProxy, object target, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors);
Expand Down Expand Up @@ -2644,6 +2648,10 @@ public TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[]
where TClass : class { }
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List<object> proxyArguments, System.Type classToProxy, object[] constructorArguments) { }
protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
Expand Down
8 changes: 8 additions & 0 deletions ref/Castle.Core-netstandard2.1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2534,6 +2534,10 @@ TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[] interc
where TClass : class;
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class;
object CreateClassProxyWithTarget(System.Type classToProxy, object target, params Castle.DynamicProxy.IInterceptor[] interceptors);
object CreateClassProxyWithTarget(System.Type classToProxy, object target, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors);
object CreateClassProxyWithTarget(System.Type classToProxy, object target, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors);
Expand Down Expand Up @@ -2644,6 +2648,10 @@ public TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[]
where TClass : class { }
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
where TClass : class { }
protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List<object> proxyArguments, System.Type classToProxy, object[] constructorArguments) { }
protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
Expand Down
47 changes: 46 additions & 1 deletion src/Castle.Core/DynamicProxy/IProxyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,5 +1029,50 @@ object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, P
object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy,
ProxyGenerationOptions options,
object[] constructorArguments, params IInterceptor[] interceptors);

/// <summary>
/// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref
/// name = "interceptors" />.
/// </summary>
/// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>
/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
/// <returns>
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
/// </returns>
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
/// name = "constructorArguments" />.</exception>
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
/// <remarks>
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
/// </remarks>
public TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, object[] constructorArguments, params IInterceptor[] interceptors) where TClass : class;

/// <summary>
/// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref
/// name = "interceptors" />.
/// </summary>
/// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
/// <returns>
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
/// </returns>
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
/// name = "constructorArguments" />.</exception>
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
/// <remarks>
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
/// </remarks>
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params IInterceptor[] interceptors) where TClass : class;
}
}
}
55 changes: 54 additions & 1 deletion src/Castle.Core/DynamicProxy/ProxyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,59 @@ public TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, params II
return (TClass)CreateClassProxy(typeof(TClass), options, interceptors);
}

/// <summary>
/// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref
/// name = "interceptors" />.
/// </summary>
/// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>
/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
/// <returns>
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
/// </returns>
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
/// name = "constructorArguments" />.</exception>
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
/// <remarks>
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
/// </remarks>
public TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, object[] constructorArguments, params IInterceptor[] interceptors)
backstromjoel marked this conversation as resolved.
Show resolved Hide resolved
backstromjoel marked this conversation as resolved.
Show resolved Hide resolved
where TClass : class
{
return (TClass)CreateClassProxy(typeof(TClass), options, constructorArguments, interceptors);
}

/// <summary>
/// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref
/// name = "interceptors" />.
/// </summary>
/// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
/// <returns>
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
/// </returns>
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
/// name = "constructorArguments" />.</exception>
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
/// <remarks>
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
/// </remarks>
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params IInterceptor[] interceptors)
where TClass : class
{
return (TClass)CreateClassProxy(typeof(TClass), constructorArguments, interceptors);
}

/// <summary>
/// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref
/// name = "interceptors" />.
Expand Down Expand Up @@ -1565,4 +1618,4 @@ protected Type CreateClassProxyTypeWithTarget(Type classToProxy, Type[] addition
return ProxyBuilder.CreateClassProxyTypeWithTarget(classToProxy, additionalInterfacesToProxy, options);
}
}
}
}