Click or drag to resize

IValueWithMeasureExtensionsConvertToWithPrecisionTUnitOfMeasure, TValueWithMeasure Method

Converts the IValueWithMeasureTUnitOfMeasure to the specified destination unit, using the specified conversion ratio provider, without rounding the result. Throws exception if the conversion is not possible.

Namespace:  Aloe.EnterpriseOne.Model.Core.Metrics
Assembly:  Aloe.EnterpriseOne.Model (in Aloe.EnterpriseOne.Model.dll) Version: 20.1.3.5
Syntax
public static TValueWithMeasure ConvertToWithPrecision<TUnitOfMeasure, TValueWithMeasure>(
	this TValueWithMeasure fromValueWithMeasure,
	TUnitOfMeasure destinationUnit,
	IConversionRatioProvider<TUnitOfMeasure> conversionRatioProvider
)
where TUnitOfMeasure : IUnitOfMeasure
where TValueWithMeasure : Object, IValueWithMeasure<TUnitOfMeasure>

Parameters

fromValueWithMeasure
Type: TValueWithMeasure
From value with measure.
destinationUnit
Type: TUnitOfMeasure
The destination unit.
conversionRatioProvider
Type: Aloe.EnterpriseOne.Model.Core.MetricsIConversionRatioProviderTUnitOfMeasure
The conversion ratio provider.

Type Parameters

TUnitOfMeasure
The type of the unit of measure.
TValueWithMeasure
The type of the value with measure.

Return Value

Type: TValueWithMeasure
The newly created IValueWithMeasureTUnitOfMeasure, which resulted from the conversion.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Exceptions
ExceptionCondition
ArgumentNullException When fromValueWithMeasure, destinationUnit or conversionRatioProvider are required, but are null
Remarks

ConvertToTUnitOfMeasure, TValueWithMeasure(TValueWithMeasure, TUnitOfMeasure, IConversionRatioProviderTUnitOfMeasure) is a generalized conversion method. It is designed to be able to convert between measurement units of the same type class. Usually, the method is called without specifying the type parameters - the compiler should be able to infer them.

Examples of conversion include:

  • Conversion of Amount instances, using currency rates ratio provider.
  • Conversion of SI measurement units, using SI ratio provider.
  • Conversion of Quantity instances, using the product as ratio provider.

Examples
Amount a = new Amount(10, usd); //the document is ratio provider, which simply transfers to its currency directory Amount b = a.ConvertToWithPrecision(eur, this.Document); Amount c = a.ConvertToWithPrecision(aus, this.Document.CurrencyDirectory); //these will throw exception Amount d = a.ConvertToOrDefault(eur, null); //no ratio provider Amount e = a.ConvertToOrDefault(cad, this.Document); //when there is no rate for "CAD"
See Also