示例#1
0
        internal void CommitValue(object record, string propName, object value)
        {
#if UWP
            PropertyInfoCollection descriptor = new PropertyInfoCollection(record.GetType());
#else
            PropertyDescriptorCollection descriptor = TypeDescriptor.GetProperties(record.GetType());
#endif
            var    propertyinfo   = descriptor.GetPropertyDescriptor(propName);
            object convertedValue = null;
            if (propertyinfo == null)
            {
                if (View.IsDynamicBound)
                {
                    var type = (value == null) ? null : value.GetType();
                    convertedValue = ValueConvert.ChangeType(value, type, null);
                    if (convertedValue != null || (NullableHelperInternal.IsNullableType(type) && convertedValue == null))
                    {
                        SetValue(record, propName, convertedValue);
                    }
                }
                return;
            }

            convertedValue = ValueConvert.ChangeType(value, propertyinfo.PropertyType, null);
            if (value != null || (NullableHelperInternal.IsNullableType(propertyinfo.PropertyType) && value == null))
            {
                SetValue(record, propName, convertedValue);
            }
        }
        /// <summary>
        /// To commits the value for the specified row data, column and corresponding changed value.
        /// </summary>
        protected virtual void CommitValue(object rowData, TreeGridColumn column, object changedValue)
        {
            Type type     = null;
            var  provider = this.TreeGrid.View.GetPropertyAccessProvider();

            type = GetPropertyType(rowData, column);
            ////While giving dummy mappingname, its type becomes null. so we should check the type as null or not.
            if (type == null)
            {
                return;
            }
            var canconvert = CanConvertToType(changedValue, ref type);

            if (!canconvert && string.IsNullOrEmpty(changedValue.ToString()))
            {
                return;
            }
            if (!(canconvert || type == typeof(string) || type == typeof(object)))
            {
                return;
            }

            if (column.IsDropDown)
            {
                CommitValueDropDownColumn(column, ref changedValue, type);
            }
            else if (type == typeof(DateTimeOffset))
            {
                DateTimeOffset value;
                DateTimeOffset.TryParse(changedValue.ToString(), out value);
                provider.SetValue(rowData, column.MappingName, value);
                return;
            }
            var pasteValue = ValueConvert.ChangeType(changedValue, type, null);

            provider.SetValue(rowData, column.MappingName, pasteValue);
        }