Skip to content

Commit d7e398f

Browse files
authored
Merge pull request castleproject#636 from backstromjoel/master
Add CreateClassProxy overloads using typeparams
2 parents e60c9e2 + eaf6aa7 commit d7e398f

File tree

6 files changed

+132
-2
lines changed

6 files changed

+132
-2
lines changed

ref/Castle.Core-net462.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,6 +2568,10 @@ TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[] interc
25682568
where TClass : class;
25692569
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
25702570
where TClass : class;
2571+
TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2572+
where TClass : class;
2573+
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2574+
where TClass : class;
25712575
object CreateClassProxyWithTarget(System.Type classToProxy, object target, params Castle.DynamicProxy.IInterceptor[] interceptors);
25722576
object CreateClassProxyWithTarget(System.Type classToProxy, object target, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors);
25732577
object CreateClassProxyWithTarget(System.Type classToProxy, object target, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors);
@@ -2690,6 +2694,10 @@ public TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[]
26902694
where TClass : class { }
26912695
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
26922696
where TClass : class { }
2697+
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2698+
where TClass : class { }
2699+
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2700+
where TClass : class { }
26932701
protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List<object> proxyArguments, System.Type classToProxy, object[] constructorArguments) { }
26942702
protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
26952703
protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }

ref/Castle.Core-net6.0.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,10 @@ TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[] interc
25362536
where TClass : class;
25372537
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
25382538
where TClass : class;
2539+
TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2540+
where TClass : class;
2541+
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2542+
where TClass : class;
25392543
object CreateClassProxyWithTarget(System.Type classToProxy, object target, params Castle.DynamicProxy.IInterceptor[] interceptors);
25402544
object CreateClassProxyWithTarget(System.Type classToProxy, object target, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors);
25412545
object CreateClassProxyWithTarget(System.Type classToProxy, object target, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors);
@@ -2646,6 +2650,10 @@ public TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[]
26462650
where TClass : class { }
26472651
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
26482652
where TClass : class { }
2653+
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2654+
where TClass : class { }
2655+
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2656+
where TClass : class { }
26492657
protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List<object> proxyArguments, System.Type classToProxy, object[] constructorArguments) { }
26502658
protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
26512659
protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }

ref/Castle.Core-netstandard2.0.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,6 +2534,10 @@ TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[] interc
25342534
where TClass : class;
25352535
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
25362536
where TClass : class;
2537+
TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2538+
where TClass : class;
2539+
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2540+
where TClass : class;
25372541
object CreateClassProxyWithTarget(System.Type classToProxy, object target, params Castle.DynamicProxy.IInterceptor[] interceptors);
25382542
object CreateClassProxyWithTarget(System.Type classToProxy, object target, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors);
25392543
object CreateClassProxyWithTarget(System.Type classToProxy, object target, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors);
@@ -2644,6 +2648,10 @@ public TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[]
26442648
where TClass : class { }
26452649
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
26462650
where TClass : class { }
2651+
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2652+
where TClass : class { }
2653+
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2654+
where TClass : class { }
26472655
protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List<object> proxyArguments, System.Type classToProxy, object[] constructorArguments) { }
26482656
protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
26492657
protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }

ref/Castle.Core-netstandard2.1.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,6 +2534,10 @@ TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[] interc
25342534
where TClass : class;
25352535
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
25362536
where TClass : class;
2537+
TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2538+
where TClass : class;
2539+
TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2540+
where TClass : class;
25372541
object CreateClassProxyWithTarget(System.Type classToProxy, object target, params Castle.DynamicProxy.IInterceptor[] interceptors);
25382542
object CreateClassProxyWithTarget(System.Type classToProxy, object target, Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors);
25392543
object CreateClassProxyWithTarget(System.Type classToProxy, object target, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors);
@@ -2644,6 +2648,10 @@ public TClass CreateClassProxy<TClass>(params Castle.DynamicProxy.IInterceptor[]
26442648
where TClass : class { }
26452649
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, params Castle.DynamicProxy.IInterceptor[] interceptors)
26462650
where TClass : class { }
2651+
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2652+
where TClass : class { }
2653+
public TClass CreateClassProxy<TClass>(Castle.DynamicProxy.ProxyGenerationOptions options, object[] constructorArguments, params Castle.DynamicProxy.IInterceptor[] interceptors)
2654+
where TClass : class { }
26472655
protected object CreateClassProxyInstance(System.Type proxyType, System.Collections.Generic.List<object> proxyArguments, System.Type classToProxy, object[] constructorArguments) { }
26482656
protected System.Type CreateClassProxyType(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }
26492657
protected System.Type CreateClassProxyTypeWithTarget(System.Type classToProxy, System.Type[] additionalInterfacesToProxy, Castle.DynamicProxy.ProxyGenerationOptions options) { }

src/Castle.Core/DynamicProxy/IProxyGenerator.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,5 +1029,50 @@ object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, P
10291029
object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy,
10301030
ProxyGenerationOptions options,
10311031
object[] constructorArguments, params IInterceptor[] interceptors);
1032+
1033+
/// <summary>
1034+
/// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref
1035+
/// name = "interceptors" />.
1036+
/// </summary>
1037+
/// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>
1038+
/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>
1039+
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
1040+
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
1041+
/// <returns>
1042+
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
1043+
/// </returns>
1044+
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
1045+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
1046+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
1047+
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
1048+
/// name = "constructorArguments" />.</exception>
1049+
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
1050+
/// <remarks>
1051+
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
1052+
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
1053+
/// </remarks>
1054+
public TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, object[] constructorArguments, params IInterceptor[] interceptors) where TClass : class;
1055+
1056+
/// <summary>
1057+
/// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref
1058+
/// name = "interceptors" />.
1059+
/// </summary>
1060+
/// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>
1061+
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
1062+
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
1063+
/// <returns>
1064+
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
1065+
/// </returns>
1066+
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
1067+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
1068+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
1069+
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
1070+
/// name = "constructorArguments" />.</exception>
1071+
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
1072+
/// <remarks>
1073+
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
1074+
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
1075+
/// </remarks>
1076+
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params IInterceptor[] interceptors) where TClass : class;
10321077
}
1033-
}
1078+
}

src/Castle.Core/DynamicProxy/ProxyGenerator.cs

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,59 @@ public TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, params II
11981198
return (TClass)CreateClassProxy(typeof(TClass), options, interceptors);
11991199
}
12001200

1201+
/// <summary>
1202+
/// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref
1203+
/// name = "interceptors" />.
1204+
/// </summary>
1205+
/// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>
1206+
/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>
1207+
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
1208+
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
1209+
/// <returns>
1210+
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
1211+
/// </returns>
1212+
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
1213+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
1214+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
1215+
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
1216+
/// name = "constructorArguments" />.</exception>
1217+
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
1218+
/// <remarks>
1219+
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
1220+
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
1221+
/// </remarks>
1222+
public TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, object[] constructorArguments, params IInterceptor[] interceptors)
1223+
where TClass : class
1224+
{
1225+
return (TClass)CreateClassProxy(typeof(TClass), options, constructorArguments, interceptors);
1226+
}
1227+
1228+
/// <summary>
1229+
/// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref
1230+
/// name = "interceptors" />.
1231+
/// </summary>
1232+
/// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>
1233+
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
1234+
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
1235+
/// <returns>
1236+
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
1237+
/// </returns>
1238+
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
1239+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
1240+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
1241+
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
1242+
/// name = "constructorArguments" />.</exception>
1243+
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
1244+
/// <remarks>
1245+
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
1246+
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
1247+
/// </remarks>
1248+
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params IInterceptor[] interceptors)
1249+
where TClass : class
1250+
{
1251+
return (TClass)CreateClassProxy(typeof(TClass), constructorArguments, interceptors);
1252+
}
1253+
12011254
/// <summary>
12021255
/// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref
12031256
/// name = "interceptors" />.
@@ -1565,4 +1618,4 @@ protected Type CreateClassProxyTypeWithTarget(Type classToProxy, Type[] addition
15651618
return ProxyBuilder.CreateClassProxyTypeWithTarget(classToProxy, additionalInterfacesToProxy, options);
15661619
}
15671620
}
1568-
}
1621+
}

0 commit comments

Comments
 (0)