2003-05-19 09:18:52 +02:00
|
|
|
// GLib.TypeConverter.cs : Convert between fundamental and .NET types
|
|
|
|
//
|
|
|
|
// Author: Rachel Hestilow <hestilow@ximian.com>
|
|
|
|
//
|
2004-06-25 20:42:19 +02:00
|
|
|
// Copyright (c) 2002 Rachel Hestilow
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of version 2 of the Lesser GNU General
|
|
|
|
// Public License as published by the Free Software Foundation.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this program; if not, write to the
|
|
|
|
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
// Boston, MA 02111-1307, USA.
|
|
|
|
|
2003-05-19 09:18:52 +02:00
|
|
|
|
2004-05-28 18:59:21 +02:00
|
|
|
namespace GLib {
|
2003-05-19 09:18:52 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
2004-01-28 00:55:13 +01:00
|
|
|
using System.Reflection;
|
2003-05-19 09:18:52 +02:00
|
|
|
|
|
|
|
public class TypeConverter {
|
2003-11-28 06:29:34 +01:00
|
|
|
|
|
|
|
private TypeConverter () {}
|
|
|
|
|
2003-12-15 17:59:25 +01:00
|
|
|
public static GType LookupType (System.Type type)
|
2003-05-19 09:18:52 +02:00
|
|
|
{
|
2005-04-22 21:10:47 +02:00
|
|
|
if (type.Equals (typeof (char)))
|
|
|
|
return GType.Char;
|
2003-05-19 09:18:52 +02:00
|
|
|
if (type.Equals (typeof (bool)))
|
2003-12-15 17:59:25 +01:00
|
|
|
return GType.Boolean;
|
2003-05-19 09:18:52 +02:00
|
|
|
if (type.Equals (typeof (int)))
|
2003-12-15 17:59:25 +01:00
|
|
|
return GType.Int;
|
2005-04-22 21:10:47 +02:00
|
|
|
if (type.Equals (typeof (uint)))
|
|
|
|
return GType.UInt;
|
2004-12-03 21:04:18 +01:00
|
|
|
if (type.Equals (typeof (long)))
|
|
|
|
return GType.Int64;
|
|
|
|
if (type.Equals (typeof (ulong)))
|
|
|
|
return GType.UInt64;
|
2003-05-19 09:18:52 +02:00
|
|
|
if (type.Equals (typeof (float)))
|
2003-12-15 17:59:25 +01:00
|
|
|
return GType.Float;
|
2005-04-22 21:10:47 +02:00
|
|
|
if (type.Equals (typeof (double)))
|
|
|
|
return GType.Double;
|
|
|
|
if (type.Equals (typeof (string)))
|
|
|
|
return GType.String;
|
2004-01-14 19:05:50 +01:00
|
|
|
if (type.IsSubclassOf (typeof (GLib.Object)))
|
|
|
|
return GType.Object;
|
2004-12-01 22:41:10 +01:00
|
|
|
PropertyInfo pi = type.GetProperty ("GType", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
2004-02-17 06:09:13 +01:00
|
|
|
if (pi != null)
|
|
|
|
return (GType) pi.GetValue (null, null);
|
2004-02-17 22:49:24 +01:00
|
|
|
if (type.IsSubclassOf (typeof (GLib.Opaque)))
|
|
|
|
return GType.Pointer;
|
2004-01-28 00:55:13 +01:00
|
|
|
|
2004-05-28 18:59:21 +02:00
|
|
|
return ManagedValue.GType;
|
2003-05-19 09:18:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|