📄 fiurational.cs
字号:
/// </summary>
/// <param name="value">A <see cref="FIURational"/> structure.</param>
/// <returns>A new instance of <see cref="SByte"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator sbyte(FIURational value)
{
return (sbyte)(double)value;
}
/// <summary>
/// Converts the value of a <see cref="FIURational"/> structure to an <see cref="UInt16"/> structure.
/// </summary>
/// <param name="value">A <see cref="FIURational"/> structure.</param>
/// <returns>A new instance of <see cref="UInt16"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator ushort(FIURational value)
{
return (ushort)(double)value;
}
/// <summary>
/// Converts the value of a <see cref="FIURational"/> structure to an <see cref="UInt32"/> structure.
/// </summary>
/// <param name="value">A <see cref="FIURational"/> structure.</param>
/// <returns>A new instance of <see cref="UInt32"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator uint(FIURational value)
{
return (uint)(double)value;
}
/// <summary>
/// Converts the value of a <see cref="FIURational"/> structure to an <see cref="UInt32"/> structure.
/// </summary>
/// <param name="value">A <see cref="FIURational"/> structure.</param>
/// <returns>A new instance of <see cref="UInt32"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator ulong(FIURational value)
{
return (ulong)(double)value;
}
//
/// <summary>
/// Converts the value of a <see cref="Boolean"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">A <see cref="Boolean"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator FIURational(bool value)
{
return new FIURational(value ? 1u : 0u, 1u);
}
/// <summary>
/// Converts the value of a <see cref="Byte"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">A <see cref="Byte"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static implicit operator FIURational(byte value)
{
return new FIURational(value, 1);
}
/// <summary>
/// Converts the value of a <see cref="Char"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">A <see cref="Char"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static implicit operator FIURational(char value)
{
return new FIURational(value, 1);
}
/// <summary>
/// Converts the value of a <see cref="Decimal"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">A <see cref="Decimal"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator FIURational(decimal value)
{
return new FIURational(value);
}
/// <summary>
/// Converts the value of a <see cref="Double"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">A <see cref="Double"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator FIURational(double value)
{
return new FIURational((decimal)value);
}
/// <summary>
/// Converts the value of an <see cref="Int16"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">An <see cref="Int16"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static implicit operator FIURational(short value)
{
return new FIURational((uint)value, 1u);
}
/// <summary>
/// Converts the value of an <see cref="Int32"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">An <see cref="Int32"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static implicit operator FIURational(int value)
{
return new FIURational((uint)value, 1u);
}
/// <summary>
/// Converts the value of an <see cref="Int64"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">An <see cref="Int64"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator FIURational(long value)
{
return new FIURational((uint)value, 1u);
}
/// <summary>
/// Converts the value of a <see cref="SByte"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">A <see cref="SByte"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static implicit operator FIURational(sbyte value)
{
return new FIURational((uint)value, 1u);
}
/// <summary>
/// Converts the value of a <see cref="Single"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">A <see cref="Single"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator FIURational(float value)
{
return new FIURational((decimal)value);
}
/// <summary>
/// Converts the value of an <see cref="UInt16"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">An <see cref="UInt16"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static implicit operator FIURational(ushort value)
{
return new FIURational(value, 1);
}
/// <summary>
/// Converts the value of an <see cref="UInt32"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">An <see cref="UInt32"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator FIURational(uint value)
{
return new FIURational(value, 1u);
}
/// <summary>
/// Converts the value of an <see cref="UInt64"/> structure to a <see cref="FIURational"/> structure.
/// </summary>
/// <param name="value">An <see cref="UInt64"/> structure.</param>
/// <returns>A new instance of <see cref="FIURational"/> initialized to <paramref name="value"/>.</returns>
public static explicit operator FIURational(ulong value)
{
return new FIURational((uint)value, 1u);
}
#endregion
#region IConvertible Member
TypeCode IConvertible.GetTypeCode()
{
return TypeCode.Double;
}
bool IConvertible.ToBoolean(IFormatProvider provider)
{
return (bool)this;
}
byte IConvertible.ToByte(IFormatProvider provider)
{
return (byte)this;
}
char IConvertible.ToChar(IFormatProvider provider)
{
return (char)this;
}
DateTime IConvertible.ToDateTime(IFormatProvider provider)
{
return Convert.ToDateTime(((IConvertible)this).ToDouble(provider));
}
decimal IConvertible.ToDecimal(IFormatProvider provider)
{
return this;
}
double IConvertible.ToDouble(IFormatProvider provider)
{
return this;
}
short IConvertible.ToInt16(IFormatProvider provider)
{
return (short)this;
}
int IConvertible.ToInt32(IFormatProvider provider)
{
return (int)this;
}
long IConvertible.ToInt64(IFormatProvider provider)
{
return (long)this;
}
sbyte IConvertible.ToSByte(IFormatProvider provider)
{
return (sbyte)this;
}
float IConvertible.ToSingle(IFormatProvider provider)
{
return this;
}
string IConvertible.ToString(IFormatProvider provider)
{
return ToString(((double)this).ToString(), provider);
}
object IConvertible.ToType(Type conversionType, IFormatProvider provider)
{
return Convert.ChangeType(((IConvertible)this).ToDouble(provider), conversionType, provider);
}
ushort IConvertible.ToUInt16(IFormatProvider provider)
{
return (ushort)this;
}
uint IConvertible.ToUInt32(IFormatProvider provider)
{
return (uint)this;
}
ulong IConvertible.ToUInt64(IFormatProvider provider)
{
return (ulong)this;
}
#endregion
#region IComparable Member
/// <summary>
/// Compares this instance with a specified <see cref="Object"/>.
/// </summary>
/// <param name="obj">An object to compare with this instance.</param>
/// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
/// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="FIURational"/>.</exception>
public int CompareTo(object obj)
{
if (obj == null)
{
return 1;
}
if (!(obj is FIURational))
{
throw new ArgumentException();
}
return CompareTo((FIURational)obj);
}
#endregion
#region IFormattable Member
/// <summary>
/// Formats the value of the current instance using the specified format.
/// </summary>
/// <param name="format">The String specifying the format to use.</param>
/// <param name="formatProvider">The IFormatProvider to use to format the value.</param>
/// <returns>A String containing the value of the current instance in the specified format.</returns>
public string ToString(string format, IFormatProvider formatProvider)
{
if (format == null)
{
format = "";
}
return String.Format(formatProvider, format, ((IConvertible)this).ToDouble(formatProvider));
}
#endregion
#region IEquatable<FIURational> Member
/// <summary>
/// Tests whether the specified <see cref="FIURational"/> structure is equivalent to this <see cref="FIURational"/> structure.
/// </summary>
/// <param name="other">A <see cref="FIURational"/> structure to compare to this instance.</param>
/// <returns><b>true</b> if <paramref name="obj"/> is a <see cref="FIURational"/> structure
/// equivalent to this <see cref="FIURational"/> structure; otherwise, <b>false</b>.</returns>
public bool Equals(FIURational other)
{
return (this == other);
}
#endregion
#region IComparable<FIURational> Member
/// <summary>
/// Compares this instance with a specified <see cref="FIURational"/> object.
/// </summary>
/// <param name="other">A <see cref="FIURational"/> to compare.</param>
/// <returns>A signed number indicating the relative values of this instance
/// and <paramref name="other"/>.</returns>
public int CompareTo(FIURational other)
{
FIURational difference = this - other;
difference.Normalize();
if (difference.numerator > 0) return 1;
if (difference.numerator < 0) return -1;
else return 0;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -