public RatioProvider(MeasurementProvider <TNumerator> t1Prov, MeasurementProvider <TDenominator> t2Prov)
            {
                Validate.NonNull(t1Prov, nameof(t1Prov));
                Validate.NonNull(t2Prov, nameof(t2Prov));

                this.Component1Provider = t1Prov;
                this.Component2Provider = t2Prov;
            }
        /// <summary>
        /// Initializes a new instance of the <see cref="Unit{T}"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="symbol">The symbol.</param>
        /// <param name="unitsPerDefault">The units per default unit for this measurement.</param>
        internal Unit(string symbol, double defaultsPerUnit, MeasurementProvider <T> provider) : base(defaultsPerUnit)
        {
            Validate.NonNull(symbol, nameof(symbol));
            Validate.NonNull(provider, nameof(provider));

            this.Symbol = $"({symbol})";
            this.MeasurementProvider = provider;
        }
Beispiel #3
0
            public TermProvider(MeasurementProvider <T1> t1Prov, MeasurementProvider <T2> t2Prov)
            {
                Validate.NonNull(t1Prov, nameof(t1Prov));
                Validate.NonNull(t2Prov, nameof(t2Prov));

                this.Component1Provider = t1Prov;
                this.Component2Provider = t2Prov;
            }
        public static MeasurementProvider <Ratio <TNumerator, TDenominator> > GetProvider(MeasurementProvider <TNumerator> numProvider, MeasurementProvider <TDenominator> denomProvider)
        {
            if (provider == null)
            {
                provider = new RatioProvider(numProvider, denomProvider);
            }

            return(provider);
        }
        internal Ratio(double amount, Unit <Ratio <TNumerator, TDenominator> > unit, MeasurementProvider <TNumerator> t1Prov, MeasurementProvider <TDenominator> t2Prov) : base(amount, unit)
        {
            Validate.NonNull(t1Prov, nameof(t1Prov));
            Validate.NonNull(t2Prov, nameof(t2Prov));

            this.NumeratorProvider   = t1Prov;
            this.DenominatorProvider = t2Prov;
            this.MeasurementProvider = GetProvider(this.NumeratorProvider, this.DenominatorProvider);
        }
Beispiel #6
0
        internal Term(double amount, Unit <Term <T1, T2> > unit, MeasurementProvider <T1> t1Prov, MeasurementProvider <T2> t2Prov) : base(amount, unit)
        {
            Validate.NonNull(t1Prov, nameof(t1Prov));
            Validate.NonNull(t2Prov, nameof(t2Prov));

            this.Item1Provider       = t1Prov;
            this.Item2Provider       = t2Prov;
            this.MeasurementProvider = GetProvider(this.Item1Provider, this.Item2Provider);
        }
Beispiel #7
0
        public static MeasurementProvider <Term <T1, T2> > GetProvider(MeasurementProvider <T1> numProvider, MeasurementProvider <T2> denomProvider)
        {
            Validate.NonNull(numProvider, nameof(numProvider));
            Validate.NonNull(denomProvider, nameof(denomProvider));

            if (provider == null)
            {
                provider = new TermProvider(numProvider, denomProvider);
            }

            return(provider);
        }
        public ExtendedComplexMeasurementProvider(MeasurementProvider <TComp1> comp1Provider, MeasurementProvider <TComp2> comp2Provider, Func <double, Unit <T>, T> createMeasurement, Func <IEnumerable <Unit <T> > > getParsableUnits, Func <IEnumerable <Operator> > getops)
        {
            Validate.NonNull(comp1Provider, nameof(comp1Provider));
            Validate.NonNull(comp2Provider, nameof(comp2Provider));
            Validate.NonNull(createMeasurement, nameof(createMeasurement));
            Validate.NonNull(getParsableUnits, nameof(getParsableUnits));
            Validate.NonNull(getops, nameof(getops));

            this.createMeasurement  = createMeasurement;
            this.getParsableUnits   = getParsableUnits;
            this.Component1Provider = comp1Provider;
            this.Component2Provider = comp2Provider;
            this.getOperators       = getops;
        }
Beispiel #9
0
 protected Ratio(IMeasurement <TNumerator> numerator, IMeasurement <TDenominator> denominator, MeasurementProvider <TSelf> provider) : this(
         numerator.ToDouble(numerator.MeasurementProvider.DefaultUnit) / denominator.ToDouble(denominator.MeasurementProvider.DefaultUnit),
         numerator.MeasurementProvider.DefaultUnit.DivideToRatioUnit(denominator.MeasurementProvider.DefaultUnit).ToRatioUnit(provider)
         )
 {
 }
 protected Term(IMeasurement <T1> item1, IMeasurement <T2> item2, MeasurementProvider <TSelf> provider) : base(
         item1.ToDouble(item1.MeasurementProvider.DefaultUnit) * item2.ToDouble(item2.MeasurementProvider.DefaultUnit),
         item1.MeasurementProvider.DefaultUnit.MultiplyToTermUnit(item2.MeasurementProvider.DefaultUnit).ToTermUnit(provider)
         )
 {
 }
        public static Unit <TSelf> ToRatioUnit <TSelf, TNumerator, TDenominator>(this Unit <Ratio <TNumerator, TDenominator> > unit, MeasurementProvider <TSelf> provider)
            where TNumerator : IMeasurement <TNumerator>
            where TDenominator : IMeasurement <TDenominator>
            where TSelf : Ratio <TSelf, TNumerator, TDenominator>
        {
            Validate.NonNull(unit, nameof(unit));
            Validate.NonNull(provider, nameof(provider));

            return(new Unit <TSelf>(unit.Symbol, unit.DefaultsPerUnit, provider));
        }
        public static Unit <TSelf> ToTermUnit <TSelf, T1, T2>(this Unit <Term <T1, T2> > unit, MeasurementProvider <TSelf> provider)
            where T1 : IMeasurement <T1>
            where T2 : IMeasurement <T2>
            where TSelf : Term <TSelf, T1, T2>
        {
            Validate.NonNull(unit, nameof(unit));
            Validate.NonNull(provider, nameof(provider));

            return(new Unit <TSelf>(unit.Symbol, unit.DefaultsPerUnit, provider));
        }
 public Unit(string symbol, MeasurementProvider <T> provider) : this(symbol, 1, provider)
 {
 }
 public PrefixableUnit(string symbol, MeasurementProvider <T> provider) : base(symbol, provider)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PrefixableUnit{T}"/> class.
 /// </summary>
 /// <param name="name">The name of the unit. Ex: foot</param>
 /// <param name="symbol">The symbol of the unit. Ex: ft</param>
 /// <param name="unitsPerDefault">The units per default unit for this type of measurement. Ex: 3.2808399 ft/m (meter is the default unit for length)</param>
 internal PrefixableUnit(string symbol, double defaultsPerUnit, MeasurementProvider <T> provider) : base(symbol, defaultsPerUnit, provider)
 {
 }