|
1 | | -// Copyright 2004-2021 Castle Project - http://www.castleproject.org/ |
| 1 | +// Copyright 2004-2025 Castle Project - http://www.castleproject.org/ |
2 | 2 | // |
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | 4 | // you may not use this file except in compliance with the License. |
@@ -121,9 +121,25 @@ private static GenericTypeParameterBuilder[] CopyGenericArguments( |
121 | 121 | { |
122 | 122 | var attributes = originalGenericArguments[i].GenericParameterAttributes; |
123 | 123 | newGenericParameters[i].SetGenericParameterAttributes(attributes); |
124 | | - var constraints = AdjustGenericConstraints(methodToCopyGenericsFrom, newGenericParameters, originalGenericArguments, originalGenericArguments[i].GetGenericParameterConstraints()); |
125 | 124 |
|
126 | | - newGenericParameters[i].SetInterfaceConstraints(constraints); |
| 125 | + var constraints = originalGenericArguments[i].GetGenericParameterConstraints(); |
| 126 | + if (constraints.Length > 0) |
| 127 | + { |
| 128 | + constraints = AdjustGenericConstraints(methodToCopyGenericsFrom, newGenericParameters, originalGenericArguments, constraints); |
| 129 | + |
| 130 | + var baseTypeConstraint = Array.Find(constraints, static c => c.IsClass); |
| 131 | + if (baseTypeConstraint != null) |
| 132 | + { |
| 133 | + newGenericParameters[i].SetBaseTypeConstraint(baseTypeConstraint); |
| 134 | + } |
| 135 | + |
| 136 | + var interfaceConstraints = Array.FindAll(constraints, static c => c.IsInterface); |
| 137 | + if (interfaceConstraints.Length > 0) |
| 138 | + { |
| 139 | + newGenericParameters[i].SetInterfaceConstraints(interfaceConstraints); |
| 140 | + } |
| 141 | + } |
| 142 | + |
127 | 143 | CopyNonInheritableAttributes(newGenericParameters[i], originalGenericArguments[i]); |
128 | 144 | } |
129 | 145 | catch (NotSupportedException) |
|
0 commit comments