// // System.ComponentModel.DefaultValueAttribute // // Authors: // Andreas Nahr (ClassDevelopment@A-SoftTech.com) // // (C) 2003 Andreas Nahr // namespace System.ComponentModel { [AttributeUsage(AttributeTargets.All)] public sealed class DefaultValueAttribute : Attribute { private object DefaultValue; public DefaultValueAttribute (bool value) { DefaultValue = value; } public DefaultValueAttribute (byte value) { DefaultValue = value; } public DefaultValueAttribute (char value) { DefaultValue = value; } public DefaultValueAttribute (double value) { DefaultValue = value; } public DefaultValueAttribute (short value) { DefaultValue = value; } public DefaultValueAttribute (int value) { DefaultValue = value; } public DefaultValueAttribute (long value) { DefaultValue = value; } public DefaultValueAttribute (object value) { DefaultValue = value; } public DefaultValueAttribute (float value) { DefaultValue = value; } public DefaultValueAttribute (string value) { DefaultValue = value; } public DefaultValueAttribute (Type type, string value) { // TODO check if this implementation is correct try { DefaultValue = Convert.ChangeType (value, type); } catch { DefaultValue = null; } } public object Value { get { return DefaultValue; } } public override bool Equals (object obj) { if (!(obj is DefaultValueAttribute)) return false; if (obj == this) return true; return ((DefaultValueAttribute) obj).Value == DefaultValue; } public override int GetHashCode() { return DefaultValue.GetHashCode(); } } } // OLD IMPLEMENTATION //using System; // // // //namespace System.ComponentModel // //{ // // /// // // /// Specifies the default value for a property. // // /// // // // // [MonoTODO("Needs testing. DefaultValueAttribute(System.Type type, string value) is not implemented. Value has no description.")] // // [AttributeUsage(AttributeTargets.All)] // // public sealed class DefaultValueAttribute : Attribute // // { // // // // private object defaultValue; // // // // /// // // /// FIXME: Summary description for Value. // // /// // // public object Value // // { // // get // // { // // return defaultValue; // // } // // } // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class. // // /// // // /// An System.Object that represents the default value. // // public DefaultValueAttribute(object value) // // { // // defaultValue = value; // // } // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class using a System.Boolean value. // // /// // // /// An System.Boolean that represents the default value. // // public DefaultValueAttribute(bool value) // // { // // defaultValue = value; // // } // // // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class using an 8-bit unsigned integer. // // /// // // /// An 8-bit unsigned integer that is the default value. // // public DefaultValueAttribute(byte value) // // { // // defaultValue = value; // // } // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class using a Unicode character. // // /// // // /// A Unicode character that is the default value. // // public DefaultValueAttribute(char value) // // { // // defaultValue = value; // // } // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class using a double-precision floating point number. // // /// // // /// A double-precision floating point number that is the default value. // // public DefaultValueAttribute(double value) // // { // // defaultValue = value; // // } // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class using a 32-bit signed integer. // // /// // // /// A 32-bit signed integer that is the default value. // // public DefaultValueAttribute(int value) // // { // // defaultValue = value; // // } // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class using a 64-bit signed integer. // // /// // // /// A 64-bit signed integer that is the default value. // // public DefaultValueAttribute(long value) // // { // // defaultValue = value; // // } // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class using a 16-bit signed integer. // // /// // // /// A 16-bit signed integer that is the default value. // // public DefaultValueAttribute(short value) // // { // // defaultValue = value; // // } // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class using a single-precision floating point number. // // /// // // /// A single-precision floating point number that is the default value. // // public DefaultValueAttribute(System.Single value) // // { // // defaultValue = value; // // } // // // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class using a System.String. // // /// // // /// A System.String that is the default value. // // public DefaultValueAttribute(string value) // // { // // defaultValue = value; // // } // // // // /* // // /// // // /// Initializes a new instance of the System.ComponentModel.DefaultValueAttribute class, converting the specified value to the specified type, and using an invariant culture as the translation context. // // /// // // /// A System.Type that represents the type to convert the value to. // // /// A System.String that can be converted to the type using the System.ComponentModel.TypeConverter for the type and the U.S. English culture. // // public DefaultValueAttribute(System.Type type, string value) // // { // // //FIXME // // throw new NotImplementedException(); // // } // // */ // // } // // // //}