IValueWithMeasureExtensionsConvertToOrDefaultTUnitOfMeasure, TValueWithMeasure Method |
Converts the
IValueWithMeasureTUnitOfMeasure to the specified destination unit,
using the specified conversion ratio provider.
Returns null 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 ConvertToOrDefault<TUnitOfMeasure, TValueWithMeasure>(
this TValueWithMeasure fromValueWithMeasure,
TUnitOfMeasure destinationUnit,
IConversionRatioProvider<TUnitOfMeasure> conversionRatioProvider,
bool roundResult = true
)
where TUnitOfMeasure : IUnitOfMeasure
where TValueWithMeasure : Object, IValueWithMeasure<TUnitOfMeasure>
<ExtensionAttribute>
Public Shared Function ConvertToOrDefault(Of TUnitOfMeasure As IUnitOfMeasure, TValueWithMeasure As {Object, IValueWithMeasure(Of TUnitOfMeasure)}) (
fromValueWithMeasure As TValueWithMeasure,
destinationUnit As TUnitOfMeasure,
conversionRatioProvider As IConversionRatioProvider(Of TUnitOfMeasure),
Optional roundResult As Boolean = true
) As TValueWithMeasure
public:
[ExtensionAttribute]
generic<typename TUnitOfMeasure, typename TValueWithMeasure>
where TUnitOfMeasure : IUnitOfMeasure
where TValueWithMeasure : Object, IValueWithMeasure<TUnitOfMeasure>
static TValueWithMeasure ConvertToOrDefault(
TValueWithMeasure fromValueWithMeasure,
TUnitOfMeasure destinationUnit,
IConversionRatioProvider<TUnitOfMeasure>^ conversionRatioProvider,
bool roundResult = true
)
[<ExtensionAttribute>]
static member ConvertToOrDefault :
fromValueWithMeasure : 'TValueWithMeasure *
destinationUnit : 'TUnitOfMeasure *
conversionRatioProvider : IConversionRatioProvider<'TUnitOfMeasure> *
?roundResult : bool
(* Defaults:
let _roundResult = defaultArg roundResult true
*)
-> '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. - roundResult (Optional)
- Type: SystemBoolean
Specifies whether to round the result according to the measurement unit
rounding rules.
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
|
Remarks
Examples
Amount a = new Amount(10, usd);
//the document is ratio provider, which simply transfers to its currency directory
Amount b = a.ConvertToOrDefault(eur, this.Document);
Amount c = a.ConvertToOrDefault(aus, this.Document.CurrencyDirectory);
//these will return null
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