var commandData = new JObject();foreach (System.Reflection.PropertyInfo p in data.GetType().GetProperties()){ if (p.GetValue(data) != null) { commandData.Add(new JProperty(p.Name, p.GetValue(data))); }}