Esempio n. 1
0
        private SwitchCase ProcessNode(DeserializerTypeContext parentCtx, UnknownTypeNode node)
        {
            var ctx = new DeserializerTypeContext
              {
            Type = node.Member.PropertyOrFieldType
              };

              InitializeVars(ctx);

              var @switch = GetSwitchStatement(ctx, node.Children);

              ctx.BlockInsideLoop = GetInnerLoopTemplate(ctx, @switch);

              var lambda = GetTemplate(ctx);

              var del = CompileExpression(node.Type, lambda);

              _treeBuilder.AddKnownType(node.Type, del);

              return GetKnownTypeSwitchCase(parentCtx, del.Method, node);
        }
Esempio n. 2
0
        private Node GetDeserializationNode(PropertyOrFieldInfo member)
        {
            Func<PropertyOrFieldInfo, Node> nodeFunc;

              if (!_deserializers.TryGetValue(member.PropertyOrFieldType, out nodeFunc))
              {
            var key = _deserializers.Keys.FirstOrDefault(k => k.IsAssignableFrom(member.PropertyOrFieldType));

            if (key != null)
            {
              nodeFunc = _deserializers[key];
            }
            else
            {
              key = _deserializers.Keys.FirstOrDefault(k => member.PropertyOrFieldType.IsAssignableFrom(k));

              if (key != null)
              {
            nodeFunc = _deserializers[key];
              }

            }

              }

              Node node;

              if (nodeFunc != null)
              {
            node = nodeFunc(member);
              }
              else if (_recursionStack.Contains(member.PropertyOrFieldType))
              {
            node = new RecursionNode
            {
              Type = member.PropertyOrFieldType,
              Member = member
            };
              }
              else
              {
            var customNode = new UnknownTypeNode
            {
              Type = member.PropertyOrFieldType,
              Member = member,
              Children = new List<Node>()
            };

            var members = GetMembers(member.PropertyOrFieldType);

            foreach (var childMember in members)
            {
              var childNode = GetDeserializationNode(childMember);
              customNode.Children.Add(childNode);
            }

            node = customNode;

              }

              return node;
        }