namespace System.Globalization
{
- public class CultureInfo
+ public class CultureInfo : IFormatProvider
{
static CultureInfo invariant_culture_info;
bool is_read_only;
}
}
+ //
+ // IFormatProvider implementation
+ //
+ public virtual object GetFormat( Type formatType )
+ {
+ object format = null;
+
+ if ( formatType == typeof(NumberFormatInfo) )
+ format = NumberFormat;
+ else if ( formatType == typeof(DateTimeFormatInfo) )
+ format = DateTimeFormat;
+
+ return format;
+ }
+
//
// Constructors
//
_MonthNames = INVARIANT_MONTH_NAMES;
}
- // LAMESPEC: this is not in ECMA specs\r
- public static DateTimeFormatInfo GetInstance(IFormatProvider provider)\r
- {\r
- if (provider != null) \r
- {\r
- if (provider is DateTimeFormatInfo) return (DateTimeFormatInfo) provider;\r
- if (provider is CultureInfo) return ((CultureInfo) provider).DateTimeFormat;\r
- return null;\r
- }\r
- else \r
- {\r
- return CurrentInfo;\r
- }\r
- }\r
-\r
+ // LAMESPEC: this is not in ECMA specs
+ public static DateTimeFormatInfo GetInstance(IFormatProvider provider)
+ {
+ if (provider != null) {
+ DateTimeFormatInfo dtfi;
+ dtfi = (DateTimeFormatInfo)provider.GetFormat(typeof(DateTimeFormatInfo));
+ if (dtfi != null)
+ return dtfi;
+ }
+
+ return CurrentInfo;
+ }
+
public bool IsReadOnly {
get {
return readOnly;
public object GetFormat (Type formatType)
{
- // LAMESPEC: ECMA says we implement IFormatProvider, but doesn't define this
- //
- // From the .NET Framework SDK
- //
- // Parameters: formatType The Type of the formatting service required.
- //
- // Return Value: The current instance of the NumberFormatInfo class, if formatType
- // is the same as the type of the current instance; otherwise, a null reference
- //
- // Remarks: This method is invoked by the Format(String, IFormatProvider) method
- // supported by the base data types when this instance is passed as the
- // IFormatProvider parameter. It implements IFormatProvider.GetFormat.
-
- if (formatType.Equals(this)) // LAMESPEC: Should this be IsInstanceOfType?
- return this;
- else return null;
+ return (formatType == GetType()) ? this : null;
}
public object Clone ()
return copy;
}
- public static NumberFormatInfo GetInstance(IFormatProvider formatProvider)
+ public static NumberFormatInfo GetInstance(IFormatProvider provider)
{
- if (formatProvider == null) return NumberFormatInfo.CurrentInfo;
- NumberFormatInfo retval = (NumberFormatInfo)formatProvider.GetFormat(Type.GetType("System.Globalization.NumberFormatInfo"));
- if (retval == null) return NumberFormatInfo.CurrentInfo;
- return retval;
+ if (provider != null) {
+ NumberFormatInfo nfi;
+ nfi = (NumberFormatInfo)provider.GetFormat(typeof(NumberFormatInfo));
+ if (nfi != null)
+ return nfi;
+ }
+
+ return CurrentInfo;
}
}
}
namespace System {
public struct Byte : IComparable, IFormattable, IConvertible {
- private static Type Type = typeof (byte);
public const byte MinValue = 0;
public const byte MaxValue = 255;
public override string ToString ()
{
- return ToString ("G", null);
+ return ToString (null, null);
}
public string ToString (string format)
public string ToString (IFormatProvider provider)
{
- return ToString ("G", provider);
+ return ToString (null, provider);
}
public string ToString (string format, IFormatProvider fp)
{
- string fmt;
- NumberFormatInfo nfi;
+ NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- fmt = (format == null) ? "G" : format;
+ if ( format == null )
+ format = "G";
- if (fp == null)
- nfi = NumberFormatInfo.CurrentInfo;
- else {
- nfi = (NumberFormatInfo) fp.GetFormat (Type);
-
- if (nfi == null)
- nfi = NumberFormatInfo.CurrentInfo;
- }
-
- return IntegerFormatter.NumberToString (fmt, nfi, value);
+ return IntegerFormatter.NumberToString(format, nfi, value);
}
// =========== IConvertible Methods =========== //
namespace System {
public struct Int16 : IComparable, IFormattable { //, IConvertible {
- private static Type Type = typeof (short);
public const short MaxValue = 32767;
public const short MinValue = -32768;
public override string ToString ()
{
- return ToString ("G", null);
+ return ToString (null, null);
}
public string ToString (IFormatProvider fp)
{
- return ToString ("G", fp);
+ return ToString (null, fp);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp)
{
- string fmt;
- NumberFormatInfo nfi;
+ NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- fmt = (format == null) ? "G" : format;
+ if ( format == null )
+ format = "G";
- if (fp == null)
- nfi = NumberFormatInfo.CurrentInfo;
- else {
- nfi = (NumberFormatInfo) fp.GetFormat (Type);
-
- if (nfi == null)
- nfi = NumberFormatInfo.CurrentInfo;
- }
-
- return IntegerFormatter.NumberToString (fmt, nfi, value);
+ return IntegerFormatter.NumberToString(format, nfi, value);
}
// =========== IConvertible Methods =========== //
namespace System {
public struct Int32 : IComparable, IFormattable, IConvertible {
- private static Type Type = typeof (int);
-
+
public const int MaxValue = 0x7fffffff;
public const int MinValue = -2147483648;
public override string ToString ()
{
- return ToString ("G", null);
+ return ToString (null, null);
}
public string ToString (IFormatProvider fp)
{
- return ToString ("G", fp);
+ return ToString (null, fp);
}
public string ToString (string format)
return ToString (format, null);
}
- public string ToString (string format, IFormatProvider fp)
+ public string ToString (string format, IFormatProvider fp )
{
- string fmt;
- NumberFormatInfo nfi;
+ NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- fmt = (format == null) ? "G" : format;
-
- if (fp == null)
- nfi = NumberFormatInfo.CurrentInfo;
- else {
- nfi = (NumberFormatInfo) fp.GetFormat (Type);
-
- if (nfi == null)
- nfi = NumberFormatInfo.CurrentInfo;
- }
+ if ( format == null )
+ format = "G";
- return IntegerFormatter.NumberToString (fmt, nfi, value);
+ return IntegerFormatter.NumberToString (format, nfi, value);
}
// =========== IConvertible Methods =========== //
namespace System {
public struct Int64 : IComparable, IFormattable { //, IConvertible {
- private static Type Type = typeof (long);
public const long MaxValue = 0x7fffffffffffffff;
public const long MinValue = -9223372036854775808;
public override string ToString ()
{
- return ToString ("G", null);
+ return ToString (null, null);
}
public string ToString (IFormatProvider fp)
{
- return ToString ("G", fp);
+ return ToString (null, fp);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp)
{
- string fmt;
- NumberFormatInfo nfi;
+ NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- fmt = (format == null) ? "G" : format;
+ if ( format == null )
+ format = "G";
- if (fp == null)
- nfi = NumberFormatInfo.CurrentInfo;
- else {
- nfi = (NumberFormatInfo) fp.GetFormat (Type);
-
- if (nfi == null)
- nfi = NumberFormatInfo.CurrentInfo;
- }
-
- return IntegerFormatter.NumberToString (fmt, nfi, value);
+ return IntegerFormatter.NumberToString (format, nfi, value);
}
// =========== IConvertible Methods =========== //
[CLSCompliant(false)]
public struct SByte : IComparable, IFormattable { //, IConvertible {
- public static Type Type = typeof (sbyte);
public const sbyte MinValue = -128;
public const sbyte MaxValue = 127;
public override string ToString ()
{
- return ToString ("G", null);
+ return ToString (null, null);
}
public string ToString (IFormatProvider fp)
{
- return ToString ("G", fp);
+ return ToString (null, fp);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp)
{
- string fmt;
- NumberFormatInfo nfi;
+ NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- fmt = (format == null) ? "G" : format;
+ if ( format == null )
+ format = "G";
- if (fp == null)
- nfi = NumberFormatInfo.CurrentInfo;
- else {
- nfi = (NumberFormatInfo) fp.GetFormat (Type);
-
- if (nfi == null)
- nfi = NumberFormatInfo.CurrentInfo;
- }
-
- return IntegerFormatter.NumberToString (fmt, nfi, value);
+ return IntegerFormatter.NumberToString(format, nfi, value);
}
// =========== ICovnertible Methods =========== //
[CLSCompliant(false)]
public struct UInt16 : IComparable, IFormattable { //, IConvertible {
- private static Type Type = typeof (ushort);
public const ushort MaxValue = 0xffff;
public const ushort MinValue = 0;
public override string ToString ()
{
- return ToString ("G", null);
+ return ToString (null, null);
}
public string ToString (IFormatProvider fp)
{
- return ToString ("G", fp);
+ return ToString (null, fp);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp)
{
- string fmt;
- NumberFormatInfo nfi;
+ NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- fmt = (format == null) ? "G" : format;
+ if ( format == null )
+ format = "G";
- if (fp == null)
- nfi = NumberFormatInfo.CurrentInfo;
- else {
- nfi = (NumberFormatInfo) fp.GetFormat (Type);
-
- if (nfi == null)
- nfi = NumberFormatInfo.CurrentInfo;
- }
-
- return IntegerFormatter.NumberToString (fmt, nfi, value);
+ return IntegerFormatter.NumberToString(format, nfi, value);
}
// =========== IConvertible Methods =========== //
[CLSCompliant(false)]
public struct UInt32 : IComparable, IFormattable { //, IConvertible {
- public static Type Type = typeof (uint);
public const uint MaxValue = 0xffffffff;
public const uint MinValue = 0;
public override string ToString ()
{
- return ToString ("G", null);
+ return ToString (null, null);
}
public string ToString (IFormatProvider fp)
{
- return ToString ("G", fp);
+ return ToString (null, fp);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp)
{
- string fmt;
- NumberFormatInfo nfi;
+ NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- fmt = (format == null) ? "G" : format;
+ if ( format == null )
+ format = "G";
- if (fp == null)
- nfi = NumberFormatInfo.CurrentInfo;
- else {
- nfi = (NumberFormatInfo) fp.GetFormat (Type);
-
- if (nfi == null)
- nfi = NumberFormatInfo.CurrentInfo;
- }
-
- return IntegerFormatter.NumberToString (fmt, nfi, value);
+ return IntegerFormatter.NumberToString(format, nfi, value);
}
// =========== IConvertible Methods =========== //
[CLSCompliant(false)]
public struct UInt64 : IComparable, IFormattable { //, IConvertible {
- private static Type Type = typeof (ulong);
-
public const ulong MaxValue = 0xffffffffffffffff;
public const ulong MinValue = 0;
public override string ToString ()
{
- return ToString ("G", null);
+ return ToString (null, null);
}
public string ToString (IFormatProvider fp)
{
- return ToString ("G", fp);
+ return ToString (null, fp);
}
public string ToString (string format)
public string ToString (string format, IFormatProvider fp)
{
- string fmt;
- NumberFormatInfo nfi;
+ NumberFormatInfo nfi = NumberFormatInfo.GetInstance( fp );
- fmt = (format == null) ? "G" : format;
+ if ( format == null )
+ format = "G";
- if (fp == null)
- nfi = NumberFormatInfo.CurrentInfo;
- else {
- nfi = (NumberFormatInfo) fp.GetFormat (Type);
-
- if (nfi == null)
- nfi = NumberFormatInfo.CurrentInfo;
- }
-
- return IntegerFormatter.NumberToString (fmt, nfi, value);
+ return IntegerFormatter.NumberToString(format, nfi, value);
}
// =========== IConvertible Methods =========== //