| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -255,6 +255,9 @@ public void MethodWithParamsTest() | |||
| 255 | 255 | [Test] | |
| 256 | 256 | public void TestGenericMethodBinding() | |
| 257 | 257 | { | |
| 258 | + // Test matching generic | ||
| 259 | + // i.e. function signature is <T>(Generic<T> var1) | ||
| 260 | + | ||
| 258 | 261 | // Run in C# | |
| 259 | 262 | var class1 = new TestGenericClass1(); | |
| 260 | 263 | var class2 = new TestGenericClass2(); | |
@@ -285,6 +288,9 @@ raise AssertionError('Values were not updated') | |||
| 285 | 288 | [Test] | |
| 286 | 289 | public void TestMultipleGenericMethodBinding() | |
| 287 | 290 | { | |
| 291 | + // Test matching multiple generics | ||
| 292 | + // i.e. function signature is <T,K>(Generic<T,K> var1) | ||
| 293 | + | ||
| 288 | 294 | // Run in C# | |
| 289 | 295 | var class1 = new TestMultipleGenericClass1(); | |
| 290 | 296 | var class2 = new TestMultipleGenericClass2(); | |
@@ -315,6 +321,9 @@ raise AssertionError('Values were not updated') | |||
| 315 | 321 | [Test] | |
| 316 | 322 | public void TestMultipleGenericParamMethodBinding() | |
| 317 | 323 | { | |
| 324 | + // Test multiple param generics matching | ||
| 325 | + // i.e. function signature is <T,K>(Generic1<T> var1, Generic<T,K> var2) | ||
| 326 | + | ||
| 318 | 327 | // Run in C# | |
| 319 | 328 | var class1a = new TestGenericClass1(); | |
| 320 | 329 | var class1b = new TestMultipleGenericClass1(); | |
@@ -358,8 +367,11 @@ raise AssertionError('Values were not updated') | |||
| 358 | 367 | } | |
| 359 | 368 | ||
| 360 | 369 | [Test] | |
| 361 | - public void TestMultipleGenericParamMethodBinding2() | ||
| 370 | + public void TestMultipleGenericParamMethodBinding_MixedOrder() | ||
| 362 | 371 | { | |
| 372 | + // Test matching multiple param generics with mixed order | ||
| 373 | + // i.e. function signature is <T,K>(Generic1<K> var1, Generic<T,K> var2) | ||
| 374 | + | ||
| 363 | 375 | // Run in C# | |
| 364 | 376 | var class1a = new TestGenericClass2(); | |
| 365 | 377 | var class1b = new TestMultipleGenericClass1(); | |
@@ -401,6 +413,33 @@ raise AssertionError('Values were not updated') | |||
| 401 | 413 | ")); | |
| 402 | 414 | } | |
| 403 | 415 | ||
| 416 | + [Test] | ||
| 417 | + public void TestPyClassGenericBinding(){ | ||
| 418 | + // Overriding our generics in Python we should still match with the generic method | ||
| 419 | + Assert.DoesNotThrow(() => PythonEngine.ModuleFromString("test", @" | ||
| 420 | + from clr import AddReference | ||
| 421 | + AddReference(""System"") | ||
| 422 | + AddReference(""Python.EmbeddingTest"") | ||
| 423 | + from Python.EmbeddingTest import * | ||
| 424 | + | ||
| 425 | + class PyGenericClass(TestMethodBinder.TestGenericClass1): | ||
| 426 | + pass | ||
| 427 | + | ||
| 428 | + class PyMultipleGenericClass(TestMethodBinder.TestMultipleGenericClass1): | ||
| 429 | + pass | ||
| 430 | + | ||
| 431 | + singleGenericClass = PyGenericClass() | ||
| 432 | + multiGenericClass = PyMultipleGenericClass() | ||
| 433 | + | ||
| 434 | + TestMethodBinder.TestGenericMethod(singleGenericClass) | ||
| 435 | + TestMethodBinder.TestMultipleGenericMethod(multiGenericClass) | ||
| 436 | + TestMethodBinder.TestMultipleGenericParamsMethod(singleGenericClass, multiGenericClass) | ||
| 437 | + | ||
| 438 | + if singleGenericClass.Value != 1 or multiGenericClass.Value != 1: | ||
| 439 | + raise AssertionError('Values were not updated') | ||
| 440 | + ")); | ||
| 441 | + } | ||
| 442 | + | ||
| 404 | 443 | public class CSharpModel | |
| 405 | 444 | { | |
| 406 | 445 | public static dynamic ProvidedArgument; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,9 +124,6 @@ internal static MethodInfo ResolveGenericMethod(MethodInfo method, Type[] argTyp | |||
| 124 | 124 | var methodGenerics = method.GetGenericArguments(); | |
| 125 | 125 | var methodGenericMap = new Dictionary<Type, Type>(); | |
| 126 | 126 | ||
| 127 | - // The generics matching these args to the method | ||
| 128 | - var argsGenericMap = new Dictionary<Type, Type[]>(); | ||
| 129 | - | ||
| 130 | 127 | // Just cache this type for sake of performance on iterations | |
| 131 | 128 | var objType = typeof(object); | |
| 132 | 129 | ||
@@ -151,7 +148,6 @@ internal static MethodInfo ResolveGenericMethod(MethodInfo method, Type[] argTyp | |||
| 151 | 148 | // If the generic type matches our params generic definition, this is our match | |
| 152 | 149 | // go ahead and match these types to this arg | |
| 153 | 150 | if (paramGenericDefinition == genericType) { | |
| 154 | - argsGenericMap.Add(argTypes[k], currentType.GenericTypeArguments); | ||
| 155 | 151 | ||
| 156 | 152 | // The matching generic for this method parameter | |
| 157 | 153 | var paramGenerics = parameters[k].ParameterType.GenericTypeArguments; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments