Exemple #1
0
        public List <BlendValueCapsule> DereferenceAll(IBlendType type)
        {
            if (!CanDereference(type))
            {
                return(null);
            }

            var result = new List <BlendValueCapsule>();

            try
            {
                int        offset = (int)m_address;
                IBlendType realType;
                using (var reader = new BinaryReader(m_mapper.GetStreamFromAddress(m_address, out realType)))
                {
                    type            = realType != null ? realType : type;         // if the given type is not equals to the real stored type, we belieave the real stored type.
                    result.Capacity = (int)reader.BaseStream.Length / type.SizeOf();
                    var context = new ReadValueContext()
                    {
                        reader = reader, mapper = m_mapper
                    };
                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        var val = type.ReadValue(context);
                        result.Add(val);
                    }
                }
            }
            catch (Exception e)
            {
                throw new BlenderException("Failed to dereference {0} as {1}", AddressString, type.Name);
            }

            return(result);
        }
Exemple #2
0
        public BlendValueCapsule DereferenceOne(IBlendType type)
        {
            if (!CanDereference(type))
            {
                return(null);
            }

            BlendValueCapsule result = null;

            try
            {
                int        offset = (int)m_address;
                IBlendType realType;
                using (var reader = new BinaryReader(m_mapper.GetStreamFromAddress(m_address, out realType)))
                {
                    var context = new ReadValueContext()
                    {
                        reader = reader, mapper = m_mapper
                    };
                    result = type.ReadValue(context);
                }
            }
            catch (Exception e)
            {
                throw new BlenderException("Failed to dereference {0} as {1}", AddressString, type.Name);
            }

            return(result);
        }
Exemple #3
0
        /// <summary>
        /// Read value corresponded this type from binary
        /// </summary>
        /// <param name="context">variable for making a value</param>
        /// <returns>value</returns>
        /// <seealso cref="IBlendType.ReadValue"/>
        public virtual BlendValueCapsule ReadValue(ReadValueContext context)
        {
            object obj = null;

            switch (ArrayDimension)
            {
            case 1:
            {
                var objs = new BlendValueCapsule[m_dimCountArray[0]];
                for (int i = 0; i < m_dimCountArray[0]; ++i)
                {
                    objs[i] = m_baseType.ReadValue(context);
                }
                obj = objs;
            }
            break;

            case 2:
            {
                var objs = new object[m_dimCountArray[0]];

                for (int i = 0; i < m_dimCountArray[0]; ++i)
                {
                    var tmp = new BlendValueCapsule[m_dimCountArray[1]];
                    for (int j = 0; j < m_dimCountArray[1]; ++j)
                    {
                        tmp[j] = m_baseType.ReadValue(context);
                    }

                    objs[i] = tmp;
                }
                obj = objs;
            }
            break;
            }

            return(new _BlendValueCapsule(this, obj));
        }