예제 #1
0
        private EsentRow RetrieveColumns(EsentCell[] columnArray)
        {
            var cells = new EsentRow();

            foreach (var column in columnArray)
            {
                var columnName = column.ColumnName;
                var encoding   = column.Encoding ?? Columns[column.ColumnName].Encoding;
                var type       = Columns[columnName].ColumnType;
                var bytes      = Api.RetrieveColumn(Database.Session.JetId, JetId, Columns[columnName].JetId);
                var value      = ValueProcessor.FromBytes(type, bytes, encoding);
                cells.Add(new EsentCell(columnName, value, encoding));
            }
            return(cells);
        }
예제 #2
0
        public static T Deserialize <T>(EsentRow r) where T : new()
        {
            var obj   = new T();
            var type  = typeof(T);
            var props = type.GetRuntimeProperties();

            foreach (var cell in r)
            {
                var prop = props.FirstOrDefault(p => p.Name == cell.ColumnName);
                if (prop == null)
                {
                    continue;
                }
                if (cell.Value?.GetType() == prop.PropertyType)
                {
                    prop.SetValue(obj, cell.Value);
                }
                if (cell.Value?.GetType() == typeof(byte[]) && prop.PropertyType != typeof(byte[]))
                {
                    prop.SetValue(obj, ValueProcessor.FromBytes(prop.PropertyType, cell.AsByteArray, cell.Encoding));
                }
            }
            return(obj);
        }