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