Best JustMockLite code snippet using Telerik.JustMock.Core.Castle.DynamicProxy.ProxyGenerator.CreateClassProxy
ProxyGenerator.cs
Source:ProxyGenerator.cs
...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;1436 }1437 protected List<object> BuildArgumentListForClassProxy(ProxyGenerationOptions options, IInterceptor[] interceptors)1438 {1439 var arguments = new List<object>(options.MixinData.Mixins) { interceptors };1440 if (options.Selector != null)1441 {1442 arguments.Add(options.Selector);1443 }1444 return arguments;1445 }1446 /// <summary>1447 /// Creates the proxy type for class proxy with given <paramref name = "classToProxy" /> class, implementing given <paramref1448 /// name = "additionalInterfacesToProxy" /> and using provided <paramref name = "options" />.1449 /// </summary>1450 /// <param name = "classToProxy">The base class for proxy type.</param>1451 /// <param name = "additionalInterfacesToProxy">The interfaces that proxy type should implement.</param>1452 /// <param name = "options">The options for proxy generation process.</param>1453 /// <returns><see cref = "Type" /> of proxy.</returns>1454 protected Type CreateClassProxyType(Type classToProxy, Type[] additionalInterfacesToProxy,1455 ProxyGenerationOptions options)1456 {1457 // create proxy1458 return ProxyBuilder.CreateClassProxyType(classToProxy, additionalInterfacesToProxy, options);1459 }1460 /// <summary>1461 /// Creates the proxy type for interface proxy with target for given <paramref name = "interfaceToProxy" /> interface, implementing given <paramref1462 /// name = "additionalInterfacesToProxy" /> on given <paramref name = "targetType" /> and using provided <paramref1463 /// name = "options" />.1464 /// </summary>1465 /// <param name = "interfaceToProxy">The interface proxy type should implement.</param>1466 /// <param name = "additionalInterfacesToProxy">The additional interfaces proxy type should implement.</param>1467 /// <param name = "targetType">Actual type that the proxy type will encompass.</param>1468 /// <param name = "options">The options for proxy generation process.</param>1469 /// <returns><see cref = "Type" /> of proxy.</returns>1470 protected Type CreateInterfaceProxyTypeWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,1471 Type targetType,1472 ProxyGenerationOptions options)1473 {1474 // create proxy1475 return ProxyBuilder.CreateInterfaceProxyTypeWithTarget(interfaceToProxy, additionalInterfacesToProxy, targetType,1476 options);1477 }1478 /// <summary>1479 /// Creates the proxy type for interface proxy with target interface for given <paramref name = "interfaceToProxy" /> interface, implementing given <paramref1480 /// name = "additionalInterfacesToProxy" /> on given <paramref name = "interfaceToProxy" /> and using provided <paramref1481 /// name = "options" />.1482 /// </summary>1483 /// <param name = "interfaceToProxy">The interface proxy type should implement.</param>1484 /// <param name = "additionalInterfacesToProxy">The additional interfaces proxy type should implement.</param>1485 /// <param name = "options">The options for proxy generation process.</param>1486 /// <returns><see cref = "Type" /> of proxy.</returns>1487 protected Type CreateInterfaceProxyTypeWithTargetInterface(Type interfaceToProxy, Type[] additionalInterfacesToProxy,1488 ProxyGenerationOptions options)1489 {1490 // create proxy1491 return ProxyBuilder.CreateInterfaceProxyTypeWithTargetInterface(interfaceToProxy, additionalInterfacesToProxy,1492 options);1493 }1494 /// <summary>1495 /// Creates the proxy type for interface proxy without target for given <paramref name = "interfaceToProxy" /> interface, implementing given <paramref1496 /// name = "additionalInterfacesToProxy" /> and using provided <paramref name = "options" />.1497 /// </summary>1498 /// <param name = "interfaceToProxy">The interface proxy type should implement.</param>1499 /// <param name = "additionalInterfacesToProxy">The additional interfaces proxy type should implement.</param>1500 /// <param name = "options">The options for proxy generation process.</param>1501 /// <returns><see cref = "Type" /> of proxy.</returns>1502 protected Type CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy,1503 ProxyGenerationOptions options)1504 {1505 // create proxy1506 return ProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(interfaceToProxy, additionalInterfacesToProxy, options);1507 }1508 protected Type CreateClassProxyTypeWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy,1509 ProxyGenerationOptions options)1510 {1511 // create proxy1512 return ProxyBuilder.CreateClassProxyTypeWithTarget(classToProxy, additionalInterfacesToProxy, options);1513 }1514 }1515}...
IProxyGenerator.cs
Source:IProxyGenerator.cs
...586 /// <remarks>587 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.588 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.589 /// </remarks>590 TClass CreateClassProxyWithTarget<TClass>(TClass target, params IInterceptor[] interceptors)591 where TClass : class;592 /// <summary>593 /// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref594 /// name = "interceptors" />.595 /// </summary>596 /// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>597 /// <param name = "target">The target object, calls to which will be intercepted.</param>598 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>599 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>600 /// <returns>601 /// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref602 /// name = "TClass" /> type.603 /// </returns>604 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>605 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <typeparamref name = "TClass" />.</exception>606 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>607 /// <remarks>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 TClass CreateClassProxyWithTarget<TClass>(TClass target, ProxyGenerationOptions options,612 params IInterceptor[] interceptors) where TClass : class;613 /// <summary>614 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref615 /// name = "interceptors" />.616 /// </summary>617 /// <param name = "classToProxy">Type of class which will be proxied.</param>618 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>619 /// <param name = "target">The target object, calls to which will be intercepted.</param>620 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>621 /// <returns>622 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref623 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.624 /// </returns>625 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>626 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref627 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>628 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>629 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>630 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>631 /// <remarks>632 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.633 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.634 /// </remarks>635 object CreateClassProxyWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy, object target,636 params IInterceptor[] interceptors);637 /// <summary>638 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref639 /// name = "interceptors" />.640 /// </summary>641 /// <param name = "classToProxy">Type of class which will be proxied.</param>642 /// <param name = "target">The target object, calls to which will be intercepted.</param>643 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>644 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>645 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>646 /// <returns>647 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref648 /// name = "classToProxy" /> type.649 /// </returns>650 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>651 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>652 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>653 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref654 /// name = "constructorArguments" />.</exception>655 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>656 /// <remarks>657 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.658 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.659 /// </remarks>660 object CreateClassProxyWithTarget(Type classToProxy, object target, ProxyGenerationOptions options,661 object[] constructorArguments, params IInterceptor[] interceptors);662 /// <summary>663 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref664 /// name = "interceptors" />.665 /// </summary>666 /// <param name = "classToProxy">Type of class which will be proxied.</param>667 /// <param name = "target">The target object, calls to which will be intercepted.</param>668 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>669 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>670 /// <returns>671 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref672 /// name = "classToProxy" /> type.673 /// </returns>674 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>675 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>676 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>677 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref678 /// name = "constructorArguments" />.</exception>679 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>680 /// <remarks>681 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.682 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.683 /// </remarks>684 object CreateClassProxyWithTarget(Type classToProxy, object target, object[] constructorArguments,685 params IInterceptor[] interceptors);686 /// <summary>687 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref688 /// name = "interceptors" />.689 /// </summary>690 /// <param name = "classToProxy">Type of class which will be proxied.</param>691 /// <param name = "target">The target object, calls to which will be intercepted.</param>692 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>693 /// <returns>694 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref695 /// name = "classToProxy" /> type.696 /// </returns>697 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>698 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>699 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>700 /// <exception cref = "ArgumentException">Thrown when no parameterless constructor exists on type <paramref701 /// name = "classToProxy" />.</exception>702 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>703 /// <remarks>704 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.705 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.706 /// </remarks>707 object CreateClassProxyWithTarget(Type classToProxy, object target, params IInterceptor[] interceptors);708 /// <summary>709 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref710 /// name = "interceptors" />.711 /// </summary>712 /// <param name = "classToProxy">Type of class which will be proxied.</param>713 /// <param name = "target">The target object, calls to which will be intercepted.</param>714 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>715 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>716 /// <returns>717 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref718 /// name = "classToProxy" /> type.719 /// </returns>720 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>721 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>722 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>723 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>724 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>725 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>726 /// <remarks>727 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.728 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.729 /// </remarks>730 object CreateClassProxyWithTarget(Type classToProxy, object target, ProxyGenerationOptions options,731 params IInterceptor[] interceptors);732 /// <summary>733 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref734 /// name = "interceptors" />.735 /// </summary>736 /// <param name = "classToProxy">Type of class which will be proxied.</param>737 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>738 /// <param name = "target">The target object, calls to which will be intercepted.</param>739 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>740 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>741 /// <returns>742 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref743 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.744 /// </returns>745 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>746 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>747 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref748 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>749 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>750 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>751 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>752 /// <remarks>753 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.754 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.755 /// </remarks>756 object CreateClassProxyWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy, object target,757 ProxyGenerationOptions options, params IInterceptor[] interceptors);758 /// <summary>759 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref760 /// name = "interceptors" />.761 /// </summary>762 /// <param name = "classToProxy">Type of class which will be proxied.</param>763 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>764 /// <param name = "target">The target object, calls to which will be intercepted.</param>765 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>766 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>767 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>768 /// <returns>769 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref770 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.771 /// </returns>772 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>773 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>774 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref775 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>776 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>777 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref778 /// name = "constructorArguments" />.</exception>779 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>780 /// <remarks>781 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.782 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.783 /// </remarks>784 object CreateClassProxyWithTarget(Type classToProxy, Type[] additionalInterfacesToProxy, object target,785 ProxyGenerationOptions options, object[] constructorArguments,786 params IInterceptor[] interceptors);787 /// <summary>788 /// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref789 /// name = "interceptors" />.790 /// </summary>791 /// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>792 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>793 /// <returns>794 /// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref795 /// name = "TClass" /> type.796 /// </returns>797 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>798 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <typeparamref name = "TClass" />.</exception>799 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>800 /// <remarks>801 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.802 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.803 /// </remarks>804 TClass CreateClassProxy<TClass>(params IInterceptor[] interceptors) where TClass : class;805 /// <summary>806 /// Creates proxy object intercepting calls to virtual members of type <typeparamref name = "TClass" /> on newly created instance of that type with given <paramref807 /// name = "interceptors" />.808 /// </summary>809 /// <typeparam name = "TClass">Type of class which will be proxied.</typeparam>810 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>811 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>812 /// <returns>813 /// New object of type <typeparamref name = "TClass" /> proxying calls to virtual members of <typeparamref814 /// name = "TClass" /> type.815 /// </returns>816 /// <exception cref = "ArgumentException">Thrown when given <typeparamref name = "TClass" /> is not a class type.</exception>817 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <typeparamref name = "TClass" />.</exception>818 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <typeparamref name = "TClass" /> throws an exception.</exception>819 /// <remarks>820 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.821 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.822 /// </remarks>823 TClass CreateClassProxy<TClass>(ProxyGenerationOptions options, params IInterceptor[] interceptors)824 where TClass : class;825 /// <summary>826 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref827 /// name = "interceptors" />.828 /// </summary>829 /// <param name = "classToProxy">Type of class which will be proxied.</param>830 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>831 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>832 /// <returns>833 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref834 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.835 /// </returns>836 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>837 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref838 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>839 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>840 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>841 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>842 /// <remarks>843 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.844 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.845 /// </remarks>846 object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy,847 params IInterceptor[] interceptors);848 /// <summary>849 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref850 /// name = "interceptors" />.851 /// </summary>852 /// <param name = "classToProxy">Type of class which will be proxied.</param>853 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>854 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>855 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>856 /// <returns>857 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref858 /// name = "classToProxy" /> type.859 /// </returns>860 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>861 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>862 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>863 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref864 /// name = "constructorArguments" />.</exception>865 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>866 /// <remarks>867 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.868 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.869 /// </remarks>870 object CreateClassProxy(Type classToProxy, ProxyGenerationOptions options, object[] constructorArguments,871 params IInterceptor[] interceptors);872 /// <summary>873 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref874 /// name = "interceptors" />.875 /// </summary>876 /// <param name = "classToProxy">Type of class which will be proxied.</param>877 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>878 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>879 /// <returns>880 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref881 /// name = "classToProxy" /> type.882 /// </returns>883 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>884 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>885 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>886 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref887 /// name = "constructorArguments" />.</exception>888 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>889 /// <remarks>890 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.891 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.892 /// </remarks>893 object CreateClassProxy(Type classToProxy, object[] constructorArguments, params IInterceptor[] interceptors);894 /// <summary>895 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref896 /// name = "interceptors" />.897 /// </summary>898 /// <param name = "classToProxy">Type of class which will be proxied.</param>899 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>900 /// <returns>901 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref902 /// name = "classToProxy" /> type.903 /// </returns>904 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>905 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>906 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>907 /// <exception cref = "ArgumentException">Thrown when no parameterless constructor exists on type <paramref908 /// name = "classToProxy" />.</exception>909 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>910 /// <remarks>911 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.912 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.913 /// </remarks>914 object CreateClassProxy(Type classToProxy, params IInterceptor[] interceptors);915 /// <summary>916 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref917 /// name = "interceptors" />.918 /// </summary>919 /// <param name = "classToProxy">Type of class which will be proxied.</param>920 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>921 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>922 /// <returns>923 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref924 /// name = "classToProxy" /> type.925 /// </returns>926 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>927 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>928 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is a generic type definition.</exception>929 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>930 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>931 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>932 /// <remarks>933 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.934 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.935 /// </remarks>936 object CreateClassProxy(Type classToProxy, ProxyGenerationOptions options, params IInterceptor[] interceptors);937 /// <summary>938 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref939 /// name = "interceptors" />.940 /// </summary>941 /// <param name = "classToProxy">Type of class which will be proxied.</param>942 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>943 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>944 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>945 /// <returns>946 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref947 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.948 /// </returns>949 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>950 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>951 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref952 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>953 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>954 /// <exception cref = "ArgumentException">Thrown when no default constructor exists on type <paramref name = "classToProxy" />.</exception>955 /// <exception cref = "TargetInvocationException">Thrown when default constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>956 /// <remarks>957 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.958 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.959 /// </remarks>960 object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options,961 params IInterceptor[] interceptors);962 /// <summary>963 /// Creates proxy object intercepting calls to virtual members of type <paramref name = "classToProxy" /> on newly created instance of that type with given <paramref964 /// name = "interceptors" />.965 /// </summary>966 /// <param name = "classToProxy">Type of class which will be proxied.</param>967 /// <param name = "additionalInterfacesToProxy">Additional interface types. Calls to their members will be proxied as well.</param>968 /// <param name = "options">The proxy generation options used to influence generated proxy type and object.</param>969 /// <param name = "constructorArguments">Arguments of constructor of type <paramref name = "classToProxy" /> which should be used to create a new instance of that type.</param>970 /// <param name = "interceptors">The interceptors called during the invocation of proxied methods.</param>971 /// <returns>972 /// New object of type <paramref name = "classToProxy" /> proxying calls to virtual members of <paramref973 /// name = "classToProxy" /> and <paramref name = "additionalInterfacesToProxy" /> types.974 /// </returns>975 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "classToProxy" /> object is a null reference (Nothing in Visual Basic).</exception>976 /// <exception cref = "ArgumentNullException">Thrown when given <paramref name = "options" /> object is a null reference (Nothing in Visual Basic).</exception>977 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> or any of <paramref978 /// name = "additionalInterfacesToProxy" /> is a generic type definition.</exception>979 /// <exception cref = "ArgumentException">Thrown when given <paramref name = "classToProxy" /> is not a class type.</exception>980 /// <exception cref = "ArgumentException">Thrown when no constructor exists on type <paramref name = "classToProxy" /> with parameters matching <paramref981 /// name = "constructorArguments" />.</exception>982 /// <exception cref = "TargetInvocationException">Thrown when constructor of type <paramref name = "classToProxy" /> throws an exception.</exception>983 /// <remarks>984 /// This method uses <see cref = "IProxyBuilder" /> implementation to generate a proxy type.985 /// As such caller should expect any type of exception that given <see cref = "IProxyBuilder" /> implementation may throw.986 /// </remarks>987 object CreateClassProxy(Type classToProxy, Type[] additionalInterfacesToProxy,988 ProxyGenerationOptions options,989 object[] constructorArguments, params IInterceptor[] interceptors);990 }991}...
DynamicProxyMockFactory.cs
Source:DynamicProxyMockFactory.cs
...107 }108 }109 }110#endif111 instance = generator.CreateClassProxy(type, settings.AdditionalMockedInterfaces, options, settings.Args, interceptor);112 }113 catch (TypeLoadException ex)114 {115 proxyFailure = ex;116 }117 catch (GeneratorException ex)118 {119 proxyFailure = ex;120 }121 catch (InvalidProxyConstructorArgumentsException ex)122 {123 proxyFailure = ex;124 if (!settings.MockConstructorCall)125 throw new MockException(ex.Message);126 }127 }128 if (proxyFailure != null)129 {130 throw new ProxyFailureException(proxyFailure);131 }132 return instance;133 }134 public Type CreateDelegateBackend(Type delegateType)135 {136 var moduleScope = generator.ProxyBuilder.ModuleScope;137 var moduleBuilder = moduleScope.ObtainDynamicModuleWithStrongName();138 var targetIntfName =139 "Castle.Proxies.Delegates." +140 delegateType.ToString()141 .Replace('.', '_')142 .Replace(',', '`')143 .Replace("+", "__")144 .Replace("[", "``")145 .Replace("]", "``");146 var typeName = moduleScope.NamingScope.GetUniqueName(targetIntfName);147 var typeBuilder = moduleBuilder.DefineType(typeName, TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Interface);148 var delegateInvoke = delegateType.GetMethod("Invoke");149 typeBuilder.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Abstract | MethodAttributes.Virtual,150 delegateInvoke.ReturnType, delegateInvoke.GetParameters().Select(p => p.ParameterType).ToArray());151 return typeBuilder.CreateType();152 }153 public IMockMixin CreateExternalMockMixin(IMockMixin mockMixin, IEnumerable<object> mixins)154 {155 var options = new ProxyGenerationOptions();156 options.AddMixinInstance(mockMixin);157 foreach (var mixin in mixins)158 options.AddMixinInstance(mixin);159 var compoundMockMixin = (IMockMixin)generator.CreateClassProxy(typeof(MocksRepository.ExternalMockMixin), options);160 return compoundMockMixin;161 }162 public ProxyTypeInfo CreateClassProxyType(Type classToProxy, MocksRepository repository, MockCreationSettings settings, MockMixin mockMixinImpl)163 {164 var pgo = CreateProxyGenerationOptions(classToProxy, settings, mockMixinImpl);165 var typeInfo = new ProxyTypeInfo166 {167 ProxyType = generator.ProxyBuilder.CreateClassProxyType(classToProxy, Type.EmptyTypes, pgo)168 };169 typeInfo.Mixins.Add(typeof(IInterceptor), repository.Interceptor);170 foreach (var mixin in pgo.MixinData.MixinInterfaces)171 {172 typeInfo.Mixins.Add(mixin, pgo.MixinData.GetMixinInstance(mixin));173 }174 return typeInfo;175 }176 private ProxyGenerationOptions CreateProxyGenerationOptions(Type type, MockCreationSettings settings, MockMixin mockMixinImpl = null)177 {178 var options = new ProxyGenerationOptions();179 if (mockMixinImpl != null)180 options.AddMixinInstance(mockMixinImpl);181 foreach (var mixin in settings.Mixins)...
CreateClassProxy
Using AI Code Generation
1using Telerik.JustMock.Core;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 public int Add(int a, int b)10 {11 return a + b;12 }13 }14 {15 public int Add(int a, int b)16 {17 return a + b;18 }19 }20 {21 static void Main(string[] args)22 {23 var proxy = Mock.CreateClassProxy<Class1>();24 proxy.Add(1, 2);25 }26 }27}28using Telerik.JustMock.Core;29using System;30using System.Collections.Generic;31using System.Linq;32using System.Text;33using System.Threading.Tasks;34{35 {36 public int Add(int a, int b)37 {38 return a + b;39 }40 }41 {42 public int Add(int a, int b)43 {44 return a + b;45 }46 }47 {48 static void Main(string[] args)49 {50 var proxy = Mock.CreateClassProxy<Class1>();51 proxy.Add(1, 2);52 }53 }54}55using Telerik.JustMock.Core;56using System;57using System.Collections.Generic;58using System.Linq;59using System.Text;60using System.Threading.Tasks;61{62 {63 public int Add(int a, int b)64 {65 return a + b;66 }67 }68 {69 public int Add(int a, int b)70 {71 return a + b;72 }73 }74 {75 static void Main(string[] args)76 {77 var proxy = Mock.CreateClassProxy<Class1>();78 proxy.Add(1, 2);79 }80 }81}
CreateClassProxy
Using AI Code Generation
1using Telerik.JustMock.Core.Castle.DynamicProxy;2{3 public static void Main()4 {5 var generator = new ProxyGenerator();6 var proxy = generator.CreateClassProxy(typeof(MyClass), new MyInterceptor());7 var result = proxy.DoSomething();8 }9}10using Telerik.JustMock.Core.Castle.DynamicProxy;11{12 public static void Main()13 {14 var generator = new ProxyGenerator();15 var proxy = generator.CreateClassProxy<MyClass>(new MyInterceptor());16 var result = proxy.DoSomething();17 }18}19using Telerik.JustMock.Core.Castle.DynamicProxy;20{21 public static void Main()22 {23 var generator = new ProxyGenerator();24 var proxy = generator.CreateClassProxy<MyClass>(new MyInterceptor());25 var result = proxy.DoSomething();26 }27}28using Telerik.JustMock.Core.Castle.DynamicProxy;29{30 public static void Main()31 {32 var generator = new ProxyGenerator();33 var proxy = generator.CreateClassProxy<MyClass>(new MyInterceptor());34 var result = proxy.DoSomething();35 }36}37using Telerik.JustMock.Core.Castle.DynamicProxy;38{39 public static void Main()40 {41 var generator = new ProxyGenerator();42 var proxy = generator.CreateClassProxy<MyClass>(new MyInterceptor());43 var result = proxy.DoSomething();44 }45}46using Telerik.JustMock.Core.Castle.DynamicProxy;47{48 public static void Main()49 {50 var generator = new ProxyGenerator();51 var proxy = generator.CreateClassProxy<MyClass>(new MyInterceptor());52 var result = proxy.DoSomething();53 }54}
CreateClassProxy
Using AI Code Generation
1using System;2using Telerik.JustMock.Core.Castle.DynamicProxy;3{4 {5 public Class1()6 {7 ProxyGenerator proxy = new ProxyGenerator();8 var result = proxy.CreateClassProxy(typeof(Class2), new object[] { });9 }10 }11}12using System;13using Telerik.JustMock.Core.Castle.DynamicProxy;14{15 {16 public Class2()17 {18 ProxyGenerator proxy = new ProxyGenerator();19 var result = proxy.CreateClassProxy(typeof(Class3), new object[] { });20 }21 }22}23using System;24using Telerik.JustMock.Core.Castle.DynamicProxy;25{26 {27 public Class3()28 {29 ProxyGenerator proxy = new ProxyGenerator();30 var result = proxy.CreateClassProxy(typeof(Class4), new object[] { });31 }32 }33}34using System;35using Telerik.JustMock.Core.Castle.DynamicProxy;36{37 {38 public Class4()39 {40 ProxyGenerator proxy = new ProxyGenerator();41 var result = proxy.CreateClassProxy(typeof(Class5), new object[] { });42 }43 }44}45using System;46using Telerik.JustMock.Core.Castle.DynamicProxy;47{48 {49 public Class5()50 {51 ProxyGenerator proxy = new ProxyGenerator();52 var result = proxy.CreateClassProxy(typeof(Class6), new object[] { });53 }54 }55}56using System;57using Telerik.JustMock.Core.Castle.DynamicProxy;58{
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!