Working on the Unified GUI, I stumbled on some missing platform mappings from the RTL2.
IEnumerable
We have the PlatformSequence that maps to IEnumerable, but not the non-generic one (just IEnumerable).
Type.Instantiate
Missing on Echoes, code could be simple:
#If ECHOES Then
Public Class TypeExtension
Extends Type
Public Function Instantiate As Object
Return Activator.CreateInstance(Me)
End Function
End Class
#End If
Type. IsPrimitive
Missing on Island, code could be simple:
#If ISLAND Then
Public Class TypeExtension
Extends Type
Public ReadOnly Property IsPrimitive As Boolean
Get
Return Me.IsValueType AndAlso Me.Code <> TypeCodes.None
End Get
End Property
End Class
#End If
method Instantiate: Object;
begin
{$IF COOPER}
result := mapped.newInstance()
{$ELSEIF TOFFEE AND NOT ISLAND}
result := fClass.alloc.init;
{$ELSEIF ECHOES}
result := Activator.CreateInstance(mapped);
{$ELSEIF ISLAND}
result := mapped.Instantiate();
{$ENDIF}
end;
end;
what am I missing? its outside all the ifdefs and has an Echoes implementation…
Depending on where the variable comes from, either cast, or just make sure you have RemObjects.Elements.RTL in use, so that when you do, say, Dim t As Type, it uses the right (cross-platform) Type class. Being mapped, the two types are assignment compatible, but iff you do, say
Dim x = SomeNetCallThatReturnsASystemType
then x will be type-inferred as System.Type and not RemObjects.Elements.RTL, yes. you can work around by e.g.
ell, then you’re EXPLCICITLY telling the compiler to NOT use the mapped type? why?
You should only use the Platform* aliases if you explicitly need to bypass the RTL2 mappings, e.g. to call an API not exposed ion the mapping, and purposely understanding that you’re switching to platform-specific code at that point. (and even then it’s extremely useless, as the members on PlatformType won’t be cross-platform, so you might as well just cast to System.Type for clarity ;).
For Each f as Reflection.Field In (New Reflection.Type withPlatformType(owner.GetType)).Fields
If f.Name = fieldName Then
FieldInfo = f
Instance = owner
//fill the field with a new instance
Value = f.GetType.Instantiate //fails on Echoes
Exit For
End If
Next
My apologies; l one thing I forgot is that the RTL2 Reflection types are ein their own namespace, so you gotta do
Imports RemObjects.Elements.RTL.Reflection
as well (or add it ti the default uses).
after that, this compiles for me:
Imports RemObjects.Elements.RTL.Reflection
Module Program
Sub Main(args as String())
writeLn("The magic happens here.")
Dim owner As String
Dim fieldName As String
For Each f as Reflection.Field In (New Reflection.Type withPlatformType(owner.GetType)).Fields
If f.Name = fieldName Then
'FieldInfo = f
'Instance = owner
//fill the field with a new instance
Dim Value = CType(f.GetType, Type).Instantiate //fails on Echoes
Exit For
End If
Next
End Sub
End Module
I could see an argument be made for making GetType and typeOf() return Imports RemObjects.Elements.RTL.Reflection.Type, when it’s in scope. I’ll see what we can do there. IIRC we had a similar issue logged last week for a non-String type two add the special compiler magic that RTL2 String gets, right? Do you recall what/where?