Exemplo n.º 1
0
        async Task RetrieveDirect(byte[] start, byte[] end, TypedRetrieveCallback <TableRow> callback)
        {
            await db.Retrieve(start, end, elems => {
                return(callback(elems.Select(m => {
                    byte[] newkey = new byte[m.Key.Length - tableName.Length];
                    Buffer.BlockCopy(m.Key, tableName.Length, newkey, 0, newkey.Length);
                    m.Key = newkey;

                    TableRow retval = new TableRow();
                    BinaryReader mreader = new BinaryReader(new MemoryStream(m.Value));
                    retval.Key = m.Key;
                    while (mreader.BaseStream.Position != mreader.BaseStream.Length)
                    {
                        retval[mreader.ReadNullTerminatedString()] = DataFormats.Deserialize(mreader);
                    }
                    return retval;
                })));
            });
        }
Exemplo n.º 2
0
        public T As <T>() where T : class, new()
        {
            T   retval    = new T();
            var keyFields = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).Where(m => m.CustomAttributes.Where(a => a.AttributeType == typeof(KeyAttribute)).Any() || m.Name == "Key");

            if (!keyFields.Any())
            {
                throw new InvalidCastException("Type " + typeof(T).Name + " does not have a Key property. Please declare a Key property.");
            }
            var keyField = keyFields.First();

            keyField.SetValue(retval, keyField.PropertyType == typeof(byte[]) ? Key : DataFormats.Deserialize(Key));
            foreach (var iable in keys)
            {
                var prop = typeof(T).GetProperty(iable.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                prop?.SetValue(retval, iable.Value);
            }
            return(retval);
        }