[Vala] Problem with programmatic generic object instantiation



Hi,

I have a generic array implementation like so:

public class GArrSerializable<T> : Serializable, Object  {
  public T[] data;
  public int length;
  public GArrSerializable(int size = 0) {
    data = new T[size];
  }

  public Type type () { return typeof (T); }

...etc

and a derived type:

public class IntArr : GArrSerializable<int> {

  public IntArr(int size = 0) {
    base (size);
  }
}

If I create an instance of the type, then instance.type () returns 24 as
expected.
If I create an instance like so:
var ia = Object  new (type) as IntArr;
var t = ia.type ();

Then t is 4 rather than 24.  As it is in the instance when it tries to
deserialize.

Can you tell me why this is so, and how I can programmatically create
objects derived from a parameterised type?

Thanks

Andrew Lees


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]