Author: jackson
Date: 2007-11-20 11:30:25 -0500 (Tue, 20 Nov 2007)
New Revision: 89992
Modified:
trunk/olive/class/agmono/Mono/ChangeLog
trunk/olive/class/agmono/Mono/Helper.cs
trunk/olive/class/agmono/Mono/NativeMethods.cs
trunk/olive/class/agmono/Mono/XamlLoaderCallbacks.cs
Log:
* NativeMethods.cs: Add value_from_str_with_typename. This
* allows
you to parse a value string without having it's Kind.
- Also added type_create_instance_from_kind. Pretty self
explanatory function.
* XamlLoaderCallbacks.cs: Make SetAttribute return true if it
actually does set the attribute.
* Helper.cs: When we encounter an agclr.dll type while trying to
parse an attribute, give agclr (who is calling us) back the
unmanaged value so that it can create the managed wrapper and
call
the new function SetAttributeFromValue.
Modified: trunk/olive/class/agmono/Mono/ChangeLog
===================================================================
--- trunk/olive/class/agmono/Mono/ChangeLog 2007-11-20 16:30:03 UTC (rev
89991)
+++ trunk/olive/class/agmono/Mono/ChangeLog 2007-11-20 16:30:25 UTC (rev
89992)
@@ -1,3 +1,16 @@
+2007-11-20 Jackson Harper <[EMAIL PROTECTED]>
+
+ * NativeMethods.cs: Add value_from_str_with_typename. This allows
+ you to parse a value string without having it's Kind.
+ - Also added type_create_instance_from_kind. Pretty self
+ explanatory function.
+ * XamlLoaderCallbacks.cs: Make SetAttribute return true if it
+ actually does set the attribute.
+ * Helper.cs: When we encounter an agclr.dll type while trying to
+ parse an attribute, give agclr (who is calling us) back the
+ unmanaged value so that it can create the managed wrapper and call
+ the new function SetAttributeFromValue.
+
2007-11-16 Jeffrey Stedfast <[EMAIL PROTECTED]>
* NativeMethods.cs: Bind to surface_get_toplevel() and fix the
Modified: trunk/olive/class/agmono/Mono/Helper.cs
===================================================================
--- trunk/olive/class/agmono/Mono/Helper.cs 2007-11-20 16:30:03 UTC (rev
89991)
+++ trunk/olive/class/agmono/Mono/Helper.cs 2007-11-20 16:30:25 UTC (rev
89992)
@@ -73,26 +73,30 @@
return converter;
}
- public static void SetPropertyFromString (object target, string
name, string value, out string error)
+ public static bool SetPropertyFromString (object target, string
name, string value, out string error, out IntPtr unmanaged_value)
{
+ unmanaged_value = IntPtr.Zero;
+
PropertyInfo pi = target.GetType ().GetProperty (name);
if (pi == null){
error = "no property descriptor found";
- return;
+ return false;
}
TypeConverter converter = GetConverterFor (pi);
if (!converter.CanConvertFrom (typeof (string))){
//
- // MS does not seem to handle this yet either,
but I think a logical improvement
- // here is to call back into unmanaged code
something like xaml_create_object_from_str
- // with the attribute string, and see if the
managed code can parse it, this would
- // allow you to stick things like Colors and
KeySplines on your object and still have
- // custom setters
+ // Attempt to create an unmanaged Value*
object, if one is created, the managed parser
+ // will create a managed wrapper for the object
and call SetPropertyFromValue with the
+ // managed object
//
- error = "unable to convert to this type from a
string";
- return;
+ unmanaged_value =
NativeMethods.value_from_str_with_typename (pi.PropertyType.Name, name, value);
+ if (unmanaged_value == IntPtr.Zero)
+ error = "unable to convert to this type
from a string";
+
+ error = "Unmanaged object created, a managed
wrapper must be created to set this property.";
+ return false;
}
error = null;
@@ -101,8 +105,29 @@
} catch (Exception e) {
error = e.ToString ();
}
+
+ return true;
}
+ public static bool SetPropertyFromValue (object target, string
name, object value, out string error)
+ {
+ PropertyInfo pi = target.GetType ().GetProperty (name);
+ if (pi == null){
+ error = "no property descriptor found";
+ return false;
+ }
+
+ error = null;
+ try {
+ pi.SetValue (target, value, null);
+ } catch (Exception e) {
+ error = e.ToString ();
+ return false;
+ }
+
+ return true;
+ }
+
public static object ChangeType (object obj, Type type)
{
return Convert.ChangeType (obj, type);
Modified: trunk/olive/class/agmono/Mono/NativeMethods.cs
===================================================================
--- trunk/olive/class/agmono/Mono/NativeMethods.cs 2007-11-20 16:30:03 UTC
(rev 89991)
+++ trunk/olive/class/agmono/Mono/NativeMethods.cs 2007-11-20 16:30:25 UTC
(rev 89992)
@@ -67,7 +67,10 @@
[DllImport("moon")]
public extern static bool type_get_value_type (Kind type);
-
+
+ [DllImport("moon")]
+ public extern static bool type_create_instance_from_kind (Kind
type);
+
[DllImport("moon")]
public extern static IntPtr dependency_property_lookup (Kind
type, string name);
@@ -647,7 +650,10 @@
[DllImport ("moon")]
public extern static void print_stack_trace ();
#endif
-
+
+ [DllImport ("moon")]
+ public extern static IntPtr value_from_str_with_typename
(string type_name, string prop_name, string str);
+
#region HtmlTimer
public delegate bool GSourceFunc (IntPtr data);
Modified: trunk/olive/class/agmono/Mono/XamlLoaderCallbacks.cs
===================================================================
--- trunk/olive/class/agmono/Mono/XamlLoaderCallbacks.cs 2007-11-20
16:30:03 UTC (rev 89991)
+++ trunk/olive/class/agmono/Mono/XamlLoaderCallbacks.cs 2007-11-20
16:30:25 UTC (rev 89992)
@@ -32,7 +32,7 @@
namespace Mono.Xaml
{
public delegate IntPtr LoadObjectCallback (string asm_name, string
asm_path, string ns, string type_name);
- public delegate void SetAttributeCallback (IntPtr target, string name,
string value);
+ public delegate bool SetAttributeCallback (IntPtr target, string name,
string value);
public delegate bool HookupEventCallback (IntPtr target, string name,
string value);
public delegate void InsertMappingCallback (string key, string value);
public delegate string GetMappingCallback (string key);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches