///////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Creates an <see cref="ICategoryModel"/> for the specified category name. /// </summary> /// <param name="name">The category name.</param> /// <param name="request">An <see cref="IDataFactoryRequest"/> that contains data about the request.</param> /// <returns>The <see cref="ICategoryModel"/> that was created.</returns> protected override ICategoryModel CreateCategoryModel(string name, IDataFactoryRequest request) { var categoryModel = base.CreateCategoryModel(name, request); if (name == "B") { categoryModel.SortComparer = new NumericValueComparer(); } return(categoryModel); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Returns the <see cref="IPropertyModel"/> collection for the specified data object. /// </summary> /// <param name="dataObject">The single object to examine.</param> /// <param name="request">An <see cref="IDataFactoryRequest"/> that contains data about the request.</param> /// <returns>A collection of <see cref="IPropertyModel"/> objects, if the specified data object has any properties.</returns> protected override IList <IPropertyModel> GetPropertyModels(object dataObject, IDataFactoryRequest request) { var dictionary = dataObject as Dictionary <TKey, TValue>; if (dictionary != null) { var propertyModels = new List <IPropertyModel>(dictionary.Count); foreach (var entry in dictionary) { propertyModels.Add(new DictionaryEntryPropertyModel <TKey, TValue>(dictionary, entry.Key)); } return(propertyModels); } return(null); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Creates an <see cref="IPropertyModel"/> for the specified mutable data object. /// </summary> /// <param name="target">The target object that owns the property.</param> /// <param name="propertyDescriptor">The <see cref="PropertyDescriptor"/> for the property be accessed on the <paramref name="target"/>.</param> /// <param name="request">An <see cref="IDataFactoryRequest"/> that contains data about the request.</param> /// <returns>The <see cref="IPropertyModel"/> that was created.</returns> protected override IPropertyModel CreatePropertyModel(object target, PropertyDescriptor propertyDescriptor, IDataFactoryRequest request) { return(new CustomPropertyModel(target, propertyDescriptor)); }
///////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Returns the <see cref="IPropertyModel"/> collection for the specified data object. /// </summary> /// <param name="dataObject">The single object to examine.</param> /// <param name="request">An <see cref="IDataFactoryRequest"/> that contains data about the request.</param> /// <returns>A collection of <see cref="IPropertyModel"/> objects, if the specified data object has any properties.</returns> protected override IList <IPropertyModel> GetPropertyModels(object dataObject, IDataFactoryRequest request) { var customer = dataObject as CustomerViewModel; if (customer != null) { // Create a list of property model results var propertyModels = new List <IPropertyModel>(); // Get the property descriptors var customerPropertyDescriptors = TypeDescriptor.GetProperties(customer); var phoneNumbersPropertyDescriptors = TypeDescriptor.GetProperties(customer.PhoneNumbers); // Add customer name, but don't allow editing of it, even though it's normally not read-only var propertyModel = new CustomPropertyModel(customer, customerPropertyDescriptors["CustomerName"]); propertyModel.CustomIsValueReadOnly = true; propertyModels.Add(propertyModel); // Add country name with a custom value template propertyModel = new CustomPropertyModel(customer, customerPropertyDescriptors["CountryName"]); propertyModel.CustomValueTemplateKey = "CountryNameValueTemplate"; propertyModels.Add(propertyModel); // Add voice phone number (routed from child object) propertyModels.Add(this.CreatePropertyModel(customer.PhoneNumbers, phoneNumbersPropertyDescriptors["Voice"], request)); // Add fax phone number (routed from child object) propertyModels.Add(this.CreatePropertyModel(customer.PhoneNumbers, phoneNumbersPropertyDescriptors["Fax"], request)); // Add referred by, which uses some custom standard values supplied on the object itself propertyModel = new CustomPropertyModel(customer, customerPropertyDescriptors["ReferredBy"]); propertyModel.CustomStandardValues = customer.AvailableReferrals; propertyModel.StandardValuesDisplayMemberPath = "Name"; propertyModels.Add(propertyModel); return(propertyModels); } else { // Fall back to using the base method's results for nested objects return(base.GetPropertyModels(dataObject, request)); } }
///////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Creates an <see cref="IPropertyModel"/> for the specified mutable data object. /// </summary> /// <param name="target">The target object that owns the property.</param> /// <param name="propertyDescriptor">The <see cref="PropertyDescriptor"/> for the property be accessed on the <paramref name="target"/>.</param> /// <param name="request">An <see cref="IDataFactoryRequest"/> that contains data about the request.</param> /// <returns>The <see cref="IPropertyModel"/> that was created.</returns> protected override IPropertyModel CreatePropertyModel(object target, PropertyDescriptor propertyDescriptor, IDataFactoryRequest request) { // Ensure the Address property is expanded var propertyModel = base.CreatePropertyModel(target, propertyDescriptor, request); if ((propertyModel != null) && (propertyModel.Name == "Address")) { propertyModel.IsExpanded = true; } return(propertyModel); }