Table of Contents

Struct Unit

Namespace
MigraDoc.DocumentObjectModel
Assembly
MigraDoc.DocumentObjectModel.dll

A Unit consists of a numerical value and a UnitType like Centimeter, Millimeter, or Inch. Several conversions between different measures are supported.

public struct Unit

Constructors

Unit(double)

Initializes a new instance of the Unit class with type set to point.

Unit(double, UnitType)

Initializes a new instance of the Unit class. Throws System.ArgumentException if

type

is invalid.

Fields

Empty

Represents the uninitialized Unit object.

Zero

Represents an initialized Unit object with value 0 and unit type point.

Properties

Centimeter

Gets or sets the value in centimeter.

Inch

Gets or sets the value in inch.

IsEmpty

Determines whether this instance is empty.

Millimeter

Gets or sets the value in millimeter.

Pica

Gets or sets the value in pica.

Point

Gets or sets the value in point.

Type

Gets the UnitType of the object.

Value

Gets or sets the raw value of the object without any conversion. To determine the UnitType use property

Type

.

Methods

CompareTo(Unit)

Compares this Unit with another Unit value.

CompareTo(Unit?)

Compares this Unit with another Unit? value.

CompareTo(object?)

Compares this Unit with another object.

ConvertType(UnitType)

Converts an existing object from one unit into another unit type.

Equals(object?)

Calls base class Equals.

FromCentimeter(double)

Returns a Unit object. Sets type to centimeter.

FromInch(double)

Returns a Unit object. Sets type to inch.

FromMillimeter(double)

Returns a Unit object. Sets type to millimeter.

FromPica(double)

Returns a Unit object. Sets type to pica.

FromPoint(double)

Returns a Unit object. Sets type to point.

GetHashCode()

Calls base class GetHashCode.

IsSameValue(Unit)

Compares the actual values of this Unit and another Unit value tolerating rounding errors.

IsSameValue(Unit?)

Compares the actual values of this Unit and another Unit? value tolerating rounding errors.

Parse(string)

This member is intended to be used by XmlDomainObjectReader only. StL: A fun fact is that this project does not even contain an XmlDomainObjectReader

ToString()

Returns the object as string. Measure will be added to the end of the string.

ToString(IFormatProvider)

Returns the object as string using the format information. Measure will be added to the end of the string.

ToString(string)

Returns the object as string using the format. Measure will be added to the end of the string.

Operators

operator +(Unit, Unit)

Adds a Unit to a Unit.

operator +(Unit, string)

Adds a string parsed as Unit to a Unit.

operator +(Unit?, Unit?)

Adds a Unit? to a Unit?.

operator +(Unit?, string)

Adds a string parsed as Unit to a Unit?.

operator /(Unit, double)

Divides a Unit by a double.

operator /(Unit?, double)

Divides a Unit? by a double.

operator ==(Unit, Unit)

Memberwise comparison checking exact value and unit. To compare by value tolerating rounding errors, use IsSameValue() or code like Math.Abs(a.Point - b.Point) < 1e-5.

operator ==(Unit?, Unit?)

Memberwise comparison checking exact value and unit. To compare by value tolerating rounding errors, use IsSameValue() or code like Math.Abs(a.Point - b.Point) < 1e-5.

operator >(Unit, Unit)

Compares two Unit values.

operator >(Unit?, Unit?)

Compares two Unit? values.

operator >=(Unit, Unit)

Compares two Unit values.

operator >=(Unit?, Unit?)

Compares two Unit? values.

implicit operator double(Unit)

Returns a double value as point.

implicit operator float(Unit)

Returns a float value as point.

implicit operator Unit(double)

Converts a double to a Unit object with type set to point.

implicit operator Unit(int)

Converts an int to a Unit object with type set to point.

implicit operator Unit(float)

Converts a float to a Unit object with type set to point.

implicit operator Unit(string?)

Converts a string to a Unit object. If the string contains a suffix like 'cm' or 'in' the object will be converted to the appropriate type, otherwise point is assumed.

operator !=(Unit, Unit)

Memberwise comparison checking exact value and unit. To compare by value tolerating rounding errors, use code like Math.Abs(a.Point - b.Point) < 1e-5.

operator !=(Unit?, Unit?)

Memberwise comparison checking exact value and unit. To compare by value tolerating rounding errors, use code like Math.Abs(a.Point - b.Point) < 1e-5.

operator <(Unit, Unit)

Compares two Unit values.

operator <(Unit?, Unit?)

Compares two Unit? values.

operator <=(Unit, Unit)

Compares two Unit values.

operator <=(Unit?, Unit?)

Compares two Unit? values.

operator *(Unit, double)

Multiplies a Unit with a double.

operator *(Unit?, double)

Multiplies a Unit? with a double.

operator -(Unit, Unit)

Subtracts a Unit from a Unit.

operator -(Unit, string)

Subtracts a string parsed as Unit from a Unit.

operator -(Unit?, Unit?)

Subtracts a Unit? from a Unit?.

operator -(Unit?, string)

Subtracts a string parsed as Unit from a Unit?.

operator -(Unit)

Returns the negative value of a Unit.