mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-25 06:25:33 +00:00
fc42fa2c04
* glib/TypeConverter.cs : lookup GTypes for boxed value types. * glib/Value.cs : fix boxed type handling in object ctor. [Fixes #51043] svn path=/trunk/gtk-sharp/; revision=22555
55 lines
1.2 KiB
C#
55 lines
1.2 KiB
C#
// GLib.TypeConverter.cs : Convert between fundamental and .NET types
|
|
//
|
|
// Author: Rachel Hestilow <hestilow@ximian.com>
|
|
//
|
|
// (c) 2002 Rachel Hestilow
|
|
|
|
namespace GLibSharp {
|
|
using System;
|
|
using System.Collections;
|
|
using System.Reflection;
|
|
using GLib;
|
|
|
|
/// <summary>
|
|
/// Fundamental type converter
|
|
/// </summary>
|
|
///
|
|
/// <remarks>
|
|
/// Utilities for converting between TypeFundamentals and System.Type
|
|
/// </remarks>
|
|
public class TypeConverter {
|
|
|
|
private TypeConverter () {}
|
|
|
|
public static GType LookupType (System.Type type)
|
|
{
|
|
if (type.Equals (typeof (string)))
|
|
return GType.String;
|
|
if (type.Equals (typeof (bool)))
|
|
return GType.Boolean;
|
|
if (type.Equals (typeof (int)))
|
|
return GType.Int;
|
|
if (type.Equals (typeof (double)))
|
|
return GType.Double;
|
|
if (type.Equals (typeof (float)))
|
|
return GType.Float;
|
|
if (type.Equals (typeof (char)))
|
|
return GType.Char;
|
|
if (type.Equals (typeof (uint)))
|
|
return GType.UInt;
|
|
if (type.IsSubclassOf (typeof (GLib.Object)))
|
|
return GType.Object;
|
|
if (type.IsValueType) {
|
|
PropertyInfo pi = type.GetProperty ("GType");
|
|
if (pi == null)
|
|
return GType.Pointer;
|
|
else
|
|
return (GType) pi.GetValue (null, null);
|
|
}
|
|
|
|
return GType.None;
|
|
}
|
|
}
|
|
}
|
|
|