Skip to content

Commit 1062546

Browse files
committed
Add CreateClassProxy overloads using typeparams
1 parent c6d7a16 commit 1062546

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

src/Castle.Core/DynamicProxy/ProxyGenerator.cs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,57 @@ 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+
/// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>
1206+
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
1207+
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
1208+
/// <returns>
1209+
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
1210+
/// </returns>
1211+
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
1212+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
1213+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
1214+
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
1215+
/// name = "constructorArguments" />.</exception>
1216+
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
1217+
/// <remarks>
1218+
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
1219+
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
1220+
/// </remarks>
1221+
public TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, object[] constructorArguments, params IInterceptor[] interceptors)
1222+
where TClass : class
1223+
{
1224+
return (TClass)CreateClassProxy(typeof(TClass), options, constructorArguments, interceptors);
1225+
}
1226+
1227+
/// <summary>
1228+
/// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref
1229+
/// name = "interceptors" />.
1230+
/// </summary>
1231+
/// <param name = "constructorArguments">Arguments of constructor of type <typeparamref name = "TClass" /> which should be used to create a new instance of that type.</param>
1232+
/// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>
1233+
/// <returns>
1234+
/// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref name = "TClass" /> type.
1235+
/// </returns>
1236+
/// <exception cref = "ArgumentNullException">Thrown when given <typeparamref name = "TClass" /> object is a null reference (Nothing in Visual Basic).</exception>
1237+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is a generic type definition.</exception>
1238+
/// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>
1239+
/// <exception cref = "ArgumentException">Thrown when no constructor exists on type <typeparamref name = "TClass" /> with parameters matching <paramref
1240+
/// name = "constructorArguments" />.</exception>
1241+
/// <exception cref = "TargetInvocationException">Thrown when constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>
1242+
/// <remarks>
1243+
/// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.
1244+
/// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.
1245+
/// </remarks>
1246+
public TClass CreateClassProxy<TClass>(object[] constructorArguments, params IInterceptor[] interceptors)
1247+
where TClass : class
1248+
{
1249+
return (TClass)CreateClassProxy(typeof(TClass), constructorArguments, interceptors);
1250+
}
1251+
12011252
/// <summary>
12021253
/// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref
12031254
/// name = "interceptors" />.
@@ -1565,4 +1616,4 @@ protected Type CreateClassProxyTypeWithTarget(Type classToProxy, Type[] addition
15651616
return ProxyBuilder.CreateClassProxyTypeWithTarget(classToProxy, additionalInterfacesToProxy, options);
15661617
}
15671618
}
1568-
}
1619+
}

0 commit comments

Comments
 (0)