comparison 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
comparison
equal deleted inserted replaced
31:1466993c104c 32:07318c10b894
1 using UnityEngine; 1 using UnityEngine;
2 using System.Collections; 2 using System.Collections;
3 using System.Collections.Generic; 3 using System.Collections.Generic;
4 using System; 4 using System;
5 using System.Text; 5 using System.Text;
6 using System.Runtime.Serialization.Formatters.Binary;
7 using System.IO;
6 8
7 namespace JungleDB { 9 namespace JungleDB {
8 public class DefaultTreeNodeAttribute : TreeNodeAttributes { 10 public class DefaultTreeNodeAttribute : TreeNodeAttributes {
9 public List<TreeNode> children; 11 public List<TreeNode> children;
10 public TreeMap<string, object> attrs; 12 public TreeMap<string, object> attrs;
66 68
67 public string getString(string key) { 69 public string getString(string key) {
68 return attrs.get(key).ToString(); 70 return attrs.get(key).ToString();
69 } 71 }
70 72
73 /// <summary>
74 /// Gets the bytes.
75 /// need Serializable to class.
76 /// </summary>
77 /// <returns>byte[]</returns>
78 /// <param name="key">Key.</param>
79 public byte[] getBytes(string key)
80 {
81 var formatter = new BinaryFormatter();
82 object source = attrs.get (key);
83 using (var stream = new MemoryStream())
84 {
85 formatter.Serialize(stream, source);
86 return stream.ToArray();
87 }
88 }
89
71 public IEnumerator<string> getKeys(){ 90 public IEnumerator<string> getKeys(){
72 return attrs.keys (); 91 return attrs.keys ();
73 } 92 }
74 93
75 } 94 }