Tag Archives: dictionary

MessagePack serialization error serializing Dictionary<object,object> to Json.Linq.JObject

Questions: Has anyone ever seen a message like this using MessagePack serialization? An exception of type ‘System.InvalidCastException’ occurred in mscorlib.dll but was not handled in user code Additional information: Unable to cast object of type ‘System.Collections.Generic.Dictionary`2[System.Object,System.Object]’ to type ‘Newtonsoft.Json.Linq.JObject’. My return type is Tuple<List<object>, MyEnum>. I’ve looked over my object graph and can’t see anything… Read More »

Programatically calling a method on a abstract class, which is stored in a dictionary?

Questions: Lets say I have a dictionary like this, it holds all the packet events. Events = new Dictionary<short, Func<ISession, IIncomingPacket, ICoreContext, Task>> { {IncomingPacketIds.HandshakeRequest, HandshakeRequest.Handle } }; Each packet files are all the same, as they follow the interface. public abstract class HandshakeRequest : IAsyncPacket { public async Task Handle(ISession session, IIncomingPacket packet, ICoreContext… Read More »

How to convert a dictionary into one condition

Questions: I have a method that I need to run only once. If a long condition is satisfied. For example: if (!(“a” == “a” && “b” == “b”)) RunMethod(); Main problem is that I can not know in advance how many keys a dictionary can have. And before what expression may or may not be… Read More »

In .Net framework how memory allocation happens in Dictionary? [on hold]

Questions: How does memory allocation happen in C# dictionary. Below is my dictionary. Dictionary<string, string> openWith = new Dictionary<string, string>(); openWith.Add(“txt”, “notepad.exe”); openWith.Add(“bmp”, “paint.exe”); openWith.Add(“dib”, “paint.exe”); If 4 values are in dictionary, so how these values are stored in memory (heap,stack or any other memory)? Answers:

GetHashCode for a class which contains a dictionary

Questions: I have a class that I need to override Equals and GetHashCode methods. The class contains a dictionary with a string key and SomeOtherClass value which, in turn, also has its own implementation of Equals and GetHashCode. public Dictionary<string, SomeOtherClass> MyDict { get; set; } My attempt to implement GetHashCode public override int GetHashCode()… Read More »