示例#1
0
        private static BinaryNode CreateHierarchy(List <IByteSerializable> traversed, IByteSerializable obj)
        {
            if (traversed.Contains(obj))
            {
                return(null);
            }

            traversed.Add(obj);

            var node       = new BinaryNode(obj);
            var childNodes = new List <BinaryNode>();

            var children = obj
                           .GetType()
                           .GetProperties()
                           .Where(x => !x.PropertyType.IsPrimitive)
                           .Select(x => x.GetValue(obj))
                           .Where(x => x != null);

            //.OfType<IByteSerializable>()
            //.ToArray();

            foreach (var c in children)
            {
                IByteSerializable bs = c as IByteSerializable;

                if (bs != null)
                {
                    childNodes.Add(CreateHierarchy(traversed, bs));
                }

                var items = c as IEnumerable <IByteSerializable>;

                if (items != null)
                {
                    childNodes.AddRange(
                        items
                        .Where(x => x != null)
                        .Select(x => CreateHierarchy(traversed, x)));
                }
            }

            node.Children = childNodes;

            return(node);
        }
 public BinaryNode(IByteSerializable structure)
     : this()
 {
     Structure = structure;
     var order = 0;
     Fields = structure
         .GetType()
         .GetProperties()
         .Where<ByteFieldAttribute>()
         .OrderBy(x => x.Attribute.Order)
         .Select(x => new BinaryNameValuePair
         {
             Order = ++order,
             Name = x.Property.Name,
             Type = x.Property.PropertyType.Name.SubstringAtIndexOf('.', 1),
             Value = x.Property.GetValue(structure),
         })
         .ToArray();
 }
示例#3
0
        public BinaryNode(IByteSerializable structure)
            : this()
        {
            Structure = structure;
            var order = 0;

            Fields = structure
                     .GetType()
                     .GetProperties()
                     .Where <ByteFieldAttribute>()
                     .OrderBy(x => x.Attribute.Order)
                     .Select(x => new BinaryNameValuePair
            {
                Order = ++order,
                Name  = x.Property.Name,
                Type  = x.Property.PropertyType.Name.SubstringAtIndexOf('.', 1),
                Value = x.Property.GetValue(structure),
            })
                     .ToArray();
        }
        private static BinaryNode CreateHierarchy(List<IByteSerializable> traversed, IByteSerializable obj)
        {
            if (traversed.Contains(obj))
            {
                return null;
            }

            traversed.Add(obj);

            var node = new BinaryNode(obj);
            var childNodes = new List<BinaryNode>();

            var children = obj
                .GetType()
                .GetProperties()
                .Where(x => !x.PropertyType.IsPrimitive)
                .Select(x => x.GetValue(obj))
                .Where(x => x != null);
            //.OfType<IByteSerializable>()
            //.ToArray();

            foreach (var c in children)
            {
                IByteSerializable bs = c as IByteSerializable;

                if (bs != null)
                {
                    childNodes.Add(CreateHierarchy(traversed, bs));
                }

                var items = c as IEnumerable<IByteSerializable>;

                if (items != null)
                {
                    childNodes.AddRange(
                        items
                            .Where(x => x != null)
                            .Select(x => CreateHierarchy(traversed, x)));
                }
            }

            node.Children = childNodes;

            return node;
        }