From 9974734473dffd687f639a2a876b22a22d44e8ec Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 14 Mar 2011 23:42:06 +0100 Subject: [PATCH] Use a property to return the list of annotations. This makes debugging annotations easier, as properties can be evaluated in the debugger. --- ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs | 56 ++++++-------------- 1 file changed, 15 insertions(+), 41 deletions(-) diff --git a/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs b/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs index dafcdc2533..8264bdc9d2 100644 --- a/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs @@ -537,49 +537,23 @@ namespace ICSharpCode.NRefactory.CSharp return null; } - public IEnumerable Annotations() where T: class - { - object annotations = this.annotations; - AnnotationList list = annotations as AnnotationList; - if (list != null) { - List result = new List(); - lock (list) { - foreach (object obj in list) { - T t = obj as T; - if (t != null) - result.Add(t); - } - } - return result; - } else { - T t = annotations as T; - if (t != null) - return new T[] { t }; - else - return Enumerable.Empty(); - } - } - - public IEnumerable Annotations(Type type) - { - if (type == null) - throw new ArgumentNullException("type"); - object annotations = this.annotations; - AnnotationList list = annotations as AnnotationList; - if (list != null) { - List result = new List(); - lock (list) { - foreach (object obj in list) { - if (type.IsInstanceOfType(obj)) - result.Add(obj); + /// + /// Gets all annotations stored on this AstNode. + /// + public IEnumerable Annotations { + get { + object annotations = this.annotations; + AnnotationList list = annotations as AnnotationList; + if (list != null) { + lock (list) { + return list.ToArray(); } + } else { + if (annotations != null) + return new object[] { annotations }; + else + return Enumerable.Empty(); } - return result; - } else { - if (type.IsInstanceOfType(annotations)) - return new object[] { annotations }; - else - return Enumerable.Empty(); } } #endregion