public void ShouldClearValue() { BusinessObject component = new BusinessObject() { Name = "TestName" }; PropertyItem property = new PropertyItem(new PropertyGrid(), component, BusinessObject.ExtractProperty("Name")); Assert.AreEqual<string>("TestName", property.GetValue().ToString()); property.ClearValue(); Assert.AreEqual<string>("DefaultName", property.GetValue().ToString()); }
public void ShouldClearValue() { BusinessObject component = new BusinessObject() { Name = "TestName" }; PropertyItem property = new PropertyItem(new PropertyGrid(), component, BusinessObject.ExtractProperty("Name")); Assert.AreEqual <string>("TestName", property.GetValue().ToString()); property.ClearValue(); Assert.AreEqual <string>("DefaultName", property.GetValue().ToString()); }
private void __AddPropertyValue(int id, float addValue, float minValue) { if (id < 0 || id >= (int)PROPERTY_DEFINE.MAX_PROPERTY_NUMBER) { return; } PropertyItem item = mPropertys[id]; if (addValue < 0 && item.GetValue() + addValue < minValue) { addValue = minValue - item.GetValue(); } item.addValue += addValue; }
/// <summary> /// Initializes a new instance of the <see cref="PropertyItemValue"/> class. /// </summary> /// <param name="property">The property.</param> public PropertyItemValue(PropertyItem property) { if (property == null) throw new ArgumentNullException("property"); this._property = property; _hasSubProperties = property.Converter.GetPropertiesSupported(); if (_hasSubProperties) { object value = property.GetValue(); PropertyDescriptorCollection descriptors = property.Converter.GetProperties(value); foreach (PropertyDescriptor d in descriptors) { _subProperties.Add(new PropertyItem(property.Owner, value, d)); // TODO: Move to PropertyData as a public property NotifyParentPropertyAttribute notifyParent = d.Attributes[KnownTypes.Attributes.NotifyParentPropertyAttribute] as NotifyParentPropertyAttribute; if (notifyParent != null && notifyParent.NotifyParent) { d.AddValueChanged(value, NotifySubPropertyChanged); } } } this._property.PropertyChanged += new PropertyChangedEventHandler(ParentPropertyChanged); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyItemValue"/> class. /// </summary> /// <param name="property">The property.</param> public PropertyItemValue(PropertyItem property) { if (property == null) { throw new ArgumentNullException("property"); } ParentProperty = property; HasSubProperties = property.Converter.GetPropertiesSupported(); if (HasSubProperties) { object value = property.GetValue(); PropertyDescriptorCollection descriptors = property.Converter.GetProperties(value); foreach (PropertyDescriptor d in descriptors) { SubProperties.Add(new PropertyItem(property.Owner, value, d)); // TODO: Move to PropertyData as a public property NotifyParentPropertyAttribute notifyParent = d.Attributes[KnownTypes.Attributes.NotifyParentPropertyAttribute] as NotifyParentPropertyAttribute; if (notifyParent != null && notifyParent.NotifyParent) { d.AddValueChanged(value, NotifySubPropertyChanged); } } } this.ParentProperty.PropertyChanged += ParentPropertyChanged; }
/// <summary> /// Initializes a new instance of the <see cref="PropertyItemValue" /> class. /// </summary> /// <param name="property">The property.</param> public PropertyItemValue(PropertyItem property) { if (property == null) throw new ArgumentNullException("property"); _property = property; _hasSubProperties = property.Converter.GetPropertiesSupported(); if (_hasSubProperties) { var value = property.GetValue(); var descriptors = property.Converter.GetProperties(value); foreach (PropertyDescriptor d in descriptors) { _subProperties.Add(new PropertyItem(property.Owner, value, d)); // TODO: Move to PropertyData as a public property var notifyParent = d.Attributes[KnownTypes.Attributes.NotifyParentPropertyAttribute] as NotifyParentPropertyAttribute; if (notifyParent != null && notifyParent.NotifyParent) { d.AddValueChanged(value, NotifySubPropertyChanged); } } } if (property.IsCollection) { LoadCollectionValues(); } _property.PropertyChanged += ParentPropertyChanged; }
private float __GetPropertyValue(int id) { if (id < 0 || id >= (int)PROPERTY_DEFINE.MAX_PROPERTY_NUMBER) { return(0); } PropertyItem item = mPropertys[id]; //PropertyItem item = mPropertys[id] as PropertyItem; return(item.GetValue()); }
/// <summary> /// Initializes a new instance of the <see cref="PropertyItemValue"/> class. /// </summary> /// <param name="property">The property.</param> public PropertyItemValue(PropertyItem property) { if (property == null) throw new ArgumentNullException("property"); this.property = property; #region IDataErrorInfo Validation attributes loading and property value getters // dmh - use property.Attributes instead of property.UnwrappedComponent.GetType().GetProperties() which can be empty // - removed getters. the actual value was unused validators = new Dictionary<string, ValidationAttribute[]> { { property.Name, property.Attributes.OfType<ValidationAttribute>().ToArray() } }; #endregion hasSubProperties = property.Converter.GetPropertiesSupported(); if (hasSubProperties) { object value = property.GetValue(); if (value != null) { PropertyDescriptorCollection descriptors = property.Converter.GetProperties(value); if (descriptors != null) foreach (PropertyDescriptor d in descriptors) { subProperties.Add(new PropertyItem(property.Owner, value, d)); // TODO: Move to PropertyData as a public property NotifyParentPropertyAttribute notifyParent = d.Attributes[KnownTypes.Attributes.NotifyParentPropertyAttribute] as NotifyParentPropertyAttribute; if (notifyParent != null && notifyParent.NotifyParent) { d.AddValueChanged(value, NotifySubPropertyChanged); } } } } this.property.PropertyChanged += ParentPropertyChanged; }
/// <summary> /// Initializes a new instance of the <see cref="PropertyItemValue"/> class. /// </summary> /// <param name="property">The property.</param> public PropertyItemValue(PropertyItem property) { if (property == null) throw new ArgumentNullException("property"); this._property = property; #region IDataErrorInfo Validation attributes loading and property value getters this._validators = this._property.UnwrappedComponent.GetType().GetProperties(). Where(componentProperties => componentProperties.GetCustomAttributes(typeof(ValidationAttribute), true).Length > 0). ToDictionary(componentProperties => componentProperties.Name, componentProperties => (ValidationAttribute[])componentProperties.GetCustomAttributes(typeof(ValidationAttribute), true)); this._getters = this._property.UnwrappedComponent.GetType().GetProperties(). Where(componentProperties => componentProperties.GetCustomAttributes(typeof(ValidationAttribute), true).Length > 0). ToDictionary(componentProperties => componentProperties.Name, componentProperties => new Func<object, object>(propertyWrapper => componentProperties.GetValue(propertyWrapper, null))); #endregion _hasSubProperties = property.Converter.GetPropertiesSupported(); if (_hasSubProperties) { object value = property.GetValue(); PropertyDescriptorCollection descriptors = property.Converter.GetProperties(value); foreach (PropertyDescriptor d in descriptors) { _subProperties.Add(new PropertyItem(property.Owner, value, d)); // TODO: Move to PropertyData as a public property NotifyParentPropertyAttribute notifyParent = d.Attributes[KnownTypes.Attributes.NotifyParentPropertyAttribute] as NotifyParentPropertyAttribute; if (notifyParent != null && notifyParent.NotifyParent) { d.AddValueChanged(value, NotifySubPropertyChanged); } } } this._property.PropertyChanged += new PropertyChangedEventHandler(ParentPropertyChanged); }
public CollectionItems(PropertyItem propertyItem) { _propertyItem = propertyItem; _values = (IList) _propertyItem.GetValue(); }
public CollectionItems(PropertyItem propertyItem) { _propertyItem = propertyItem; _values = (IList)_propertyItem.GetValue(); }
private static List <ResourceReference> AllBaseReferences(this Base FhirBase) { //Cache if (ClassPropertyMappingListCache == null) { ClassPropertyMappingListCache = new Dictionary <int, IEnumerable <Hl7.Fhir.Introspection.PropertyMapping> >(); } var ReferenceResultList = new List <ResourceReference>(); if (FhirBase == null) { return(ReferenceResultList); } //If DomainResource of Extention then drill through all extentions and collect all referances if (FhirBase is DomainResource DomainResource) { ReferenceResultList.AddRange(DomainResource.Extension.AllExtensionListReferences()); } else if (FhirBase is Extension Extension) { ReferenceResultList.AddRange(Extension.AllExtensionReferences()); } //Cache ClassMappings's PropertyList as likley to have same resource again in the bundle entries IEnumerable <Hl7.Fhir.Introspection.PropertyMapping> PropertyMappingList = ClassPropertyMappingListCache.SingleOrDefault(x => x.Key == FhirBase.TypeName.GetHashCode()).Value; if (PropertyMappingList == null) { var ClassMapping = Hl7.Fhir.Introspection.ClassMapping.Create(FhirBase.GetType()); PropertyMappingList = ClassMapping.PropertyMappings.Where(t => t.ElementType == typeof(ResourceReference) || t.ElementType.BaseType == typeof(BackboneElement)); ClassPropertyMappingListCache.Add(FhirBase.TypeName.GetHashCode(), PropertyMappingList); } foreach (var PropertyItem in PropertyMappingList) { if (PropertyItem.ElementType.BaseType == typeof(BackboneElement)) { if (PropertyItem.IsCollection) { var PropertyCollection = PropertyItem.GetValue(FhirBase) as System.Collections.IEnumerable; foreach (var CollectionItem in PropertyCollection) { var BackboneElement = CollectionItem as BackboneElement; ReferenceResultList.AddRange(BackboneElement.AllBaseReferences()); } } else { var BackboneElement = PropertyItem.GetValue(FhirBase) as BackboneElement; ReferenceResultList.AddRange(BackboneElement.AllBaseReferences()); } } else { if (PropertyItem.GetValue(FhirBase) is ResourceReference rr) { ReferenceResultList.Add(rr); } } } return(ReferenceResultList); }
private static List <ResourceReference> AllBaseReferences(this Base FhirBase, Dictionary <int, IEnumerable <Hl7.Fhir.Introspection.PropertyMapping> > ClassPropertyMappingListCache) { var ReferenceResultList = new List <ResourceReference>(); if (FhirBase == null) { return(ReferenceResultList); } //If DomainResource or Extension then drill through all extensions and collect all references if (FhirBase is DomainResource DomainResource) { ReferenceResultList.AddRange(DomainResource.Extension.AllExtensionListReferences()); } else if (FhirBase is Extension Extension) { ReferenceResultList.AddRange(Extension.AllExtensionReferences()); } //Cache ClassMappings's PropertyList as likely to have same resource again in the bundle entries IEnumerable <Hl7.Fhir.Introspection.PropertyMapping> PropertyMappingList = ClassPropertyMappingListCache.SingleOrDefault(x => x.Key == FhirBase.TypeName.GetHashCode()).Value; if (PropertyMappingList == null) { var ClassMapping = Hl7.Fhir.Introspection.ClassMapping.Create(FhirBase.GetType()); PropertyMappingList = ClassMapping.PropertyMappings.Where(t => t.ElementType == typeof(ResourceReference) || t.ElementType.BaseType == typeof(BackboneElement)); ClassPropertyMappingListCache.Add(FhirBase.TypeName.GetHashCode(), PropertyMappingList); } int Count = 0; foreach (var PropertyItem in PropertyMappingList) { if (PropertyItem.ElementType.BaseType == typeof(BackboneElement)) { if (PropertyItem.IsCollection) { try { var PropertyCollection = PropertyItem.GetValue(FhirBase) as System.Collections.IEnumerable; foreach (var CollectionItem in PropertyCollection) { var BackboneElement = CollectionItem as BackboneElement; ReferenceResultList.AddRange(BackboneElement.AllBaseReferences(ClassPropertyMappingListCache)); } } catch (System.Exception) { //Why Does 'PropertyItem.GetValue(FhirBase)' throw an exception? //for no we are ignoring the exception as not sure what else to do, could be some //ResourceReferences in transaction bundles are not updated. } } else { try { var BackboneElement = PropertyItem.GetValue(FhirBase) as BackboneElement; ReferenceResultList.AddRange(BackboneElement.AllBaseReferences(ClassPropertyMappingListCache)); } catch (System.Exception) { //Why Does 'PropertyItem.GetValue(FhirBase)' throw an exception? //for no we are ignoring the exception as not sure what else to do, could be some //ResourceReferences in transaction bundles are not updated. } } } else { try { if (PropertyItem.GetValue(FhirBase) is ResourceReference SingleRef) { ReferenceResultList.Add(SingleRef); } if (PropertyItem.GetValue(FhirBase) is ICollection <ResourceReference> ResourceReferenceList) { foreach (ResourceReference Ref in ResourceReferenceList) { ReferenceResultList.Add(Ref); } } } catch (System.Exception) { //Why Does 'PropertyItem.GetValue(FhirBase)' throw an exception? //for no we are ignoring the exception as not sure what else to do, could be some //ResourceReferences in translation bundles are not updated. } } Count++; } return(ReferenceResultList); }