Closed kalatchev closed 2 years ago
@kalatchev the dotnet CLR is case-sensitive which is what VB.Net uses.
We will remove the duplicate names in the next major release.
In the mean time can you not do something with reflection like this?
Dim methodInfo = GetType(ExtraComponents).GetMethods().FirstOrDefault(Function(m) m.Name = "GetComponent" AndAlso m.GetCustomAttribute(GetType(ObsoleteAttribute), False) Is Nothing)
methodInfo?.Invoke(component, New Object() {val})
you could then perhaps wrap that up in a helper extension method.
Thank you @milkshakeuk !
Your suggestion works just fine. The only modification I did is
Dim methodInfo = GetType(ExtraComponents).GetMethods().FirstOrDefault(Function(m) m.Name = "GetComponent")
since string comparison is case sensitive and Function(m) m.Name = "GetComponent"
returns correct MethodInfo
, there is no need to check for attributes, at least in this given situation.
Once again, thanks!
@kalatchev no problem, glad it worked for you.
Description In class
NHapi.Base.Model.ExtraComponents
there is a .net language incompatibility because there are two methods (GetComponent
andNumComponents
) that have duplicates with a different casing, which works only in C#, but not in a case-insensitive languages such as VB.NET. Example:getComponent
andGetComponent
. These two methods are uninvokable through VB.NET and generally have to be considered as a non-CLS compliant. Moreover, lower-case variants are marked as deprecated, so IMHO they should be simply removed.Environmental Details:
Additional details I tried to invoke them with
CallByName(obj1, "GetComponent", CallType.Method, 1)
but even that doesn't work and I'm gettingException thrown: 'System.Reflection.AmbiguousMatchException' in Microsoft.VisualBasic.dll
.I searched over the code, and issue
SA1300
is found on numerous places, and all they will have the same issue.