PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/ResourceManagement.ObjectModel/RmBinary.cs

#
C# | 138 lines | 115 code | 20 blank | 3 comment | 24 complexity | 57a202320b66fdfc09a997ade1be3571 MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.Linq;
  4using System.Text;
  5
  6namespace Microsoft.ResourceManagement.ObjectModel
  7{
  8    public class RmBinary : IComparable, IComparable<RmBinary>
  9    {
 10        byte[] value;
 11        public RmBinary()
 12        {
 13            this.value = new byte[0];
 14        }
 15        public RmBinary(String value)
 16        {
 17            this.Value = value;
 18        }
 19        /// <summary>
 20        /// The string must be supported by the DateTime class
 21        /// </summary>
 22        public String Value
 23        {
 24            get
 25            {
 26                return this.ToString();
 27            }
 28            set
 29            {
 30                if (value != null)
 31                {
 32                    this.value = UnicodeEncoding.UTF8.GetBytes(value);
 33                }
 34                else
 35                {
 36                    this.value = new byte[0];
 37                }
 38            }
 39        }
 40
 41        public byte[] ValueAsBinary
 42        {
 43            get
 44            {
 45                return this.value;
 46            }
 47        }
 48
 49        public override bool Equals(object obj)
 50        {
 51            RmBinary other = obj as RmBinary;
 52            if (other as Object == null)
 53                return false;
 54            else
 55                return this.ToString().Equals(other.ToString());
 56        }
 57
 58        public override int GetHashCode()
 59        {
 60            return this.ToString().GetHashCode();
 61        }
 62
 63        public override string ToString()
 64        {
 65            return UnicodeEncoding.UTF8.GetString(this.value);
 66        }
 67
 68
 69
 70        #region IComparable Members
 71
 72        public int CompareTo(object obj)
 73        {
 74            if (obj as Object == null)
 75                throw new ArgumentNullException("obj");
 76            return this.CompareTo(obj as RmBinary);
 77        }
 78
 79        public static bool operator ==(RmBinary attrib1, RmBinary attrib2)
 80        {
 81            if (attrib1 as Object == null)
 82                return false;
 83            if (attrib2 as Object == null)
 84                return false;
 85            return attrib1.CompareTo(attrib2) == 0;
 86        }
 87
 88        public static bool operator !=(RmBinary attrib1, RmBinary attrib2)
 89        {
 90            if (attrib1 == null)
 91                return false;
 92            return attrib1.CompareTo(attrib2) != 0;
 93        }
 94
 95        public static bool operator <(RmBinary attrib1, RmBinary attrib2)
 96        {
 97            if (attrib1 == null)
 98                return false;
 99            return attrib1.CompareTo(attrib2) < 0;
100        }
101
102        public static bool operator >(RmBinary attrib1, RmBinary attrib2)
103        {
104            if (attrib1 == null)
105                return false;
106            return attrib1.CompareTo(attrib2) > 0;
107        }
108
109        public static bool operator <=(RmBinary attrib1, RmBinary attrib2)
110        {
111            if (attrib1 == null)
112                return false;
113            return attrib1.CompareTo(attrib2) <= 0;
114        }
115
116        public static bool operator >=(RmBinary attrib1, RmBinary attrib2)
117        {
118            if (attrib1 == null)
119                return false;
120            return attrib1.CompareTo(attrib2) >= 0;
121        }
122
123        #endregion
124
125        #region IComparable<RmDateTime> Members
126
127        public int CompareTo(RmBinary other)
128        {
129            if (other == null)
130                throw new ArgumentNullException("other");
131            else
132                return this.ToString().CompareTo(other.ToString());
133
134        }
135
136        #endregion
137    }
138}