private void EnsureInit() { if (_column != null) return; // make sure we have a DataField if (String.IsNullOrEmpty(DataField)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_MissingDataField, ID)); } MetaTable table = null; if (!String.IsNullOrEmpty(ContextTypeName) || !String.IsNullOrEmpty(TableName)) { // make sure both ContextTypeName and TableName are specified together if (String.IsNullOrEmpty(ContextTypeName)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_MissingContextTypeName, ID)); } if (String.IsNullOrEmpty(TableName)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_MissingTableName, ID)); } Type contextType = GetContextType(ContextTypeName); MetaModel model = null; try { model = MetaModel.GetModel(contextType); } catch (InvalidOperationException e) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_UnknownContextType, ID, contextType.FullName), e); } string tableName = TableName; try { table = model.GetTable(tableName); } catch (ArgumentException e) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_InvalidTableName, ID, tableName), e); } } else { // get context information from request context table = DynamicDataRouteHandler.GetRequestMetaTable(HttpContext.Current); if (table == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_CantInferInformationFromRequestUrl, ID)); } } try { _column = table.GetColumn(DataField); } catch (InvalidOperationException e) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_InvalidDataField, ID, DataField), e); } // create appropriate filter implementation based on column type if (_column is MetaForeignKeyColumn) { _filterDelegate = new ForeignKeyFilterDelegate(this); } else if (_column.ColumnType == typeof(bool) && !_column.IsCustomProperty) { _filterDelegate = new BooleanPropertyFilterDelegate(this); } else { _filterDelegate = new DefaultPropertyFilterDelegate(this); } }
private void EnsureInit() { if (_column != null) { return; } // make sure we have a DataField if (String.IsNullOrEmpty(DataField)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_MissingDataField, ID)); } MetaTable table = null; if (!String.IsNullOrEmpty(ContextTypeName) || !String.IsNullOrEmpty(TableName)) { // make sure both ContextTypeName and TableName are specified together if (String.IsNullOrEmpty(ContextTypeName)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_MissingContextTypeName, ID)); } if (String.IsNullOrEmpty(TableName)) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_MissingTableName, ID)); } Type contextType = GetContextType(ContextTypeName); MetaModel model = null; try { model = MetaModel.GetModel(contextType); } catch (InvalidOperationException e) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_UnknownContextType, ID, contextType.FullName), e); } string tableName = TableName; try { table = model.GetTable(tableName); } catch (ArgumentException e) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_InvalidTableName, ID, tableName), e); } } else { // get context information from request context table = DynamicDataRouteHandler.GetRequestMetaTable(HttpContext.Current); if (table == null) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_CantInferInformationFromRequestUrl, ID)); } } try { _column = table.GetColumn(DataField); } catch (InvalidOperationException e) { throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, DynamicDataResources.FilterUserControlBase_InvalidDataField, ID, DataField), e); } // create appropriate filter implementation based on column type if (_column is MetaForeignKeyColumn) { _filterDelegate = new ForeignKeyFilterDelegate(this); } else if (_column.ColumnType == typeof(bool) && !_column.IsCustomProperty) { _filterDelegate = new BooleanPropertyFilterDelegate(this); } else { _filterDelegate = new DefaultPropertyFilterDelegate(this); } }