Esempio n. 1
0
        private static void CopyProperty(Object dataItem, ConnectionAttribute a, Control c)
        {
            PropertyInfo piSource = null;
            PropertyInfo piTarget = null;
            String       prop     = a.DataItemProperty;

            try
            {
                piSource = dataItem.GetType().GetProperty(prop);
            }
            catch (Exception ex)
            {
                throw new InitializerException(
                          new StringBuilder("Source property '").
                          Append(prop).
                          Append("' not found").ToString(),
                          ex);
            }

            if (piSource == null)
            {
                throw new InitializerException(
                          new StringBuilder("Source property '").
                          Append(prop).
                          Append("' not found").ToString());
            }

            prop = a.ControlProperty;
            try
            {
                piTarget = c.GetType().GetProperty(prop);
            }
            catch (Exception ex)
            {
                throw new InitializerException(
                          new StringBuilder("Target property '").
                          Append(prop).
                          Append("' not found").ToString(),
                          ex);
            }

            if (piTarget == null)
            {
                throw new InitializerException(
                          new StringBuilder("Target property '").
                          Append(prop).
                          Append("' not found").ToString());
            }

            Object val = piSource.GetGetMethod().Invoke(dataItem, new Object[] { });

            Type            vct = a.ValueConverter;
            ConstructorInfo ci  = vct.GetConstructor(new Type[] { });
            IValueConverter vc  = (IValueConverter)ci.Invoke(new Object[] { });

            val = vc.ConvertForControl(val);

            piTarget.GetSetMethod().Invoke(c, new Object[] { val });
        }