Author: toshok
Date: 2007-07-21 04:28:19 -0400 (Sat, 21 Jul 2007)
New Revision: 82409

Modified:
   trunk/olive/class/System.Silverlight/Makefile
   trunk/olive/class/System.Silverlight/System.Windows/ChangeLog
   
trunk/olive/class/System.Silverlight/System.Windows/ScriptableObjectGenerator.cs
   trunk/olive/class/System.Silverlight/System.Windows/WebApplication.cs
Log:
2007-07-21  Chris Toshok  <[EMAIL PROTECTED]>

        * WebApplication.cs, ScriptableObjectGenerator.cs: rework the
        scriptable object stuff pretty substantially.  separate type
        validation from the generation of the wrapper object.  This is so
        that eventually with events we won't need to validate the type
        whenever we wrap event args (since we'll already have validated it
        during the course of validating the class containing the
        scriptable event.)  Also, fix property sets, gets, and invocation.
        everything except events should be working.  Also, leave a comment
        about the Binder implementation (and how it's not necessaryin the
        long term.)



Modified: trunk/olive/class/System.Silverlight/Makefile
===================================================================
--- trunk/olive/class/System.Silverlight/Makefile       2007-07-21 08:25:59 UTC 
(rev 82408)
+++ trunk/olive/class/System.Silverlight/Makefile       2007-07-21 08:28:19 UTC 
(rev 82409)
@@ -3,6 +3,6 @@
 
 LIBRARY = System.SilverLight.dll
 
-LIB_MCS_FLAGS = -unsafe -r:System -r:agmono.dll
+LIB_MCS_FLAGS = -r:System -r:agmono.dll
 
 include ../../build/library.make

Modified: trunk/olive/class/System.Silverlight/System.Windows/ChangeLog
===================================================================
--- trunk/olive/class/System.Silverlight/System.Windows/ChangeLog       
2007-07-21 08:25:59 UTC (rev 82408)
+++ trunk/olive/class/System.Silverlight/System.Windows/ChangeLog       
2007-07-21 08:28:19 UTC (rev 82409)
@@ -1,3 +1,16 @@
+2007-07-21  Chris Toshok  <[EMAIL PROTECTED]>
+
+       * WebApplication.cs, ScriptableObjectGenerator.cs: rework the
+       scriptable object stuff pretty substantially.  separate type
+       validation from the generation of the wrapper object.  This is so
+       that eventually with events we won't need to validate the type
+       whenever we wrap event args (since we'll already have validated it
+       during the course of validating the class containing the
+       scriptable event.)  Also, fix property sets, gets, and invocation.
+       everything except events should be working.  Also, leave a comment
+       about the Binder implementation (and how it's not necessaryin the
+       long term.)
+
 2007-07-17  Chris Toshok  <[EMAIL PROTECTED]>
 
        * ScriptableObjectGenerator.cs (InvokeFromUnmanaged): marshal the

Modified: 
trunk/olive/class/System.Silverlight/System.Windows/ScriptableObjectGenerator.cs
===================================================================
--- 
trunk/olive/class/System.Silverlight/System.Windows/ScriptableObjectGenerator.cs
    2007-07-21 08:25:59 UTC (rev 82408)
+++ 
trunk/olive/class/System.Silverlight/System.Windows/ScriptableObjectGenerator.cs
    2007-07-21 08:28:19 UTC (rev 82409)
@@ -1,42 +1,230 @@
 using System;
+using System.Collections.Generic;
 using System.Text;
 using System.Windows.Browser;
 using System.Windows.Browser.Serialization;
 using System.Runtime.InteropServices;
 using System.Reflection;
+using System.Globalization;
 using Mono;
 
 namespace System.Windows
 {
-       internal class ScriptableObjectGenerator
-       {
-               public static void Generate (IntPtr plugin_handle, string 
nameOnJS, object obj)
+       delegate void InvokeDelegate (IntPtr obj_handle, IntPtr method_handle,
+                                     [MarshalAs (UnmanagedType.LPArray, 
SizeParamIndex = 3)]
+                                     IntPtr[] args,
+                                     int arg_count,
+                                     ref Value return_value);
+
+       delegate void SetPropertyDelegate (IntPtr obj_handle, IntPtr 
property_handle, ref Value value);
+       delegate void GetPropertyDelegate (IntPtr obj_handle, IntPtr 
property_handle, ref Value value);
+       delegate void EventHandlerDelegate (IntPtr obj_handle, IntPtr 
event_handle);
+
+
+       // XXX This class shouldn't be needed.  MS just calls
+       // Convert.ChangeType on the arguments, and *somehow* gets the
+       // exception returned to JS.  We don't do that yet, so
+       // unhandled exceptions crash the browser.  In an effort to
+       // keep things limping along, we use this binder.
+       class JSFriendlyMethodBinder : Binder {
+               public override FieldInfo BindToField (BindingFlags 
bindingAttr, FieldInfo [] match, object value, CultureInfo culture)
                {
-                       new ScriptableObjectGenerator (plugin_handle, nameOnJS, 
obj).Generate ();
+                       throw new NotImplementedException ();
                }
 
-               string name;
+               public override MethodBase BindToMethod (BindingFlags 
bindingAttr, MethodBase [] match, ref object [] args, ParameterModifier [] 
modifiers, CultureInfo culture, string [] names, out object state)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override object ChangeType (object value, Type type, 
CultureInfo culture)
+               {
+                       if (value == null)
+                               return null;
+
+                       if (value.GetType() == type)
+                               return value;
+
+                       /* the set of source types for JS functions is
+                        * very, very small, so we switch over the
+                        * parameter type first */
+
+                       try {
+                               return Convert.ChangeType (value, type, 
culture);
+                       }
+                       catch {
+                               // no clue if this is right.. if we
+                               // fail to convert, what do we return?
+
+                               switch (Type.GetTypeCode (type))
+                               {
+                               case TypeCode.Char:
+                               case TypeCode.Byte:
+                               case TypeCode.SByte:
+                               case TypeCode.Int16:
+                               case TypeCode.Int32:
+                               case TypeCode.Int64:
+                               case TypeCode.UInt16:
+                               case TypeCode.UInt32:
+                               case TypeCode.UInt64:
+                               case TypeCode.Single:
+                               case TypeCode.Double:
+                                       return Convert.ChangeType (0, type, 
culture);
+
+                               case TypeCode.String:
+                                       return "";
+
+                               case TypeCode.Boolean:
+                                       return false;
+                               }
+                       }
+
+                       throw new NotSupportedException ();
+               }
+
+               public override void ReorderArgumentArray (ref object [] args, 
object state)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override MethodBase SelectMethod (BindingFlags 
bindingAttr, MethodBase [] match, Type [] types, ParameterModifier [] modifiers)
+               {
+                       throw new NotImplementedException ();
+               }
+
+               public override PropertyInfo SelectProperty (BindingFlags 
bindingAttr, PropertyInfo [] match, Type returnType, Type [] indexes, 
ParameterModifier [] modifiers)
+               {
+                       throw new NotImplementedException ();
+               }
+       }
+
+
+       internal class ScriptableNativeMethods {
+               [DllImport ("moonplugin", EntryPoint = 
"moonlight_scriptable_object_wrapper_create")]
+               public static extern IntPtr wrapper_create (IntPtr 
plugin_handle, IntPtr obj_handle,
+                                                           InvokeDelegate 
invoke,
+                                                           SetPropertyDelegate 
set_prop,
+                                                           GetPropertyDelegate 
get_prop,
+                                                           
EventHandlerDelegate add_event,
+                                                           
EventHandlerDelegate remove_event);
+
+               [DllImport ("moonplugin", EntryPoint = 
"moonlight_scriptable_object_add_property")]
+               public static extern void add_property (IntPtr plugin_handle,
+                                                       IntPtr wrapper,
+                                                       IntPtr property_handle,
+                                                       string property_name,
+                                                       TypeCode property_type,
+                                                       bool readable,
+                                                       bool writable);
+
+               [DllImport ("moonplugin", EntryPoint = 
"moonlight_scriptable_object_add_event")]
+               public static extern void add_event (IntPtr plugin_handle,
+                                                    IntPtr wrapper,
+                                                    IntPtr event_handle,
+                                                    string event_name);
+
+               [DllImport ("moonplugin", EntryPoint = 
"moonlight_scriptable_object_add_method")]
+               public static extern void add_method (IntPtr plugin_handle,
+                                                     IntPtr wrapper,
+                                                     IntPtr method_handle,
+                                                     string method_name,
+                                                     TypeCode 
method_return_type,
+                                                     TypeCode[] 
method_parameter_types,
+                                                     int parameter_count);
+
+               [DllImport ("moonplugin", EntryPoint = 
"moonlight_scriptable_object_register")]
+               public static extern void register (IntPtr plugin_handle,
+                                                   string name,
+                                                   IntPtr wrapper);
+       }
+
+       internal class ScriptableObjectWrapper {
+
+               IntPtr scriptable_wrapper;
                object obj;
-               Type type;
-               IntPtr plugin_handle;
-               IntPtr scriptable_wrapper;
 
-               ScriptableObjectGenerator (IntPtr plugin_handle, string name, 
object obj)
+               List<GCHandle> handles; /* for methods, events, properties, as 
well as the object itself */
+
+               public ScriptableObjectWrapper (object obj)
                {
-                       this.plugin_handle = plugin_handle;
-                       this.name = name;
+                       this.handles = new List<GCHandle>();
                        this.obj = obj;
-                       type = obj.GetType ();
+
+                       GCHandle obj_handle = GCHandle.Alloc (obj);
+
+                       handles.Add (obj_handle);
+                       
+                       scriptable_wrapper = 
ScriptableNativeMethods.wrapper_create (WebApplication.Current.PluginHandle,
+                                                                               
     (IntPtr)obj_handle,
+                                                                               
     invoke,
+                                                                               
     set_prop,
+                                                                               
     get_prop,
+                                                                               
     add_event,
+                                                                               
     remove_event);
                }
 
-               delegate void InvokeDelegate (IntPtr obj_handle, IntPtr 
method_handle,
-                                             IntPtr args,
-                                             int arg_count,
-                                             ref Value return_value);
+               public IntPtr UnmanagedWrapper {
+                       get { return scriptable_wrapper; }
+               }
 
-               delegate void SetPropertyDelegate (IntPtr obj_handle, IntPtr 
property_handle, Value value);
-               delegate void GetPropertyDelegate (IntPtr obj_handle, IntPtr 
property_handle, ref Value value);
+               public void AddProperty (PropertyInfo pi)
+               {
+                       GCHandle prop_handle = GCHandle.Alloc (pi);
 
+                       handles.Add (prop_handle);
+
+                       TypeCode tc = Type.GetTypeCode (pi.PropertyType);
+
+                       ScriptableNativeMethods.add_property 
(WebApplication.Current.PluginHandle,
+                                                             
scriptable_wrapper,
+                                                             
(IntPtr)prop_handle,
+                                                             pi.Name,
+                                                             tc,
+                                                             pi.CanRead,
+                                                             pi.CanWrite);
+               }
+
+               public void AddEvent (EventInfo ei)
+               {
+                       GCHandle event_handle = GCHandle.Alloc (ei);
+
+                       handles.Add (event_handle);
+
+                       ScriptableNativeMethods.add_event 
(WebApplication.Current.PluginHandle,
+                                                          scriptable_wrapper,
+                                                          (IntPtr)event_handle,
+                                                          ei.Name);
+               }
+
+               public void AddMethod (MethodInfo mi)
+               {
+                       ParameterInfo[] ps = mi.GetParameters();
+                       TypeCode[] tcs = new TypeCode [ps.Length];
+
+                       foreach (ParameterInfo p in ps) {
+                               TypeCode pc = Type.GetTypeCode 
(p.ParameterType);
+                               tcs[p.Position] = pc;
+                       }
+
+                       GCHandle method_handle = GCHandle.Alloc (mi);
+
+                       handles.Add (method_handle);
+
+                       ScriptableNativeMethods.add_method 
(WebApplication.Current.PluginHandle,
+                                                           scriptable_wrapper,
+                                                           
(IntPtr)method_handle,
+                                                           mi.Name,
+                                                           Type.GetTypeCode 
(mi.ReturnType),
+                                                           tcs,
+                                                           tcs.Length);
+               }
+
+               static InvokeDelegate invoke = new InvokeDelegate 
(InvokeFromUnmanaged);
+               static SetPropertyDelegate set_prop = new SetPropertyDelegate 
(SetPropertyFromUnmanaged);
+               static GetPropertyDelegate get_prop = new GetPropertyDelegate 
(GetPropertyFromUnmanaged);
+               static EventHandlerDelegate add_event = new 
EventHandlerDelegate (AddEventFromUnmanaged);
+               static EventHandlerDelegate remove_event = new 
EventHandlerDelegate (RemoveEventFromUnmanaged);
+
                static object ObjectFromValue (Value v)
                {
                        switch (v.k) {
@@ -53,6 +241,7 @@
                        case Kind.STRING:
                                return Marshal.PtrToStringAuto (v.u.p);
                        default:
+                               Console.WriteLine ("unsupported Kind.{0}", v.k);
                                throw new NotSupportedException ();
                        }
                }
@@ -68,13 +257,17 @@
                                v.k = Kind.DOUBLE;
                                v.u.d = (double)o;
                                break;
+                       case TypeCode.Int32:
+                               v.k = Kind.INT32;
+                               v.u.i32 = (int)o;
+                               break;
                        case TypeCode.Int64:
                                v.k = Kind.INT64;
-                               v.u.d = (long)o;
+                               v.u.i64 = (long)o;
                                break;
                        case TypeCode.UInt64:
                                v.k = Kind.UINT64;
-                               v.u.d = (ulong)o;
+                               v.u.ui64 = (ulong)o;
                                break;
                        case TypeCode.String:
                                v.k = Kind.STRING;
@@ -85,33 +278,39 @@
                                v.u.p = result;
                                break;
                        default:
+                               Console.WriteLine ("unsupported TypeCode.{0}", 
Type.GetTypeCode(o.GetType()));
                                throw new NotSupportedException ();
                        }
                }
 
-               static void InvokeFromUnmanaged (IntPtr obj_handle, IntPtr 
method_handle, IntPtr uargs, int arg_count, ref Value return_value)
+               static void InvokeFromUnmanaged (IntPtr obj_handle, IntPtr 
method_handle, IntPtr[] uargs, int arg_count, ref Value return_value)
                {
                        object obj = GCHandle.FromIntPtr (obj_handle).Target;
                        MethodInfo mi = (MethodInfo)GCHandle.FromIntPtr 
(method_handle).Target;
 
                        object[] margs = new object[arg_count];
+                       ParameterInfo[] pis = mi.GetParameters ();
+
+                       Console.WriteLine ("arg_count = {0}", arg_count);
                        for (int i = 0; i < arg_count; i ++) {
-                               Value v;
+                               Value v = (Value)Marshal.PtrToStructure 
(uargs[i], typeof (Value));
 
-                               unsafe {
-                                       v = (Value)Marshal.PtrToStructure 
((IntPtr)(uargs.ToInt64() + sizeof (Value) * i), typeof (Value));
-                               }
+                               object o = ObjectFromValue (v);
+                               Console.WriteLine ("margs[{1}] = {2} ({0})", 
o.GetType(), i, o);
 
-                               margs[i] = ObjectFromValue (v);
+                               margs[i] = o; //Convert.ChangeType (o, 
pis[i].ParameterType);
                        }
 
-                       object rv = mi.Invoke (obj, margs);
+                       for (int i = 0; i < arg_count; i ++) {
+                       }
 
+                       object rv = mi.Invoke (obj, BindingFlags.Default, new 
JSFriendlyMethodBinder(), margs, null);
+
                        if (mi.ReturnType != typeof (void))
                                ValueFromObject (ref return_value, rv);
                }
 
-               static void SetPropertyFromUnmanaged (IntPtr obj_handle, IntPtr 
property_handle, Value value)
+               static void SetPropertyFromUnmanaged (IntPtr obj_handle, IntPtr 
property_handle, ref Value value)
                {
                        object obj = GCHandle.FromIntPtr (obj_handle).Target;
                        PropertyInfo pi = (PropertyInfo)GCHandle.FromIntPtr 
(property_handle).Target;
@@ -132,99 +331,138 @@
                        ValueFromObject (ref value, v);
                }
 
-               static InvokeDelegate invoke = new InvokeDelegate 
(InvokeFromUnmanaged);
-               static SetPropertyDelegate set_prop = new SetPropertyDelegate 
(SetPropertyFromUnmanaged);
-               static GetPropertyDelegate get_prop = new GetPropertyDelegate 
(GetPropertyFromUnmanaged);
+               static void AddEventFromUnmanaged (IntPtr obj_handle, IntPtr 
event_handle)
+               {
+                       EventInfo ei = (EventInfo)GCHandle.FromIntPtr 
(event_handle).Target;
 
-               void Generate ()
+                       Console.WriteLine ("TODO - AddEventFromUnmanaged");
+                       Console.WriteLine (" + {0}", ei.Name);
+                       Console.WriteLine (" + {0}", ei.DeclaringType.FullName);
+                       Console.WriteLine (" + {0}", ei.EventHandlerType);
+               }
+
+               static void RemoveEventFromUnmanaged (IntPtr obj_handle, IntPtr 
event_handle)
                {
-                       bool hasItem = false;
+                       EventInfo ei = (EventInfo)GCHandle.FromIntPtr 
(event_handle).Target;
 
-                       GCHandle obj_handle = GCHandle.Alloc (obj); // XXX leak
+                       Console.WriteLine ("TODO - RemoveEventFromUnmanaged");
+                       Console.WriteLine (" + {0}", ei.Name);
+                       Console.WriteLine (" + {0}", ei.DeclaringType.FullName);
+                       Console.WriteLine (" + {0}", ei.EventHandlerType);
+               }
+       }
 
-                       scriptable_wrapper = 
moonlight_scriptable_object_wrapper_create (plugin_handle, (IntPtr)obj_handle,
-                                                                               
         invoke, set_prop, get_prop);
+       internal class ScriptableObjectGenerator
+       {
+               string name;
+               object obj;
+               Type type;
 
-                       // add properties
+               public ScriptableObjectGenerator (object obj)
+               {
+                       this.obj = obj;
+                       type = obj.GetType ();
+               }
 
+               public void ValidateType (Type t)
+               {
+                       bool hasItem = false;
+
+                       if (t.GetCustomAttributes (typeof 
(ScriptableAttribute), false).Length == 0)
+                               throw new NotSupportedException (
+                                                String.Format ("Class {0} must 
have [ScriptableAttribute] to be used as a scriptable object type", type));
+
                        foreach (PropertyInfo pi in type.GetProperties ()) {
                                if (pi.GetCustomAttributes (typeof 
(ScriptableAttribute), false).Length == 0)
                                        continue;
-                               GenerateProperty (pi);
+
+                               TypeCode tc = Type.GetTypeCode 
(pi.PropertyType);
+                               if (!IsSupportedType (tc))
+                                       throw new NotSupportedException (
+                                                String.Format ("The scriptable 
object type {0} has a property {1} whose type {2} is not supported",
+                                                               type, pi, 
pi.PropertyType));
+                               
                                hasItem = true;
                        }
 
-                       // add events
                        foreach (EventInfo ei in type.GetEvents ()) {
                                if (ei.GetCustomAttributes (typeof 
(ScriptableAttribute), false).Length == 0)
                                        continue;
-                               GenerateEvent (ei);
+
+                               Console.WriteLine ("event handler type = {0}", 
ei.EventHandlerType);
+                               Console.WriteLine ("typeof (EventHandler<>) == 
{0}", typeof (EventHandler<>));
+
+                               if (ei.EventHandlerType != typeof (EventHandler)
+                                   && typeof (EventHandler<>).IsAssignableFrom 
(ei.EventHandlerType)) {
+                                       try {
+                                               ValidateType 
(ei.EventHandlerType);
+                                       }
+                                       catch (Exception e) {
+                                               throw new NotSupportedException 
(
+                                                        String.Format ("The 
scriptable object type {0} has a event {1} whose type {2} is not supported",
+                                                                       type, 
ei, ei.EventHandlerType), e);
+                                       }
+                               }
+
                                hasItem = true;
                        }
 
-                       // add functions
                        foreach (MethodInfo mi in type.GetMethods ()) {
                                if (mi.GetCustomAttributes (typeof 
(ScriptableAttribute), false).Length == 0)
                                        continue;
-                               GenerateMethod (mi);
+
+                               TypeCode rc = Type.GetTypeCode (mi.ReturnType);
+                               if (mi.ReturnType != typeof (void) && 
!IsSupportedType (rc))
+                                       throw new NotSupportedException (
+                                                String.Format ("The scriptable 
object type {0} has a method {1} whose return type {2} is not supported",
+                                                               type, mi, 
mi.ReturnType));
+
+                               ParameterInfo[] ps = mi.GetParameters();
+                               foreach (ParameterInfo p in ps) {
+                                       TypeCode pc = Type.GetTypeCode 
(p.ParameterType);
+                                       if (p.IsOut || !IsSupportedType (pc))
+                                               throw new NotSupportedException 
(
+                                                String.Format ("The scriptable 
object type {0} has an event {1} whose parameter {2} is of not supported type",
+                                                               type, mi, p));
+                               }
+
                                hasItem = true;
                        }
 
                        if (!hasItem)
                                throw new ArgumentException (String.Format 
("The scriptable type {0} does not have scriptable members", type));
-
-                       moonlight_scriptable_object_register (plugin_handle, 
name, scriptable_wrapper);
                }
 
-               void GenerateProperty (PropertyInfo pi)
+               public ScriptableObjectWrapper Generate (bool validate)
                {
-                       TypeCode tc = Type.GetTypeCode (pi.PropertyType);
-                       if (!IsSupportedType (tc))
-                               throw new NotSupportedException (String.Format 
("The scriptable object type {0} has a property {1} whose type {2} is not 
supported", type, pi, pi.PropertyType));
+                       if (validate)
+                               ValidateType (type);
 
-                       GCHandle prop_handle = GCHandle.Alloc (pi); // XXX leak
+                       ScriptableObjectWrapper scriptable = new 
ScriptableObjectWrapper (obj);
 
-                       moonlight_scriptable_object_add_property (plugin_handle,
-                                                                 
scriptable_wrapper,
-                                                                 
(IntPtr)prop_handle,
-                                                                 pi.Name,
-                                                                 tc,
-                                                                 pi.CanRead,
-                                                                 pi.CanWrite);
-               }
+                       // add properties
 
-               void GenerateEvent (EventInfo ei)
-               {
-                       Console.WriteLine ("TODO - events aren't hooked up yet 
for scriptable objects");
-               }
+                       foreach (PropertyInfo pi in type.GetProperties ()) {
+                               if (pi.GetCustomAttributes (typeof 
(ScriptableAttribute), false).Length == 0)
+                                       continue;
+                               scriptable.AddProperty (pi);
+                       }
 
-               void GenerateMethod (MethodInfo mi)
-               {
-                       TypeCode rc = Type.GetTypeCode (mi.ReturnType);
-                       
-                       if (mi.ReturnType != typeof (void) && !IsSupportedType 
(rc))
-                               throw new NotSupportedException (String.Format 
("The scriptable object type {0} has a method {1} whose return type {2} is not 
supported", type, mi, mi.ReturnType));
+                       // add events
+                       foreach (EventInfo ei in type.GetEvents ()) {
+                               if (ei.GetCustomAttributes (typeof 
(ScriptableAttribute), false).Length == 0)
+                                       continue;
+                               scriptable.AddEvent (ei);
+                       }
 
-                       ParameterInfo[] ps = mi.GetParameters();
-                       TypeCode[] tcs = new TypeCode [ps.Length];
+                       // add functions
+                       foreach (MethodInfo mi in type.GetMethods ()) {
+                               if (mi.GetCustomAttributes (typeof 
(ScriptableAttribute), false).Length == 0)
+                                       continue;
+                               scriptable.AddMethod (mi);
+                       }
 
-                               foreach (ParameterInfo p in ps) {
-                                       TypeCode pc = Type.GetTypeCode 
(p.ParameterType);
-                                       if (p.IsOut || !IsSupportedType (pc))
-                                               throw new NotSupportedException 
(String.Format ("The scriptable object type {0} has an event {1} whose 
parameter {2} is of not supported type", type, mi, p));
-
-                                       tcs[p.Position] = pc;
-                               }
-
-                               GCHandle method_handle = GCHandle.Alloc (mi); 
// XXX leak
-
-                               moonlight_scriptable_object_add_method 
(plugin_handle,
-                                                                       
scriptable_wrapper,
-                                                                       
(IntPtr)method_handle,
-                                                                       mi.Name,
-                                                                       
Type.GetTypeCode (mi.ReturnType),
-                                                                       tcs,
-                                                                       
tcs.Length);
+                       return scriptable;
                }
 
                bool IsSupportedType (TypeCode tc)
@@ -251,33 +489,5 @@
                        }
                        return false;
                }
-
-               [DllImport ("moonplugin")]
-               static extern IntPtr moonlight_scriptable_object_wrapper_create 
(IntPtr plugin_handle, IntPtr obj_handle,
-                                                                               
 InvokeDelegate invoke,
-                                                                               
 SetPropertyDelegate set_prop,
-                                                                               
 GetPropertyDelegate get_prop);
-
-               [DllImport ("moonplugin")]
-               static extern void moonlight_scriptable_object_add_property 
(IntPtr plugin_handle,
-                                                                            
IntPtr wrapper,
-                                                                            
IntPtr property_handle,
-                                                                            
string property_name,
-                                                                            
TypeCode property_type,
-                                                                            
bool readable,
-                                                                            
bool writable);
-               [DllImport ("moonplugin")]
-               static extern void moonlight_scriptable_object_add_method 
(IntPtr plugin_handle,
-                                                                          
IntPtr wrapper,
-                                                                          
IntPtr method_handle,
-                                                                          
string method_name,
-                                                                          
TypeCode method_return_type,
-                                                                          
TypeCode[] method_parameter_types,
-                                                                          int 
parameter_count);
-
-               [DllImport ("moonplugin")]
-               static extern void moonlight_scriptable_object_register (IntPtr 
plugin_handle,
-                                                                        string 
name,
-                                                                        IntPtr 
wrapper);
        }
 }

Modified: trunk/olive/class/System.Silverlight/System.Windows/WebApplication.cs
===================================================================
--- trunk/olive/class/System.Silverlight/System.Windows/WebApplication.cs       
2007-07-21 08:25:59 UTC (rev 82408)
+++ trunk/olive/class/System.Silverlight/System.Windows/WebApplication.cs       
2007-07-21 08:28:19 UTC (rev 82409)
@@ -46,12 +46,11 @@
                        if (scriptKey.Length == 0)
                                throw new ArgumentException ("scriptKey");
 
-                       object [] atts = instance.GetType 
().GetCustomAttributes (typeof (ScriptableAttribute), false);
-                       // It neither supports ScriptableObject nor its derived 
types such as HtmlElement.
-                       if (atts.Length == 0)
-                               throw new NotSupportedException ("The argument 
object type does not have a ScriptableAttribute");
+                       ScriptableObjectGenerator gen = new 
ScriptableObjectGenerator (instance);
 
-                       ScriptableObjectGenerator.Generate (plugin_handle, 
scriptKey, instance);
+                       ScriptableObjectWrapper wrapper = gen.Generate (true);
+
+                       ScriptableNativeMethods.register (plugin_handle, 
scriptKey, wrapper.UnmanagedWrapper);
                }
 
                // it is non-null on silverlight apps, and null on console apps

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to