예제 #1
0
        //Devalize
        public static object Val2Host(VAL val, object host)
        {
            FieldInfo[] fields = host.GetType().GetFields();
            foreach (FieldInfo fieldInfo in fields)
            {
                try
                {
                    VAL p = val[fieldInfo.Name];

                    if (p.Defined)
                    {
                        if (fieldInfo.FieldType == typeof(VAL))
                        {
                            fieldInfo.SetValue(host, p);
                        }
                        else
                        {
                            SetValue(host, fieldInfo.FieldType, fieldInfo.Name, p);
                        }
                    }
                }
                catch (ArgumentException)
                {
                }
                catch (Exception)
                {
                }
            }

            PropertyInfo[] properties = host.GetType().GetProperties();
            foreach (PropertyInfo propertyInfo in properties)
            {
                try
                {
                    VAL p = val[propertyInfo.Name];
                    if (p.Defined)
                    {
                        if (propertyInfo.CanWrite)
                        {
                            if (propertyInfo.PropertyType == typeof(VAL))
                            {
                                propertyInfo.SetValue(host, p, null);
                            }
                            else
                            {
                                SetValue(host, propertyInfo.PropertyType, propertyInfo.Name, p);
                            }
                        }
                        else   //CanRead
                        {
                            object prop = propertyInfo.GetValue(host, null);
                            if (prop is IList)
                            {
                                IList  array = (IList)prop;
                                int    count = array.Count;
                                object phost = p.HostValue;
                                if (phost is ICollection)
                                {
                                    ICollection collection = (ICollection)phost;
                                    int         i          = 0;
                                    foreach (object x in collection)
                                    {
                                        if (i < count)
                                        {
                                            array[i] = x;
                                        }
                                        else
                                        {
                                            array.Add(x);
                                        }

                                        i++;
                                    }
                                }
                            }
                            else
                            {
                                Val2Host(p, propertyInfo.GetValue(host, null));
                            }
                        }
                    }
                }
                catch (ArgumentException)
                {
                }
            }

            EventInfo[] events = host.GetType().GetEvents();
            foreach (EventInfo eventInfo in events)
            {
                try
                {
                    VAL p = val[eventInfo.Name];
                    if (p.Defined)
                    {
                        if (p.ty == VALTYPE.funccon)       //event handler
                        {
                            HostEvent hostEvent = new HostEvent(eventInfo, p);
                            VAL       d         = hostEvent.AddDelegateEventHandler();
                            eventInfo.AddEventHandler(host, d.value as Delegate);
                        }
                    }
                }
                catch (ArgumentException)
                {
                }
            }

            return(host);
        }
예제 #2
0
 /// <summary>
 /// Clear event handlers
 /// </summary>
 public void ClearEventHandler()
 {
     HostEvent.ClearEventHandler(context.DataSegment);
 }