From dc995bd1da98971009454f4efe043d6237d00729 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sun, 21 Jun 2015 15:39:58 +0200 Subject: * OpenTK: * OpenTKGameWindow.cs: * Tests.csproj: * GOLIBTest_4.cs: * GOLIBTest_1.cs: * Window.goml: * Listbox.goml: * test4.goml: * GOLIBTest_Expandable.cs: * testExpandable.goml: debug and test * Colors.cs: debug argb->rgba * CompilerServices.cs: value type conversion * Border.cs: default border =1 * Checkbox.cs: * Expandable.cs: changes in update technic * Group.cs: Clipping debug (need rework) * Label.cs: debug text positionning * Slider.cs: debug * TextBox.cs: selectable=true by default --- src/CompilerServices/CompilerServices.cs | 33 ++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'src/CompilerServices/CompilerServices.cs') diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index d7d19fa1..ae4b700a 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -270,8 +270,12 @@ namespace go if (!srcValueType.IsValueType) il.Emit(OpCodes.Castclass, srcValueType); - if (piTarget.PropertyType == typeof(string)) - il.Emit(OpCodes.Callvirt, miToStr); + else + il.Emit( OpCodes.Callvirt, GetConvertMethod( piTarget.PropertyType )); + // if (piTarget.PropertyType == typeof(string)) +// else if ( srcValueType != piTarget.PropertyType) +// + il.Emit(OpCodes.Callvirt, piTarget.GetSetMethod()); } il.MarkLabel(labFailed); @@ -284,6 +288,31 @@ namespace go //Delegate del = dm.CreateDelegate(typeof(System.EventHandler)); addHandler.Invoke(_source, new object[] {del}); } + + #region conversions + + internal static MethodInfo GetConvertMethod( Type targetType ) + { + string name; + + if( targetType == typeof( bool ) ) + name = "ToBoolean"; + else if( targetType == typeof( byte ) ) + name = "ToByte"; + else if( targetType == typeof( short ) ) + name = "ToInt16"; + else if( targetType == typeof( int ) ) + name = "ToInt32"; + else if( targetType == typeof( long ) ) + name = "ToInt64"; + else if (targetType == typeof (string ) ) + return typeof(object).GetMethod("ToString", Type.EmptyTypes); + else + throw new NotImplementedException( string.Format( "Conversion to {0} is not implemented.", targetType.Name ) ); + + return typeof( Convert ).GetMethod( name, BindingFlags.Static | BindingFlags.Public, null, new Type[] { typeof( object ) }, null ); + } + #endregion public static FieldInfo getEventHandlerField(Type type, string eventName) { -- cgit v1.3.1-4-g156e