2003-05-19 07:18:52 +00:00
|
|
|
// GLib.TypeConverter.cs : Convert between fundamental and .NET types
|
|
|
|
//
|
|
|
|
// Author: Rachel Hestilow <hestilow@ximian.com>
|
|
|
|
//
|
2004-06-25 18:42:19 +00: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 07:18:52 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|