diff Main/jungle-main/transaction/DefaultTreeNodeAttribute.cs @ 32:07318c10b894

add getBytes method.
author Kazuma Takeda
date Fri, 20 Jan 2017 07:43:43 +0900
parents 1466993c104c
children f2ea780b3e80
line wrap: on
line diff
--- 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 ();
 		}