2007-08-14 Mike Kestner <mkestner@novell.com>
* glib/ListBase.cs : add AllocNativeElement method and an Append (object) method that uses it. * glib/List.cs : add object[] ctor using new append method. * glib/SList.cs : add object[] ctor using new append method. These are needed to return G(S)List* values as virtual method return values. svn path=/trunk/gtk-sharp/; revision=84112
This commit is contained in:
parent
bc971d723f
commit
f956b09858
4 changed files with 49 additions and 0 deletions
|
@ -1,3 +1,12 @@
|
|||
2007-08-14 Mike Kestner <mkestner@novell.com>
|
||||
|
||||
* glib/ListBase.cs : add AllocNativeElement method and an
|
||||
Append (object) method that uses it.
|
||||
* glib/List.cs : add object[] ctor using new append method.
|
||||
* glib/SList.cs : add object[] ctor using new append method.
|
||||
These are needed to return G(S)List* values as virtual method
|
||||
return values.
|
||||
|
||||
2007-08-13 Mike Kestner <mkestner@novell.com>
|
||||
|
||||
* generator/MethodBody.cs : finally kill the s/out ref/ref/ hack.
|
||||
|
|
|
@ -99,5 +99,10 @@ namespace GLib {
|
|||
|
||||
public List (IntPtr raw, System.Type element_type, bool owned, bool elements_owned) : base (raw, element_type, owned, elements_owned) {}
|
||||
|
||||
public List (object[] elements, System.Type element_type, bool owned, bool elements_owned) : this (IntPtr.Zero, element_type, owned, elements_owned)
|
||||
{
|
||||
foreach (object o in elements)
|
||||
Append (o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,11 @@ namespace GLib {
|
|||
this.Append (Marshaller.StringToPtrGStrdup (item));
|
||||
}
|
||||
|
||||
public void Append (object item)
|
||||
{
|
||||
this.Append (AllocNativeElement (item));
|
||||
}
|
||||
|
||||
public void Prepend (IntPtr raw)
|
||||
{
|
||||
list_ptr = Prepend (list_ptr, raw);
|
||||
|
@ -122,6 +127,30 @@ namespace GLib {
|
|||
private FilenameString () {}
|
||||
}
|
||||
|
||||
IntPtr AllocNativeElement (object element)
|
||||
{
|
||||
if (element_type == null) {
|
||||
if (element is IWrapper)
|
||||
return (element as IWrapper).Handle;
|
||||
else
|
||||
return (IntPtr) GCHandle.Alloc (element);
|
||||
} else {
|
||||
if (element_type == typeof (string))
|
||||
return Marshaller.StringToPtrGStrdup (element as string);
|
||||
else if (element_type == typeof (FilenameString))
|
||||
return Marshaller.StringToFilenamePtr (element as string);
|
||||
else if (element_type == typeof (IntPtr))
|
||||
return (IntPtr) GCHandle.Alloc (element);
|
||||
else if (typeof (IWrapper).IsAssignableFrom (element_type))
|
||||
return (element as IWrapper).Handle;
|
||||
else if (element_type == typeof (int))
|
||||
return new IntPtr ((int) element);
|
||||
else if (element_type.IsValueType)
|
||||
return Marshaller.StructureToPtrAlloc (element);
|
||||
}
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
internal object DataMarshal (IntPtr data)
|
||||
{
|
||||
object ret = null;
|
||||
|
|
|
@ -99,5 +99,11 @@ namespace GLib {
|
|||
public SList (IntPtr raw, System.Type element_type) : this (raw, element_type, false, false) {}
|
||||
|
||||
public SList (IntPtr raw, System.Type element_type, bool owned, bool elements_owned) : base (raw, element_type, false, false) {}
|
||||
|
||||
public SList (object[] members, System.Type element_type, bool owned, bool elements_owned) : this (IntPtr.Zero, element_type, owned, elements_owned)
|
||||
{
|
||||
foreach (object o in members)
|
||||
Append (o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue