Ejemplo n.º 1
0
 public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator locator)
 {
     Data.Branch result = new Data.Branch(data, type);
     foreach (Reflect.Field field in data.GetFields())
     {
         Uri.Locator l = locator.Copy();
         string name = field.Name.Convert(Casing.Camel, storage.Casing);
         l.Fragment = (l.Fragment.NotEmpty() ? l.Fragment + "." : "") + name;
         result.Nodes.Add(storage.Serialize(field.Type, field.Data, l).UpdateName(name));
     }
     return result;
 }
Ejemplo n.º 2
0
 public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator locator)
 {
     Data.Collection result = new Data.Collection(data, type);
     Reflect.Type elementType = this.GetElementType(type);
     int c = 0;
     foreach (object child in data as System.Collections.IEnumerable)
     {
         Uri.Locator l = null;
         if (locator.NotNull())
         {
             l = locator.Copy();
             l.Fragment = (l.Fragment.NotEmpty() ? l.Fragment + "/" : "") + (c++).ToString();
         }
         result.Nodes.Add(storage.Serialize(elementType, child, l));
     }
     return result;
 }
Ejemplo n.º 3
0
 public Data.Node Serialize(IStorage storage, Reflect.Type type, object data, Uri.Locator resource)
 {
     Data.Node result;
     Uri.Locator l = storage.Resolver.Update(data, resource);
     if (l.NotNull())
         result = new Data.Link(l);
     else
     {
         result = new Data.Branch(data, type);
         foreach (Reflect.Property property in data.GetProperties())
         {
             ParameterAttribute[] attributes = property.GetAttributes<ParameterAttribute>();
             if (attributes.Length == 1 && property.Data.NotNull())
             {
                 string name = attributes[0].Name ?? property.Name.Convert(Casing.Pascal, storage.Casing);
                 if (resource.NotNull())
                 {
                     l = resource.Copy();
                     l.Fragment = (l.Fragment.NotEmpty() ? l.Fragment + "/" : "") + name;
                 }
                 (result as Data.Branch).Nodes.Add(storage.Serialize(property.Type, property.Data, l).UpdateName(name).UpdateAttribute(attributes[0]).UpdateLocator(resource));
             }
         }
     }
     return result;
 }