public static void SetComplexObject <T>(object obj, string objName) { //Saving and retrieval of a single complex object var ser = new DataContractJsonSerializer(typeof(T)); var objJSON = string.Empty; using (var ms = new MemoryStream()) { ser.WriteObject(ms, obj); objJSON = Encoding.UTF8.GetString(ms.ToArray()); } RedisConnector.Set(objName, objJSON); }
public static void SetComplexList <T>(List <T> listobj, string objName) { List <string> lstStrJSON = new List <string>(); foreach (T obj in listobj) { var ser = new DataContractJsonSerializer(typeof(T)); var objJSON = string.Empty; using (var ms = new MemoryStream()) { ser.WriteObject(ms, obj); objJSON = Encoding.UTF8.GetString(ms.ToArray()); } lstStrJSON.Add(objJSON); } RedisConnector.Set(objName, lstStrJSON); }