Browse Source

Use a property to return the list of annotations.

This makes debugging annotations easier, as properties can be evaluated in the debugger.
newNRvisualizers
Daniel Grunwald 15 years ago
parent
commit
9974734473
  1. 42
      ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs

42
ICSharpCode.NRefactory/CSharp/Ast/AstNode.cs

@ -537,51 +537,25 @@ namespace ICSharpCode.NRefactory.CSharp
return null; return null;
} }
public IEnumerable<T> Annotations<T>() where T: class /// <summary>
{ /// Gets all annotations stored on this AstNode.
object annotations = this.annotations; /// </summary>
AnnotationList list = annotations as AnnotationList; public IEnumerable<object> Annotations {
if (list != null) { get {
List<T> result = new List<T>();
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<T>();
}
}
public IEnumerable<object> Annotations(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
object annotations = this.annotations; object annotations = this.annotations;
AnnotationList list = annotations as AnnotationList; AnnotationList list = annotations as AnnotationList;
if (list != null) { if (list != null) {
List<object> result = new List<object>();
lock (list) { lock (list) {
foreach (object obj in list) { return list.ToArray();
if (type.IsInstanceOfType(obj))
result.Add(obj);
}
} }
return result;
} else { } else {
if (type.IsInstanceOfType(annotations)) if (annotations != null)
return new object[] { annotations }; return new object[] { annotations };
else else
return Enumerable.Empty<object>(); return Enumerable.Empty<object>();
} }
} }
}
#endregion #endregion
public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data); public abstract S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data);

Loading…
Cancel
Save