Re: [Vala] Problem with programmatic generic object instantiation
- From: Daniel Espinosa <esodan gmail com>
- To: Andy Lees <andrewl oz gmail com>
- Cc: Vala-list <vala-list gnome org>
- Subject: Re: [Vala] Problem with programmatic generic object instantiation
- Date: Tue, 16 Feb 2016 06:16:05 -0600
Take in account that Type system is dynamically created, then a type number
will change with each execution.
Use
YourCreatedObject is typeof (Object)
to check if the created object is of type you need, like a derived object.
You can use
obj.get_type().is_a(typeof (Object))
And consider that your example is exactly the way to create an object of
Generic class, because you have set tje object type. Create a generic
instance with Object.new you should provide the object type.
El feb. 16, 2016 5:14 AM, "Andy Lees" <andrewl oz gmail com> escribió:
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
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]