I am dealing to store data in azure queue storage and for that currently i have 2 data types classes as below
[Serializable]
public class Task1Item
{
public int ID { get; set; }
public string Company { get; set; }
------
------
}
[Serializable]
public class Task2Item
{
public int ID { get; set; }
public string connectTo{ get; set; }
public string Port{ get; set; }
------
------
}
and for inserting record to queue i am using below methods
// For Task1Item
CloudQueueMessage msg = new CloudQueueMessage(item1.ToBinary<Task1Item>());
// For Task2Item
CloudQueueMessage msg = new CloudQueueMessage(item2.ToBinary<Task2Item>());
and i need to read from different queues
var item1 = cloudQueueMessage1.FromMessage<Task1Item>();
var item2 = cloudQueueMessage2.FromMessage<Task2Item>();
Here i would like to use only 1 queue storage (as there will be more taskitem) so can any one please suggest me how can i combine different types to one type of object?
Note: ToBinary & FromMessage are simple extensions
public static byte[] ToBinary<T>(this T dns)
{
var binaryFormatter = new BinaryFormatter();
byte[] bytes = null;
using (var memoryStream = new MemoryStream())
{
binaryFormatter.Serialize(memoryStream, dns);
bytes = memoryStream.GetBuffer();
}
return bytes;
}
public static T FromMessage<T>(this CloudQueueMessage cloudQueueMessage)
{
var bytes = cloudQueueMessage.AsBytes;
using (var memoryStream = new MemoryStream(bytes))
{
var binaryFormatter = new BinaryFormatter();
return (T)binaryFormatter.Deserialize(memoryStream);
}
}
Thanks.