Exemple #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.StartObject)
            {
                JObject item = JObject.Load(reader);
                if (item["Args"] != null)
                {
                    var argsList = item["Args"].ToObject <IEnumerable <AxisMoveArgs> >(serializer);
                    var obj      = new MassMoveArgs(argsList)
                    {
                        LogicalMotionComponent    = item["LogicalMotionComponent"].Value <string>(),
                        HashStringInPresetProfile = item["HashString"].Value <string>()
                    };

                    return(obj);
                }
                else
                {
                    throw new JsonReaderException("the move args array can not be null.");
                }
            }
            else
            {
                throw new JsonReaderException("the token type is not StartObject.");
            }
        }
Exemple #2
0
        /// <summary>
        /// Convert the instance of MassMoveArgs to json string
        /// </summary>
        /// <param name="Arg">The instance of MassMovrArgs object</param>
        /// <returns></returns>
        public static string ToJsonString(MassMoveArgs Arg)
        {
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.Converters.Add(new MassMoveArgsJsonConverter());
            var json = JsonConvert.SerializeObject(Arg, settings);

            return(json);
        }