コード例 #1
0
        public override object GetValue(object component)
        {
            CheckComponentType(component);
            if (this.ComponentType == component.GetType())
            {
                return(PropInfo.IsNull() ? null : PropInfo.GetValue(component, null));
            }

            PropertyInfo[] propInfos = component.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            //This code is copied from http://www.sql.ru/forum/actualthread.aspx?tid=579972
            // and i have no idea what the following code is trying to achieve.
            //It looks like it might be trying to deal with the prop info being
            // on a customer e.g. when a PropInfo for CustomerName on Customer when the component is Order.
            foreach (PropertyInfo mypropinfo in propInfos)
            {
                object obj = mypropinfo.GetValue(component, null);

                PropertyInfo[] nestedpropsInfo = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

                foreach (PropertyInfo mynestedpropinfo in nestedpropsInfo)
                {
                    if (PropInfo.Name == mynestedpropinfo.Name)
                    {
                        return(mynestedpropinfo.GetValue(obj, null));
                    }
                }
            }
            return(null);
        }
コード例 #2
0
 public override void SetValue(object component, object value)
 {
     if (PropInfo.IsNull())
     {
         return;
     }
     CheckComponentType(component);
     if (PropInfo.DeclaringType == component.GetType())
     {
         PropInfo.SetValue(component, value, null);
     }
     else
     {
         PropertyInfo[] propsInfo = component.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
         foreach (PropertyInfo mypropinfo in propsInfo)
         {
             object         obj             = mypropinfo.GetValue(component, null);
             PropertyInfo[] nestedpropsInfo = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
             foreach (PropertyInfo mynestedpropinfo in nestedpropsInfo)
             {
                 if (PropInfo.Name == mynestedpropinfo.Name)
                 {
                     mynestedpropinfo.SetValue(obj, value, null);
                 }
             }
         }
     }
 }