示例#1
0
        internal EnumValue(AdsEnumInfoEntry entry)
        {
            this._name = entry.name;
            this._size = entry.value.Length;
            Type type = typeof(T);

            if (type == typeof(byte))
            {
                this._value = (T)Convert.ChangeType(entry.value[0], typeof(byte), CultureInfo.InvariantCulture);
            }
            else if (type == typeof(sbyte))
            {
                this._value = (T)Convert.ChangeType((sbyte)entry.value[0], typeof(sbyte), CultureInfo.InvariantCulture);
            }
            else if (type == typeof(short))
            {
                short num = BitConverter.ToInt16(entry.value, 0);
                this._value = (T)Convert.ChangeType(num, typeof(T), CultureInfo.InvariantCulture);
            }
            else if (type == typeof(ushort))
            {
                ushort num2 = BitConverter.ToUInt16(entry.value, 0);
                this._value = (T)Convert.ChangeType(num2, typeof(T), CultureInfo.InvariantCulture);
            }
            else if (type == typeof(int))
            {
                int num3 = BitConverter.ToInt32(entry.value, 0);
                this._value = (T)Convert.ChangeType(num3, typeof(T), CultureInfo.InvariantCulture);
            }
            else if (type == typeof(uint))
            {
                uint num4 = BitConverter.ToUInt32(entry.value, 0);
                this._value = (T)Convert.ChangeType(num4, typeof(T), CultureInfo.InvariantCulture);
            }
            else if (type == typeof(long))
            {
                long num5 = BitConverter.ToInt64(entry.value, 0);
                this._value = (T)Convert.ChangeType(num5, typeof(T), CultureInfo.InvariantCulture);
            }
            else
            {
                if (type != typeof(ulong))
                {
                    throw new ArgumentException("Wrong Enum base type.");
                }
                ulong num6 = BitConverter.ToUInt64(entry.value, 0);
                this._value = (T)Convert.ChangeType(num6, typeof(T), CultureInfo.InvariantCulture);
            }
        }
示例#2
0
        internal static IEnumValue Create(AdsDatatypeId baseTypeId, AdsEnumInfoEntry enumInfo)
        {
            if (enumInfo == null)
            {
                throw new ArgumentNullException("entry");
            }
            if (baseTypeId == AdsDatatypeId.ADST_INT16)
            {
                return(new EnumValue <short>(enumInfo));
            }
            if (baseTypeId == AdsDatatypeId.ADST_INT32)
            {
                return(new EnumValue <int>(enumInfo));
            }
            switch (baseTypeId)
            {
            case AdsDatatypeId.ADST_INT8:
                return(new EnumValue <sbyte>(enumInfo));

            case AdsDatatypeId.ADST_UINT8:
                return(new EnumValue <byte>(enumInfo));

            case AdsDatatypeId.ADST_UINT16:
                return(new EnumValue <ushort>(enumInfo));

            case AdsDatatypeId.ADST_UINT32:
                return(new EnumValue <uint>(enumInfo));

            case AdsDatatypeId.ADST_INT64:
                return(new EnumValue <long>(enumInfo));

            case AdsDatatypeId.ADST_UINT64:
                return(new EnumValue <ulong>(enumInfo));
            }
            throw new ArgumentOutOfRangeException("baseTypeId");
        }