/// <summary>This operator is used in code generated by the compiler when needed.</summary>
[DebuggerStepThrough];
PUBLIC STATIC OPERATOR IMPLICIT(u AS __Usual ) AS Logic
IF (u:IsNull) .OR. (!u:_initialized)
RETURN false
ENDIF
RETURN u:_usualType SWITCH__UsualType.Logic => u:_logicValue,
__UsualType.Long => u:_intValue != 0,
__UsualType.Int64 => u:_i64Value != 0,
__UsualType.Currency => u:_currencyValue != 0,
__UsualType.Decimal => u:_decimalValue != 0m,
_ => THROW __Usual.ConversionError(8u, TYPEOF(Logic), u),
END OPERATOR
This code disassembles to a SWITCH expression, which we do not support (yet) in X#.
If I disable the C# 8 Switch Expression support then it is decompiled into the correct code:
/// <summary>This operator is used in code generated by the compiler when needed.</summary>
[DebuggerStepThrough];
PUBLIC STATIC OPERATOR IMPLICIT(u AS __Usual ) AS Logic
IF (u:IsNull) .OR. (!u:_initialized)
RETURN false
ENDIF
SWITCH u:_usualType
CASE __UsualType.Logic
RETURN u:_logicValue
CASE __UsualType.Long
RETURN u:_intValue != 0
CASE __UsualType.Int64
RETURN u:_i64Value != 0
CASE __UsualType.Currency
RETURN u:_currencyValue != 0
CASE __UsualType.Decimal
RETURN u:_decimalValue != 0m
OTHERWISE
THROW __Usual.ConversionError(8u, TYPEOF(Logic), u)
END SWITCH
END OPERATOR
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Hi Robert,
thanks for your feedback.
I've just published a new Release that correct this one, and another one related to BinaryOperator, can you give it a try ?
Thanks,
Fab
Fab,
This seems to do it.
I figured it was indeed as easy as disabling the feature.
There may be more features in the C# 8, 9 and 10 area that we are not supporting yet, such as ranges, records, file scoped namespace declarations.
We DO support nint/nunit and init accessors.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Franz,
The _ variable in C# is a so called 'discard'. It is a way of assigning a value to a temporary variable. You can also use this discard for out parameters that you are not interested in.
The compiler will not warn that you are assigning to a discard and not using it.
And X# also supports the discard with the same name (the single underscore character).
I guess that the original code of the assembly assigns the return value of the call to a local and has a assertion check in Debug mode to see if the variable is what is expected.
The assertion is removed in release mode but the assignment is still there.
ILSpy detects that the variable is assigned but not used and uses the discard variable name for it.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
public static string ToPIN(this string pin)
{
string text = string.Empty;
for (int i = 0; i < pin.Length; i++)
{
text = text + "3" + pin[i];
}
return text;
}
public static method ToPIN(pin AS STRING) AS STRING
LOCAL text AS STRING
LOCAL i AS LONG
text := string.Empty
i := 0
WHILE i < pin:Length
// text := text + "3" + pin[i] // error XS9078
text := text + "3" + pin.Substring(i,1) // OK
i++
ENDDO
RETURN text
C# treats the string as array and can do the loop with
Franz,
Usually the C# compiler is much stricter than the X# compiler, but in this case it is not.
The C# code is adding a character to a string.Behind the scenes it translates