IValueWithMeasureExtensionsConvertToTUnitOfMeasure, TValueWithMeasure Method |
Converts the
IValueWithMeasureTUnitOfMeasure to the specified destination unit,
using the specified conversion ratio provider.
Rounds the result according to the rounding rules of the destination unit.
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
Syntaxpublic static TValueWithMeasure ConvertTo<TUnitOfMeasure, TValueWithMeasure>(
this TValueWithMeasure fromValueWithMeasure,
TUnitOfMeasure destinationUnit,
IConversionRatioProvider<TUnitOfMeasure> conversionRatioProvider
)
where TUnitOfMeasure : IUnitOfMeasure
where TValueWithMeasure : Object, IValueWithMeasure<TUnitOfMeasure>
<ExtensionAttribute>
Public Shared Function ConvertTo(Of TUnitOfMeasure As IUnitOfMeasure, TValueWithMeasure As {Object, IValueWithMeasure(Of TUnitOfMeasure)}) (
fromValueWithMeasure As TValueWithMeasure,
destinationUnit As TUnitOfMeasure,
conversionRatioProvider As IConversionRatioProvider(Of TUnitOfMeasure)
) As TValueWithMeasure
public:
[ExtensionAttribute]
generic<typename TUnitOfMeasure, typename TValueWithMeasure>
where TUnitOfMeasure : IUnitOfMeasure
where TValueWithMeasure : Object, IValueWithMeasure<TUnitOfMeasure>
static TValueWithMeasure ConvertTo(
TValueWithMeasure fromValueWithMeasure,
TUnitOfMeasure destinationUnit,
IConversionRatioProvider<TUnitOfMeasure>^ conversionRatioProvider
)
[<ExtensionAttribute>]
static member ConvertTo :
fromValueWithMeasure : 'TValueWithMeasure *
destinationUnit : 'TUnitOfMeasure *
conversionRatioProvider : IConversionRatioProvider<'TUnitOfMeasure> -> 'TValueWithMeasure when 'TUnitOfMeasure : IUnitOfMeasure when 'TValueWithMeasure : Object and 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:
TValueWithMeasureThe 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).
ExceptionsException | Condition |
---|
ArgumentNullException |
When fromValueWithMeasure, destinationUnit or conversionRatioProvider are required, but are null
|
RemarksConvertToTUnitOfMeasure, 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.ConvertTo(eur, this.Document);
Amount c = a.ConvertTo(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