예제 #1
0
        public DvProportion(float numerator, float denominator, ProportionKind type, bool isIntegral, int precision,
                            DvInterval <DvProportion> normalRange, ReferenceRange <DvProportion>[] otherReferenceRanges)
            : this()
        {
            DesignByContract.Check.Require(isIntegral || (type != ProportionKind.pkFraction &&
                                                          type != ProportionKind.pkIntegerFraction));
            DesignByContract.Check.Require(otherReferenceRanges == null || otherReferenceRanges.Length > 0);
            DesignByContract.Check.Require(type != ProportionKind.pkUnitary || denominator == 1);
            DesignByContract.Check.Require(type != ProportionKind.pkPercent || denominator == 100);

            this.type = type;

            if (type == ProportionKind.pkFraction || type == ProportionKind.pkIntegerFraction)
            {
                this.numerator    = (float)Math.Truncate(numerator);
                this.denominator  = (float)Math.Truncate(denominator);
                this.precision    = 0;
                this.precisionSet = true;
            }
            else
            {
                this.numerator   = numerator;
                this.denominator = denominator;
            }

            this.numeratorSet   = true;
            this.denominatorSet = true;

            this.precision    = precision;
            this.precisionSet = true;

            SetBaseData(null, normalRange, otherReferenceRanges);

            this.CheckInvariants();
        }
예제 #2
0
        public DvProportion(float numerator, float denominator, ProportionKind type)
            : this()
        {
            DesignByContract.Check.Require(type != ProportionKind.pkUnitary || denominator == 1);
            DesignByContract.Check.Require(type != ProportionKind.pkPercent || denominator == 100);

            this.type = type;

            if (type == ProportionKind.pkFraction || type == ProportionKind.pkIntegerFraction)
            {
                this.numerator    = (float)Math.Truncate(numerator);
                this.denominator  = (float)Math.Truncate(denominator);
                this.precision    = 0;
                this.precisionSet = true;
            }

            else
            {
                this.numerator   = numerator;
                this.denominator = denominator;
            }

            this.numeratorSet   = true;
            this.denominatorSet = true;

            CheckInvariants();
        }
예제 #3
0
        protected override void ReadXmlBase(System.Xml.XmlReader reader)
        {
            base.ReadXmlBase(reader);

            Check.Assert(reader.LocalName == "numerator", "Expected LocalName should be numerator rather than "
                         + reader.LocalName);
            this.numerator    = reader.ReadElementContentAsFloat("numerator", RmXmlSerializer.OpenEhrNamespace);
            this.numeratorSet = true;

            reader.MoveToContent();
            Check.Assert(reader.LocalName == "denominator", "Expected LocalName should be denominator rather than "
                         + reader.LocalName);
            this.denominator    = reader.ReadElementContentAsFloat("denominator", RmXmlSerializer.OpenEhrNamespace);
            this.denominatorSet = true;

            reader.MoveToContent();
            Check.Assert(reader.LocalName == "type", "Expected LocalName should be type rather than "
                         + reader.LocalName);
            int typeValue = reader.ReadElementContentAsInt("type", RmXmlSerializer.OpenEhrNamespace);

            if (typeValue == 0)
            {
                this.type = ProportionKind.pkRatio;
            }
            else if (typeValue == 1)
            {
                this.type = ProportionKind.pkUnitary;
            }
            else if (typeValue == 2)
            {
                this.type = ProportionKind.pkPercent;
            }
            else if (typeValue == 3)
            {
                this.type = ProportionKind.pkFraction;
            }
            else if (typeValue == 4)
            {
                this.type = ProportionKind.pkIntegerFraction;
            }
            else
            {
                throw new InvalidOperationException("invalid type value for Proportion.type: " + typeValue);
            }
            this.typeSet = true;

            reader.MoveToContent();
            if (reader.LocalName == "precision")
            {
                this.precision    = reader.ReadElementContentAsInt("precision", RmXmlSerializer.OpenEhrNamespace);
                this.precisionSet = true;
            }
        }