public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            var jobject = JObject.Load(reader);

            object resolvedType = null;

            JToken token;
            bool   gotVal = jobject.TryGetValue("kind", StringComparison.InvariantCultureIgnoreCase, out token);

            if (gotVal)
            {
                if (token.Value <string>().Equals("segment"))
                {
                    resolvedType = new Segment();
                }
                else
                {
                    resolvedType = new Ignorable();
                }
            }

            serializer.Populate(jobject.CreateReader(), resolvedType);

            return(resolvedType);
        }
 public void Ignorable(XlfEventArgs args)
 {
     if (args.NodeType.Equals("EndElement"))
     {
         stack.Pop();
     }
     else
     {
         Unit parent = stack.Peek() as Unit;
         if (parent != null)
         {
             Ignorable ignorable = new Ignorable();
             parent.Subunits.Add(ignorable);
             stack.Push(ignorable);
         }
         else
         {
             throw new Exception("Was expecting a Unit object.");
         }
     }
 }