RTL2: missing platform mappings

Working on the Unified GUI, I stumbled on some missing platform mappings from the RTL2.

  1. IEnumerable
    We have the PlatformSequence that maps to IEnumerable, but not the non-generic one (just IEnumerable).
  2. Type.Instantiate
    Missing on Echoes, code could be simple:


Public Class TypeExtension
Extends Type

Public Function Instantiate As Object
  Return Activator.CreateInstance(Me)
  End Function
End Class
#End If
  1. Type. IsPrimitive
    Missing on Island, code could be simple:


Public Class TypeExtension
  Extends Type

  Public ReadOnly Property IsPrimitive As Boolean
      Return Me.IsValueType AndAlso Me.Code <> TypeCodes.None
    End Get
  End Property

End Class
#End If

use ISequence(Of T) (the cross-language equivalent of sequence of T in Oxygene)

    method Instantiate: Object;
      {$IF COOPER}
      result := mapped.newInstance()
      result := fClass.alloc.init;
      result := Activator.CreateInstance(mapped);
      result := mapped.Instantiate();

what am I missing? its outside all the ifdefs and has an Echoes implementation…

In my version ( I get on Echoes Full:

(E44) No member “Instantiate” on type System.Type

not on System.Type, no. That’s the .NET class.

So, I have to cast everything everywhere to make sure it’s the RTL class?

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.

Dim x As Type = SomeNetCallThatReturnsASystemType

The same will happen for String, fwiw.

That is the issue at hand yes.

I have something like this:

Dim x as PlatformType =  ....

As x is a mapped class, I expect the GetType to be mapped as PlatformType too …

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 ;).

The real code:

    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

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
  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?

It’s there.

So I have to cast it …

In this case, for now, yes.

logged bugs://85774: Expand [DefaultStringType(] to DateTime and Type