Mercurial > hg > Database > jungle-sharp
changeset 32:07318c10b894
add getBytes method.
author | Kazuma Takeda |
---|---|
date | Fri, 20 Jan 2017 07:43:43 +0900 |
parents | 1466993c104c |
children | 56de71ae6f7e |
files | Main/jungle-main/core/Attributes.cs Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs |
diffstat | 2 files changed, 20 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/Main/jungle-main/core/Attributes.cs Fri Jan 20 07:08:03 2017 +0900 +++ b/Main/jungle-main/core/Attributes.cs Fri Jan 20 07:43:43 2017 +0900 @@ -2,5 +2,6 @@ public interface Attributes{ object get (string key); T get<T> (string key); + byte[] getBytes(string key); string getString (string key); }
--- a/Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs Fri Jan 20 07:08:03 2017 +0900 +++ b/Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs Fri Jan 20 07:43:43 2017 +0900 @@ -3,6 +3,8 @@ using System.Collections.Generic; using System; using System.Text; +using System.Runtime.Serialization.Formatters.Binary; +using System.IO; namespace JungleDB { public class DefaultTreeNodeAttribute : TreeNodeAttributes { @@ -68,6 +70,23 @@ return attrs.get(key).ToString(); } + /// <summary> + /// Gets the bytes. + /// need Serializable to class. + /// </summary> + /// <returns>byte[]</returns> + /// <param name="key">Key.</param> + public byte[] getBytes(string key) + { + var formatter = new BinaryFormatter(); + object source = attrs.get (key); + using (var stream = new MemoryStream()) + { + formatter.Serialize(stream, source); + return stream.ToArray(); + } + } + public IEnumerator<string> getKeys(){ return attrs.keys (); }