private IEnumerable <PropertyItem> CollectProperties(object[] components) { if (components == null || components.Length == 0) { throw new ArgumentNullException(nameof(components)); } // TODO: PropertyItem is to be wired with PropertyData rather than pure PropertyDescriptor in the next version! var descriptors = (components.Length == 1) ? MetadataRepository.GetProperties(components[0]).Select(prop => prop.Descriptor) : ObjectServices.GetMergedProperties(components); IList <PropertyItem> propertyCollection = new List <PropertyItem>(); foreach (var propertyDescriptor in descriptors) { var item = CreatePropertyItem(propertyDescriptor); if (item != null) { propertyCollection.Add(item); } } return(propertyCollection); }
/// <summary> /// Gets the editor. /// </summary> /// <param name="propertyItem">The property item.</param> /// <returns>Editor for Property</returns> public Editor GetEditor(PropertyItem propertyItem) { if (propertyItem == null) { throw new ArgumentNullException("propertyItem"); } Editor editor; if (propertyItem.Attributes != null) { editor = GetPropertyEditorByAttributes(propertyItem.Attributes); if (editor != null) { return(editor); } } if (propertyItem.Component != null && !string.IsNullOrEmpty(propertyItem.Name)) { object declaringObject = ObjectServices.GetUnwrappedObject(propertyItem.Owner.SelectedObject); editor = FindPropertyEditor(declaringObject.GetType(), propertyItem.Name); if (editor != null) { return(editor); } } if (propertyItem.PropertyValue.HasSubProperties) { return(new TypeEditor(propertyItem.PropertyType, EditorKeys.ComplexPropertyEditorKey)); } bool hasType = propertyItem.PropertyType != null; if (hasType) { editor = FindTypeEditor(propertyItem.PropertyType); if (editor != null) { return(editor); } } if (hasType) { foreach (var cachedEditor in Cache) { if (cachedEditor.Key.IsAssignableFrom(propertyItem.PropertyType)) { return(cachedEditor.Value); } } return(new TypeEditor(propertyItem.PropertyType, EditorKeys.DefaultEditorKey)); } return(null); }
public void ShouldReturnStringConverterForSpecialProperties() { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(typeof(ContentControl))["Content"]; Assert.AreEqual <TypeConverter>(ObjectServices.DefaultStringConverter, ObjectServices.GetPropertyConverter(descriptor)); descriptor = TypeDescriptor.GetProperties(typeof(HeaderedContentControl))["Header"]; Assert.AreEqual <TypeConverter>(ObjectServices.DefaultStringConverter, ObjectServices.GetPropertyConverter(descriptor)); descriptor = TypeDescriptor.GetProperties(typeof(FrameworkElement))["ToolTip"]; Assert.AreEqual <TypeConverter>(ObjectServices.DefaultStringConverter, ObjectServices.GetPropertyConverter(descriptor)); descriptor = TypeDescriptor.GetProperties(typeof(FrameworkElement))["Tag"]; Assert.AreEqual <TypeConverter>(ObjectServices.DefaultStringConverter, ObjectServices.GetPropertyConverter(descriptor)); }
private void ActivateService(ObjectServices service, UserObjectsMD userObject) { switch (service) { case ObjectServices.Find: userObject.CanFind = BoYesNoEnum.tYES; break; case ObjectServices.Delete: userObject.CanDelete = BoYesNoEnum.tYES; break; case ObjectServices.Cancel: userObject.CanCancel = BoYesNoEnum.tYES; break; case ObjectServices.Close: userObject.CanClose = BoYesNoEnum.tYES; break; case ObjectServices.Log: userObject.CanLog = BoYesNoEnum.tYES; userObject.LogTableName = $"{userObject.TableName}_LOG"; break; case ObjectServices.ManageSeries: userObject.ManageSeries = BoYesNoEnum.tYES; break; case ObjectServices.YearTransfer: userObject.CanYearTransfer = BoYesNoEnum.tYES; break; case ObjectServices.Default: userObject.CanFind = BoYesNoEnum.tYES; userObject.CanDelete = BoYesNoEnum.tYES; break; default: throw new ArgumentOutOfRangeException(nameof(service), service, "Unknown service"); } }
/// <summary> /// Gets the editor. /// </summary> /// <param name="categoryItem">The category item.</param> /// <returns>Editor for Category</returns> public Editor GetEditor(CategoryItem categoryItem) { if (categoryItem == null) { throw new ArgumentNullException("categoryItem"); } if (categoryItem.Owner == null) { return(null); } object declaringObject = ObjectServices.GetUnwrappedObject(categoryItem.Owner.SelectedObject); if (declaringObject == null) { return(null); } Type declaringType = declaringObject.GetType(); Editor editor = FindCategoryEditor(declaringType, categoryItem.Name); if (editor != null) { return(editor); } editor = GetCategoryEditorByAttributes(declaringType, categoryItem.Name); if (editor != null) { return(editor); } return(new CategoryEditor(declaringType, categoryItem.Name, EditorKeys.DefaultCategoryEditorKey)); }
public void ShouldReturnPropertyConverter() { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(typeof(TextBox))["Text"]; Assert.AreEqual <TypeConverter>(TypeDescriptor.GetConverter(typeof(string)), ObjectServices.GetPropertyConverter(descriptor)); }
public void ShoudlDecorateFontWeightConverter() { PropertyDescriptor descriptor = TypeDescriptor.GetProperties(typeof(Control))["FontWeight"]; Assert.AreEqual <TypeConverter>(ObjectServices.DefaultFontWeightConverterDecorator, ObjectServices.GetPropertyConverter(descriptor)); }
public void ShouldFailForNullPropertyDescriptor() { ObjectServices.GetPropertyConverter(null); }
public void ShouldReturnInvariantCulture() { Assert.AreEqual <CultureInfo>(CultureInfo.InvariantCulture, ObjectServices.GetSerializationCulture(typeof(Rect))); Assert.AreEqual <CultureInfo>(CultureInfo.InvariantCulture, ObjectServices.GetSerializationCulture(typeof(Geometry))); }
public void ShouldReturnCurrentCultureForNullType() { Assert.AreEqual <CultureInfo>(CultureInfo.CurrentCulture, ObjectServices.GetSerializationCulture(null)); }
public void ShouldReturnCurrentCultureForCultureInvariantTypes() { Assert.AreEqual <CultureInfo>(CultureInfo.CurrentCulture, ObjectServices.GetSerializationCulture(typeof(string))); Assert.AreEqual <CultureInfo>(CultureInfo.CurrentCulture, ObjectServices.GetSerializationCulture(typeof(int))); }
/// <summary> /// Gets the serialization culture. /// </summary> /// <returns>Culture to serialize value.</returns> protected virtual CultureInfo GetSerializationCulture() { return(ObjectServices.GetSerializationCulture(_propertyItemValue.CollectionItemType)); }
/// <summary> /// Gets the serialization culture. /// </summary> /// <returns>Culture to serialize value.</returns> protected virtual CultureInfo GetSerializationCulture() { return(ObjectServices.GetSerializationCulture(_parentProperty.PropertyType)); }
/// <summary> /// Gets the editor. /// </summary> /// <param name="propertyItem">The property item.</param> /// <returns>Editor for Property</returns> public Editor GetEditor(PropertyItem propertyItem) { if (propertyItem == null) { throw new ArgumentNullException(nameof(propertyItem)); } Editor editor; //first check custom editors if (propertyItem.Component != null && this.Count > 0) { Type propType = propertyItem.Component.GetType(); Editor customEditor = this.OfType <PropertyEditor>().Where (x => x.PropertyName == propertyItem.Name && x.DeclaringType.GetElementType() == propType.GetElementType()) .FirstOrDefault(); if (customEditor != null) { return(customEditor); } } if (propertyItem.Attributes != null) { editor = GetPropertyEditorByAttributes(propertyItem.Attributes); if (editor != null) { return(editor); } } if (propertyItem.Component != null && !string.IsNullOrEmpty(propertyItem.Name)) { object declaringObject = ObjectServices.GetUnwrappedObject(propertyItem.Owner.SelectedObject); editor = FindPropertyEditor(declaringObject.GetType(), propertyItem.Name); if (editor != null) { return(editor); } } if (propertyItem.PropertyValue.HasSubProperties) { return(new TypeEditor(propertyItem.PropertyType, EditorKeys.ComplexPropertyEditorKey)); } bool hasType = propertyItem.PropertyType != null; if (hasType) { editor = FindTypeEditor(propertyItem.PropertyType); if (editor != null) { return(editor); } } if (hasType) { foreach (var cachedEditor in Cache) { if (cachedEditor.Key.IsAssignableFrom(propertyItem.PropertyType)) { return(cachedEditor.Value); } } return(new TypeEditor(propertyItem.PropertyType, EditorKeys.DefaultEditorKey)); } return(null); }