示例#1
0
        public override bool ValidValue(object aValue)
        {
            DesignByContract.Check.Require(aValue != null, string.Format(
                                               CommonStrings.XMustNotBeNull, "aValue"));
            DesignByContract.Check.Require(this.IsValid(), string.Format(
                                               AmValidationStrings.ConstraintXIsValidGetsFalse, "CDvQuantity"));

            if (this.AnyAllowed())
            {
                return(true);
            }

            DvQuantity dvQuantity = aValue as DvQuantity;

            if (dvQuantity != null)
            {
                if (this.list != null)
                {
                    foreach (CQuantityItem item in this.List)
                    {
                        if (item.Units == dvQuantity.Units)
                        {
                            double dvMagnitude = dvQuantity.Magnitude;
                            float  floatValue  = (float)(dvMagnitude);
                            if (item.Magnitude == null || item.Magnitude.Has(floatValue))
                            {
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    // TODO: lookup allowed units for specified property
                    return(true);
                }
            }
            this.ValidationContext.AcceptValidationError(this,
                                                         string.Format(AmValidationStrings.InvalidDvQuantityX, dvQuantity));

            return(false);
        }
示例#2
0
        private void ReadXml(CDvQuantity cDomainType)
        {
            reader.ReadStartElement();
            reader.MoveToContent();

            this.ReadXmlBase((CObject)cDomainType);

            if (reader.LocalName == "assumed_value")
            {
                DvQuantity assumedValue = new DvQuantity();
                assumedValue.ReadXml(reader);
                cDomainType.AssumedValue = assumedValue;
            }

            if (reader.LocalName == "property")
            {
                cDomainType.Property = new CodePhrase();
                cDomainType.Property.ReadXml(reader);
            }

            if (reader.LocalName == "list")
            {
                cDomainType.List = new OpenEhr.AssumedTypes.List<CQuantityItem>();
                do
                {
                    CQuantityItem quantityItem = new CQuantityItem();
                    this.ReadXml(quantityItem);
                    cDomainType.List.Add(quantityItem);
                } while (reader.LocalName == "list" && reader.NodeType != XmlNodeType.EndElement);

                Check.Assert(cDomainType.List.Count > 0, "CDvQuantity.List may not be empty.");
            }

            reader.ReadEndElement();
            reader.MoveToContent();
        }