ValidatorContext.cs 954 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections.Generic;
  2. namespace Quadarax.Foundation.Core.Value
  3. {
  4. public class ValidatorContext
  5. {
  6. private readonly IDictionary<string, object> _context = new Dictionary<string, object>();
  7. public ValidatorContext()
  8. {
  9. }
  10. public ValidatorContext(IEnumerable<KeyValuePair<string,object>> initialContext)
  11. {
  12. if (initialContext != null)
  13. foreach (var item in initialContext)
  14. {
  15. _context.Add(item);
  16. }
  17. }
  18. public TValue GetValue<TValue>(string key)
  19. {
  20. return (TValue) _context[key];
  21. }
  22. public void SetValue<TValue>(string key, TValue value)
  23. {
  24. if (!_context.TryAdd(key, value))
  25. _context[key] = value;
  26. }
  27. public bool Exists(string key)
  28. {
  29. return _context.ContainsKey(key);
  30. }
  31. }
  32. }