2003-05-19 07:18:52 +00:00
|
|
|
// GLib.TypeConverter.cs : Convert between fundamental and .NET types
|
|
|
|
//
|
|
|
|
// Author: Rachel Hestilow <hestilow@ximian.com>
|
|
|
|
//
|
|
|
|
// (c) 2002 Rachel Hestilow
|
|
|
|
|
2004-05-28 16:59:21 +00:00
|
|
|
namespace GLib {
|
2003-05-19 07:18:52 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
2004-01-27 23:55:13 +00:00
|
|
|
using System.Reflection;
|
2003-05-19 07:18:52 +00:00
|
|
|
|
|
|
|
public class TypeConverter {
|
2003-11-28 05:29:34 +00:00
|
|
|
|
|
|
|
private TypeConverter () {}
|
|
|
|
|
2003-12-15 16:59:25 +00:00
|
|
|
public static GType LookupType (System.Type type)
|
2003-05-19 07:18:52 +00:00
|
|
|
{
|
|
|
|
if (type.Equals (typeof (string)))
|
2003-12-15 16:59:25 +00:00
|
|
|
return GType.String;
|
2003-05-19 07:18:52 +00:00
|
|
|
if (type.Equals (typeof (bool)))
|
2003-12-15 16:59:25 +00:00
|
|
|
return GType.Boolean;
|
2003-05-19 07:18:52 +00:00
|
|
|
if (type.Equals (typeof (int)))
|
2003-12-15 16:59:25 +00:00
|
|
|
return GType.Int;
|
2003-05-19 07:18:52 +00:00
|
|
|
if (type.Equals (typeof (double)))
|
2003-12-15 16:59:25 +00:00
|
|
|
return GType.Double;
|
2003-05-19 07:18:52 +00:00
|
|
|
if (type.Equals (typeof (float)))
|
2003-12-15 16:59:25 +00:00
|
|
|
return GType.Float;
|
2003-05-19 07:18:52 +00:00
|
|
|
if (type.Equals (typeof (char)))
|
2003-12-15 16:59:25 +00:00
|
|
|
return GType.Char;
|
2003-05-19 07:18:52 +00:00
|
|
|
if (type.Equals (typeof (uint)))
|
2003-12-15 16:59:25 +00:00
|
|
|
return GType.UInt;
|
2004-01-14 18:05:50 +00:00
|
|
|
if (type.IsSubclassOf (typeof (GLib.Object)))
|
|
|
|
return GType.Object;
|
2004-02-17 05:09:13 +00:00
|
|
|
PropertyInfo pi = type.GetProperty ("GType", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
|
|
|
if (pi != null)
|
|
|
|
return (GType) pi.GetValue (null, null);
|
2004-02-17 21:49:24 +00:00
|
|
|
if (type.IsSubclassOf (typeof (GLib.Opaque)))
|
|
|
|
return GType.Pointer;
|
2004-02-17 05:09:13 +00:00
|
|
|
if (type.IsValueType)
|
|
|
|
return GType.Pointer;
|
2004-01-27 23:55:13 +00:00
|
|
|
|
2004-05-28 16:59:21 +00:00
|
|
|
return ManagedValue.GType;
|
2003-05-19 07:18:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|