public int Marshal(IAttributedInstance symbol, object val, byte[] bValue, int offset)
        {
            Encoding encoding = null;

            EncodingAttributeConverter.TryGetEncoding(symbol.Attributes, out encoding);
            return(this.Marshal(symbol.DataType, encoding, val, bValue, offset));
        }
        internal int Unmarshal(IAttributedInstance symbol, Type targetType, byte[] data, int offset, out object value)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            int byteSize = 0;

            if (targetType.IsValueType)
            {
                object obj2;
                byteSize = this._internalConverter.Unmarshal(symbol, data, offset, out obj2);
                value    = PrimitiveTypeConverter.Convert(obj2, targetType);
            }
            else
            {
                value = this.createValue(symbol.DataType, targetType);
                this.InitializeInstanceValue(symbol, ref value, data, offset);
                byteSize = symbol.ByteSize;
            }
            return(byteSize);
        }
 public byte[] Marshal(IAttributedInstance symbol, object value)
 {
     byte[] bValue = new byte[symbol.ByteSize];
     this.CheckType(symbol.DataType, value.GetType());
     this.Marshal(symbol, value, bValue, 0);
     return(bValue);
 }
        internal void InitializeInstanceValue(IAttributedInstance symbol, ref object targetInstance, byte[] data, int offset)
        {
            Encoding encoding = null;

            EncodingAttributeConverter.TryGetEncoding(symbol.Attributes, out encoding);
            this.InitializeInstanceValue(symbol.DataType, encoding, ref targetInstance, data, offset);
        }
        public int Unmarshal(IAttributedInstance symbol, byte[] data, int offset, out object value)
        {
            Type managed = null;

            if (!this.TryGetManagedType(symbol.DataType, out managed))
            {
                throw new NotSupportedException();
            }
            return(this.Unmarshal(symbol, managed, data, offset, out value));
        }
示例#6
0
        public bool TryGetManagedType(IAttributedInstance symbol, out Type managed)
        {
            IDataType       dataType = symbol.DataType;
            IResolvableType type2    = symbol.DataType as IResolvableType;

            if (type2 != null)
            {
                dataType = type2.ResolveType(DataTypeResolveStrategy.AliasReference);
            }
            return(this._typeMarshaller.TryGetManagedType(dataType, out managed));
        }
示例#7
0
        private bool TryGetEncoding(IAttributedInstance symbol, out Encoding encoding)
        {
            bool flag = EncodingAttributeConverter.TryGetEncoding(symbol.Attributes, out encoding);

            if (!flag && (symbol.DataType.Category == DataTypeCategory.String))
            {
                IStringType dataType = (IStringType)symbol.DataType;
                encoding = dataType.Encoding;
                flag     = true;
            }
            return(flag);
        }
示例#8
0
        public int Unmarshal(IAttributedInstance symbol, byte[] data, int offset, out object value)
        {
            Encoding encoding = null;

            EncodingAttributeConverter.TryGetEncoding(symbol.Attributes, out encoding);
            IDataType       dataType = symbol.DataType;
            IResolvableType type2    = symbol.DataType as IResolvableType;

            if (type2 != null)
            {
                dataType = type2.ResolveType(DataTypeResolveStrategy.AliasReference);
            }
            return(this._typeMarshaller.Unmarshal(dataType, encoding, data, offset, out value));
        }
示例#9
0
        public byte[] Marshal(IAttributedInstance symbol, object value)
        {
            Encoding encoding = null;

            this.TryGetEncoding(symbol, out encoding);
            IDataType       dataType = symbol.DataType;
            IResolvableType type2    = symbol.DataType as IResolvableType;

            if (type2 != null)
            {
                dataType = type2.ResolveType(DataTypeResolveStrategy.AliasReference);
            }
            return(this._typeMarshaller.Marshal(dataType, encoding, value));
        }
示例#10
0
        public int MarshalSize(IAttributedInstance symbol, object value)
        {
            Type             type     = value.GetType();
            DataTypeCategory category = symbol.DataType.Category;

            if (category != DataTypeCategory.Primitive)
            {
                if (category == DataTypeCategory.Alias)
                {
                    return(this._internalConverter.MarshalSize(symbol, value));
                }
                else if (category != DataTypeCategory.String)
                {
                    return(symbol.ByteSize);
                }
            }
            return(this._internalConverter.MarshalSize(symbol, value));
        }
示例#11
0
 public bool TryGetManagedType(IAttributedInstance symbol, out Type managed) =>
 this._internalConverter.TryGetManagedType(symbol, out managed);