'In' operator fails when calling method from C#

Hi Team,

Kindly find below method(TestCall) which is from Oxygene

{$SCOPEDENUMS ON}
WeekDay = public flags (Monday, Tuesday, Wednessday);
WeekDays = public set of WeekDay;

function Class1.TestCall(WD: WeekDays): Boolean;
begin

var w : WeekDays := [WeekDay.Tuesday, WeekDay.Wednessday];
if WeekDay.Wednessday in w then // This is working as its only in Oxygene world
result := True else
result := False;

if WeekDay.Wednessday in WD then // This is NOT working as WD is comming from C# world 
result := True else
result := False; 

end;

  1. When we are calling this method from C# application ‘in’ operator failing and return false.
  2. When calling from C#, Method(TestCall) asking for the casting as below
    class1.TestCall((int)WeekDay.Wednessday); // Need to do casting

Please find attached sample project for more details.
Could you please have a look into this, Let us know if required more details.

ClassLibrary1.zip (203.2 KB)

Thankyou!

sets and flags are both features specific to Oxygene, so I’m not surprised, but I’ll have a closer look.

Oh, the C# project is even using Visual C#, not our compiler. Yeah, that wont work.

If inconvertible your project to RemObjects C#, it fails correctly, with

      class1.TestCall((int)WeekDay.Wednessday);//int 1  // E486 Parameter 1 is "Int32", should be "WeekDays", in call to Boolean Class1.TestCall(WeekDays WD)

you cannot just pass an int to a set, and since Visual C# does not support sets and they are not a CLS complain type, this can’t work. To interact between Oxygene and non-Elements .NET languages, you can only use CLS types. See https://docs.microsoft.com/en-us/dotnet/standard/language-independence-and-language-independent-components.