public object this[string name] { get { return(this.fields[name]); } set { if (value != null && !(value is DBNull)) { MapCore mapCore = this.GetMapCore(); if (mapCore != null) { Field field = (Field)mapCore.GroupFields.GetByName(name); if (field == null) { throw new ArgumentException(SR.ExceptionFieldNameDoesNotExist(name)); } if (!field.Type.IsInstanceOfType(value) && field.Type != Field.ConvertToSupportedType(value.GetType())) { throw new ArgumentException(SR.ExceptionFieldMustBeOfType(name, field.Type.ToString())); } field.SetValue(Field.ConvertToSupportedValue(value), this.fields); mapCore.InvalidateRules(); mapCore.InvalidateDataBinding(); } else { this.fields[name] = Field.ConvertToSupportedValue(value); } this.InvalidateViewport(); } } }
public static object ConvertToSupportedValue(object value) { Type type = value.GetType(); Type type2 = Field.ConvertToSupportedType(type); if (type == type2) { return(value); } return(Convert.ChangeType(value, type2, CultureInfo.InvariantCulture)); }
public static void InitDesignDataTable(object dataSource, string dataMember, DataTable designDataTable) { if (dataSource != null) { designDataTable.Clear(); designDataTable.Columns.Clear(); try { ArrayList dataSourceDataFields = DataBindingHelper.GetDataSourceDataFields(dataSource, dataMember, string.Empty); if (dataSourceDataFields.Count != 0) { foreach (DataFieldDescriptor item in dataSourceDataFields) { designDataTable.Columns.Add(item.Name, Field.ConvertToSupportedType(item.Type)); } } } catch (Exception) { } } }