Okay. I know it is a long time after I asked this question. But we solved this.
We used BinaryFormatter Serializer which essentially converts the .NET object into a memory map and serializes it as a binary array. This memory map can be used to recreate the original object without public default constructors.
This BinaryFormatter serialization is supported by .NET from early versions.
The downside to this approach is that we have to manually go to every class in the object hierarchy and give Serializable Attribute decoration to the class.
Another downside is that only the properties that hold a non-null value get serialized.
This means, If none of your unit tests initialize some or any property of the object being serialized, there is a great chance we may hit a runtime Serialization Exception, which can be easily solved by decoration the type Serializable
We may also be able to use, other serialization formats like MsgPack etc.
public class TheTypeToBeCached
{
public OneSubType Property1 {get;set;}
public SecondSubType Property2 {get;set;}
}
public class OneSubType
{
public ThirdSubType Property3 {get;set;}
public ForthSubType Property4 {get;set;}
public AnotherSubType Property5 {get;set;}
}
public class SecondSubType
{
public ForthSubType Property6 {get;set;}
public AnotherSubType Property7 {get;set;}
}
public class ThridSubType
{
public SecondSubType Property8{get;set;}
}
public class ForthSubType
{
public SecondSubType Property9{get;set;}
}
public class AnotherSubType
{
public OneSubType Property10{get;set;}
}
The above hierarchy can be Serialized and deserialzed using BinaryFormatter Serializer even if it has multiple round relationships.
[Serializable]
public class TheTypeToBeCached
{
public OneSubType Property1 {get;set;}
public SecondSubType Property2 {get;set;}
}
[Serializable]
public class OneSubType
{
public ThirdSubType Property3 {get;set;}
public ForthSubType Property4 {get;set;}
public AnotherSubType Property5 {get;set;}
}
[Serializable]
public class SecondSubType
{
public ForthSubType Property6 {get;set;}
public AnotherSubType Property7 {get;set;}
}
[Serializable]
public class ThridSubType
{
public SecondSubType Property8{get;set;}
}
[Serializable]
public class ForthSubType
{
public SecondSubType Property9{get;set;}
}
[Serializable]
public class AnotherSubType
{
public OneSubType Property10{get;set;}
}
somethinghas to convert your object to a redis string