SqlNodeAnnotations.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace System.Data.Linq.SqlClient {
  5. /// <summary>
  6. /// Associate annotations with SqlNodes.
  7. /// </summary>
  8. internal class SqlNodeAnnotations {
  9. Dictionary<SqlNode, List<SqlNodeAnnotation>> annotationMap = new Dictionary<SqlNode, List<SqlNodeAnnotation>>();
  10. Dictionary<Type, string> uniqueTypes = new Dictionary<Type, string>();
  11. /// <summary>
  12. /// Add an annotation to the given node.
  13. /// </summary>
  14. internal void Add(SqlNode node, SqlNodeAnnotation annotation) {
  15. List<SqlNodeAnnotation> list = null;
  16. if (!this.annotationMap.TryGetValue(node, out list)) {
  17. list = new List<SqlNodeAnnotation>();
  18. this.annotationMap[node]=list;
  19. }
  20. uniqueTypes[annotation.GetType()] = String.Empty;
  21. list.Add(annotation);
  22. }
  23. /// <summary>
  24. /// Gets the annotations for the given node. Null if none.
  25. /// </summary>
  26. internal List<SqlNodeAnnotation> Get(SqlNode node) {
  27. List<SqlNodeAnnotation> list = null;
  28. this.annotationMap.TryGetValue(node, out list);
  29. return list;
  30. }
  31. /// <summary>
  32. /// Whether the given node has annotations.
  33. /// </summary>
  34. internal bool NodeIsAnnotated(SqlNode node) {
  35. if (node == null)
  36. return false;
  37. return this.annotationMap.ContainsKey(node);
  38. }
  39. /// <summary>
  40. /// Checks whether there's at least one annotation of the given type.
  41. /// </summary>
  42. internal bool HasAnnotationType(Type type) {
  43. return this.uniqueTypes.ContainsKey(type);
  44. }
  45. }
  46. }