Esempio n. 1
0
        public HashEnumDataProvider(object value)
        {
            Type t = value.GetType();

            if (!t.IsEnum)
            {
                throw new ArgumentException("HashEnumDataProvider only support enum types");
            }

            Type baseType = Enum.GetUnderlyingType(t);

            ConstructorInfo ctorInfo = typeof(HashPrimitiveDataProvider).GetConstructor(new Type[] { baseType });

            if (ctorInfo == null)
            {
                throw new ArgumentException("Cannot find HashPrimitiveDataProvider with appropriate ctor");
            }

            if (baseType == typeof(uint))
            {
                _subDataProvider = (HashPrimitiveDataProvider)ctorInfo.Invoke(new object[] { (uint)value });
            }
            else if (baseType == typeof(ushort))
            {
                _subDataProvider = (HashPrimitiveDataProvider)ctorInfo.Invoke(new object[] { (ushort)value });
            }
            else if (baseType == typeof(byte))
            {
                _subDataProvider = (HashPrimitiveDataProvider)ctorInfo.Invoke(new object[] { (byte)value });
            }
            else
            {
                throw new ArgumentException("Type not supported");
            }
        }
        public HashEnumDataProvider(object value)
        {
            Type t = value.GetType ();

            if (!t.IsEnum)
                throw new ArgumentException ("HashEnumDataProvider only support enum types");

            Type baseType = Enum.GetUnderlyingType(t);

            ConstructorInfo ctorInfo = typeof(HashPrimitiveDataProvider).GetConstructor (new Type[] { baseType });

            if (ctorInfo == null)
                throw new ArgumentException ("Cannot find HashPrimitiveDataProvider with appropriate ctor");

            if(baseType == typeof(uint))
                _subDataProvider = (HashPrimitiveDataProvider)ctorInfo.Invoke (new object[] { (uint)value });
            else if(baseType == typeof(ushort))
                _subDataProvider = (HashPrimitiveDataProvider)ctorInfo.Invoke (new object[] { (ushort)value });
            else if(baseType == typeof(byte))
                _subDataProvider = (HashPrimitiveDataProvider)ctorInfo.Invoke (new object[] { (byte)value });
            else
                throw new ArgumentException("Type not supported");
        }