示例#1
0
        public DictionaryConverter(Type DictionaryType, bool KeyIgnoreCase = false)
        {
            this.IsIgnoreCase = KeyIgnoreCase;

            this.DictionaryType = DictionaryType;
            KeyType             = ObjectHelper.GetDictionaryKeyType(DictionaryType);
            ValueType           = ObjectHelper.GetDictionaryValueType(DictionaryType);

            KeyLength   = ConverterHelper.GetTypeLength(KeyType);
            Valuelength = ConverterHelper.GetTypeLength(ValueType);

            GetKeyObjectBytes = ConverterHelper.GetValueToBytes(KeyType);
            GetKeyObjectValue = ConverterHelper.GetBytesToValue(KeyType);

            GetValueObjectBytes = ConverterHelper.GetValueToBytes(ValueType);
            GetValueObjectValue = ConverterHelper.GetBytesToValue(ValueType);

            if (GetKeyObjectBytes == null || GetKeyObjectValue == null)
            {
                throw new Exception(KeyType.Name + " is not yet supported.");
            }

            if (GetValueObjectBytes == null || GetValueObjectValue == null)
            {
                throw new Exception(ValueType.Name + " is not yet supported.");
            }
        }
示例#2
0
        public object BytesToValue(string typename, byte[] ValueBytes)
        {
            if (ConverterHelper.TypeNameConverter.ContainsKey(typename))
            {
                var convert = ConverterHelper.TypeNameConverter[typename];
                return(convert(ValueBytes));
            }

            var type = TypeHelper.GetType(typename);

            if (type == null)
            {
                return(null);
            }

            var converter = ConverterHelper.GetBytesToValue(type);

            if (converter != null)
            {
                return(converter(ValueBytes));
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        public CollectionConverter(Type CollectionType)
        {
            this.CollectionType = CollectionType;
            this.DataType       = ObjectHelper.GetEnumberableType(CollectionType);

            this.FieldLength = ConverterHelper.GetTypeLength(this.DataType);

            this.GetObjectBytes = ConverterHelper.GetValueToBytes(this.DataType);
            this.GetObjectValue = ConverterHelper.GetBytesToValue(this.DataType);

            if (this.GetObjectBytes == null || this.GetObjectValue == null)
            {
                throw new Exception(this.DataType.Name + " is not yet supported.");
            }
        }