Unit Struct
Represents a length measurement.
[TypeConverter(typeof(UnitConverter))]
public struct Unit
Constructors
Unit(double)
Initializes a new instance of the Unit struct.
public Unit(double value)
Parameter | Type | Description |
---|---|---|
value | double | The value. |
Unit(double, UnitType)
Initializes a new instance of the Unit struct.
public Unit(double value, UnitType type)
Parameter | Type | Description |
---|---|---|
value | double | The value. |
type | UnitType | The type. |
Unit(string)
Initializes a new instance of the Unit struct.
public Unit(string value)
Parameter | Type | Description |
---|---|---|
value | string | The value. |
Unit(string, CultureInfo)
Initializes a new instance of the Unit struct.
public Unit(string value, CultureInfo culture)
Parameter | Type | Description |
---|---|---|
value | string | The value. |
culture | CultureInfo | The culture. |
Properties
IsEmpty
Gets a value indicating whether this instance is empty.
Type
Gets the type of units used by Value.
Value
Gets the value.
Methods
Centimeter(double)
Creates a new Unit instance with the specified centimeters.
public static Unit Centimeter(double value)
Parameter | Type | Description |
---|---|---|
value | double | The centimeter value. |
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameter | Type | Description |
---|---|---|
obj | object | Another object to compare to. |
Returns
- bool:
true if
obj
and this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int:
A 32-bit signed integer that is the hash code for this instance.
GetPixels(double)
Gets the number of pixels represented by this Unit using the specified width when the Type is set to Percentage.
Inch(double)
Creates a new Unit instance with the specified inches.
public static Unit Inch(double value)
Parameter | Type | Description |
---|---|---|
value | double | The inch value. |
Returns
Parse(string)
Parses the specified string.
public static Unit Parse(string value)
Parameter | Type | Description |
---|---|---|
value | string | The string to parse. |
Returns
Parse(string, CultureInfo)
Parses the specified string using the specified CultureInfo.
public static Unit Parse(string value, CultureInfo culture)
Parameter | Type | Description |
---|---|---|
value | string | The string to parse. |
culture | CultureInfo | The culture. |
Returns
Percentage(double)
Creates a new Unit instance with the specified percentage.
public static Unit Percentage(double value)
Parameter | Type | Description |
---|---|---|
value | double | The percentage value. |
Returns
Pixel(double)
Creates a new Unit instance with the specified pixels.
public static Unit Pixel(double value)
Parameter | Type | Description |
---|---|---|
value | double | The pixel value. |
Returns
Point(double)
Creates a new Unit instance with the specified points.
public static Unit Point(double value)
Parameter | Type | Description |
---|---|---|
value | double | The point value. |
Returns
ToString()
Returns a string representation of this instance.
ToString(IFormatProvider)
Returns a string representation of this instance using the specified IFormatProvider to convert the Value.
public string ToString(IFormatProvider formatProvider)
Parameter | Type | Description |
---|---|---|
formatProvider | IFormatProvider | The format provider. |
Returns
ValidateIsGreaterThan(object, double)
Validates that the object is a Unit greater than the specified number.
public static bool ValidateIsGreaterThan(object value, double min)
Parameter | Type | Description |
---|---|---|
value | object | The object to validate. |
min | double | The number that the value must be greater than. |
Returns
- bool:
true
if the validation is successful; otherwise,false
.
ValidateIsGreaterThanOrEqual(object, double)
Validates that the object is a Unit greater than or equal to the specified number.
public static bool ValidateIsGreaterThanOrEqual(object value, double min)
Parameter | Type | Description |
---|---|---|
value | object | The object to validate. |
min | double | The number that the value must be greater than or equal to. |
Returns
- bool:
true
if the validation is successful; otherwise,false
.
ValidateIsPositive(object)
Validates that the object is a Unit greater than or equal to 0
.
public static bool ValidateIsPositive(object value)
Parameter | Type | Description |
---|---|---|
value | object | The object to validate. |
Returns
- bool:
true
if the validation is successful; otherwise,false
.
Operators
operator ==(Unit, Unit)
Compares two Unit objects to determine whether they are equal.
public static bool operator ==(Unit left, Unit right)
Parameter | Type | Description |
---|---|---|
left | Unit | The left. |
right | Unit | The right. |
Returns
implicit operator Unit(double)
public static implicit operator Unit(double value)
Parameter | Type | Description |
---|---|---|
value | double | The value. |
Returns
- Unit:
The result of the conversion.
operator !=(Unit, Unit)
Compares two Unit objects to determine whether they are not equal.
public static bool operator !=(Unit left, Unit right)
Parameter | Type | Description |
---|---|---|
left | Unit | The left. |
right | Unit | The right. |
Returns
Fields
Empty
Represents an empty Unit. This field is read-only.
public static readonly Unit Empty