I'm using fluent validation API for writing validations.
I came across a internal set
property on ValidationContext
class.
public class ValidationContext {
public Dictionary<string, object> RootContextData { get; internal set; } = new Dictionary<string, object>();
}
I came across the internal set property in this question. So, I can set the value of a dictionary like this
var rowItemContext = new ValidationContext();
rowItemContext.RootContextData.Add("ab", new object());//this works
The above code to add an item to the RootcontextData
works.
But the following line to directly assign another dictionary to RootContextData results in an compile time error.
Property or indexer 'ValidationContext.RootContextData' cannot be assigned to -- it is read only
rowItemContext.RootContextData = new Dictionary<string, object>()
{
{ "ab", new object() }
};
So, to add a dictionary of items to context data I have to loop over the dictionary to add. I'm surprised to see why the first one works but not the direct assignment.