xsharp.eu • Error xs1061 in Compare method
Page 1 of 1

Error xs1061 in Compare method

Posted: Mon Feb 03, 2020 10:11 am
by wriedmann
Hello,

please see this code:

Code: Select all

using System.Collections.Generic

class xCompare

public property MyValue as string auto

end class

class xComparer<xCompare> implements IComparer<xCompare>

method Compare( o1 as xCompare, o2 as xCompare ) as int
local nReturn as int
local c1 as string
local c2 as string

c1 := o1:MyValue // error XS1061: 'xCompare' does not contain a definition for 'MyValue' and no accessible extension method 'MyValue' accepting a first argument of type 'xCompare' could be found 
c2  := o2:MyValue // error XS1061: 'xCompare' does not contain a definition for 'MyValue' and no accessible extension method 'MyValue' accepting a first argument of type 'xCompare' could be found 

nReturn := String.Compare( c1, c2 )

return nReturn

end class
The error seems to have to do with the fact that the Compare method is using generics.
When I remove the generics part from the method declaration, the code compiles without error.

Wolfgang

Error xs1061 in Compare method

Posted: Mon Feb 03, 2020 11:57 am
by Chris
Hi Wolfgang,

This is because there's a name conflict between the name of the Generic class param and the type having the same named. Normally the naming convention you would use for that is

class xComparer<T> implements IComparer<xCompare>

if what you intended to do was to force the generic param being of type xCompare, then you would need to use

class xComparer<T> implements IComparer<xCompare> where T is xCompare

Error xs1061 in Compare method

Posted: Mon Feb 03, 2020 1:09 pm
by wriedmann
Hi Chris,

thank you very much! That solved my problem.

Sometimes it seems I have problems with the syntax - and could not find any samples, therefore I've asked here.

Thank you again!

Wolfgang
P.S. I like the XPorter enhancements very much!

Error xs1061 in Compare method

Posted: Mon Feb 03, 2020 2:28 pm
by Chris
You're welcome Wolfgang, that's why we have the forums! :)