Table of Contents

Class Unit

Namespace
StockSharp.Messages
Assembly
StockSharp.Messages.dll

Special class, allows to set the value as a percentage, absolute, points and pips values.

[DataContract]
public class Unit : Equatable<Unit>, IOperable<Unit>, IComparable<Unit>, IPersistable, IFormattable
Inheritance
Unit
Implements
IOperable<Unit>
IPersistable
Extension Methods

Constructors

Unit()

Create unit.

public Unit()

Unit(decimal)

Create absolute value Absolute.

public Unit(decimal value)

Parameters

value decimal

Value.

Unit(decimal, UnitTypes)

Create a value of types Absolute and Percent.

public Unit(decimal value, UnitTypes type)

Parameters

value decimal

Value.

type UnitTypes

Measure unit.

Unit(decimal, UnitTypes, Func<UnitTypes, decimal?>)

Create a value of types Point and Step.

public Unit(decimal value, UnitTypes type, Func<UnitTypes, decimal?> getTypeValue)

Parameters

value decimal

Value.

type UnitTypes

Measure unit.

getTypeValue Func<UnitTypes, decimal?>

The handler returns a value associated with Type (price or volume steps).

Properties

GetTypeValue

The handler returns a value associated with Type (price or volume steps).

public Func<UnitTypes, decimal?> GetTypeValue { get; set; }

Property Value

Func<UnitTypes, decimal?>

Type

Measure unit.

[DataMember]
public UnitTypes Type { get; set; }

Property Value

UnitTypes

Value

Value.

[DataMember]
public decimal Value { get; set; }

Property Value

decimal

Methods

Clone()

Create a copy of Unit.

public override Unit Clone()

Returns

Unit

Copy.

CompareTo(Unit)

Compare Unit on the equivalence.

public override int CompareTo(Unit other)

Parameters

other Unit

Another value with which to compare.

Returns

int

The result of the comparison.

Convert(UnitTypes, bool)

Cast the value to another type.

public Unit Convert(UnitTypes destinationType, bool throwException = true)

Parameters

destinationType UnitTypes

Destination value type.

throwException bool

Throw exception in case of impossible conversion. Otherwise, returns null.

Returns

Unit

Converted value.

Convert(UnitTypes, Func<UnitTypes, decimal?>, bool)

Cast the value to another type.

public Unit Convert(UnitTypes destinationType, Func<UnitTypes, decimal?> getTypeValue, bool throwException = true)

Parameters

destinationType UnitTypes

Destination value type.

getTypeValue Func<UnitTypes, decimal?>

The handler returns a value associated with Type (price or volume steps).

throwException bool

Throw exception in case of impossible conversion. Otherwise, returns null.

Returns

Unit

Converted value.

Equals(object)

Compare Unit on the equivalence.

public override bool Equals(object other)

Parameters

other object

Another value with which to compare.

Returns

bool

true, if the specified object is equal to the current object, otherwise, false.

GetHashCode()

Get the hash code of the object Unit.

public override int GetHashCode()

Returns

int

A hash code.

GetTypeSuffix(UnitTypes)

Get string suffix.

public static string GetTypeSuffix(UnitTypes type)

Parameters

type UnitTypes

Measure unit.

Returns

string

String suffix.

Load(SettingsStorage)

Load settings.

public void Load(SettingsStorage storage)

Parameters

storage SettingsStorage

Settings storage.

OnEquals(Unit)

Compare Unit on the equivalence.

protected override bool OnEquals(Unit other)

Parameters

other Unit

Another value with which to compare.

Returns

bool

true, if the specified object is equal to the current object, otherwise, false.

Save(SettingsStorage)

Save settings.

public void Save(SettingsStorage storage)

Parameters

storage SettingsStorage

Settings storage.

ToString()

public override string ToString()

Returns

string

ToString(string, IFormatProvider)

public string ToString(string format, IFormatProvider formatProvider)

Parameters

format string
formatProvider IFormatProvider

Returns

string

Operators

operator +(Unit, Unit)

Add the two objects Unit.

public static Unit operator +(Unit u1, Unit u2)

Parameters

u1 Unit

First object Unit.

u2 Unit

Second object Unit.

Returns

Unit

The result of addition.

operator /(Unit, Unit)

Divide the unit Unit to another.

public static Unit operator /(Unit u1, Unit u2)

Parameters

u1 Unit

First object Unit.

u2 Unit

Second object Unit.

Returns

Unit

The result of the division.

operator ==(Unit, Unit)

Compare two values for equality (if the value of different types, the conversion will be used).

public static bool operator ==(Unit u1, Unit u2)

Parameters

u1 Unit

First unit.

u2 Unit

Second unit.

Returns

bool

true, if the values are equals, otherwise, false.

explicit operator decimal(Unit)

Cast object from Unit to decimal.

public static explicit operator decimal(Unit unit)

Parameters

unit Unit

Object Unit.

Returns

decimal

decimal value.

explicit operator double(Unit)

Cast object from Unit to double.

public static explicit operator double(Unit unit)

Parameters

unit Unit

Object Unit.

Returns

double

double value.

explicit operator decimal?(Unit)

Cast object from Unit to nullable decimal.

public static explicit operator decimal?(Unit unit)

Parameters

unit Unit

Object Unit.

Returns

decimal?

decimal value.

explicit operator double?(Unit)

Cast object from Unit to nullable double.

public static explicit operator double?(Unit unit)

Parameters

unit Unit

Object Unit.

Returns

double?

double value.

operator >(Unit, Unit)

Check whether the first value is greater than the second.

public static bool operator >(Unit u1, Unit u2)

Parameters

u1 Unit

First unit.

u2 Unit

Second unit.

Returns

bool

true, if the first value is greater than the second, false.

operator >=(Unit, Unit)

Check whether the first value is greater than or equal to the second.

public static bool operator >=(Unit u1, Unit u2)

Parameters

u1 Unit

First unit.

u2 Unit

Second unit.

Returns

bool

true, if the first value is greater than or equal the second, otherwise, false.

implicit operator Unit(decimal)

Cast decimal object to the type Unit.

public static implicit operator Unit(decimal value)

Parameters

value decimal

decimal value.

Returns

Unit

Object Unit.

implicit operator Unit(double)

Cast double object to the type Unit.

public static implicit operator Unit(double value)

Parameters

value double

double value.

Returns

Unit

Object Unit.

implicit operator Unit(int)

Cast int object to the type Unit.

public static implicit operator Unit(int value)

Parameters

value int

int value.

Returns

Unit

Object Unit.

operator !=(Unit, Unit)

Compare two values in the inequality (if the value of different types, the conversion will be used).

public static bool operator !=(Unit u1, Unit u2)

Parameters

u1 Unit

First unit.

u2 Unit

Second unit.

Returns

bool

true, if the values are equals, otherwise, false.

operator <(Unit, Unit)

Check whether the first value is less than the second.

public static bool operator <(Unit u1, Unit u2)

Parameters

u1 Unit

First unit.

u2 Unit

Second unit.

Returns

bool

true, if the first value is less than the second, false.

operator <=(Unit, Unit)

Check whether the first value is less than or equal to the second.

public static bool operator <=(Unit u1, Unit u2)

Parameters

u1 Unit

First unit.

u2 Unit

Second unit.

Returns

bool

true, if the first value is less than or equal to the second, false.

operator *(Unit, Unit)

Multiply the two objects Unit.

public static Unit operator *(Unit u1, Unit u2)

Parameters

u1 Unit

First object Unit.

u2 Unit

Second object Unit.

Returns

Unit

The result of the multiplication.

operator -(Unit, Unit)

Subtract the unit Unit from another.

public static Unit operator -(Unit u1, Unit u2)

Parameters

u1 Unit

First object Unit.

u2 Unit

Second object Unit.

Returns

Unit

The result of the subtraction.

operator -(Unit)

Get the value with the opposite sign from the value Value.

public static Unit operator -(Unit u)

Parameters

u Unit

Unit.

Returns

Unit

Opposite value.