On 4/12/2010 8:31 PM, Jb Evain wrote: > Hey folks, > > You can read about the development of the new version of Mono.Cecil there: > > http://evain.net/blog/articles/2010/04/12/mono-cecil-0-9-cecil-light > > Thanks to everyone on the list for their past and future > contributions. I'm looking forward your feedback on this version. > >
The new Cecil version looks interesting.
I'm currently trying to upgrade SharpDevelop 4.0 to use Cecil 0.9.
Could you please clarify in the migration guide: what happened to
MethodDefinition.This?
And was "Sequence" really always 1-based, or just for instance methods
(HasThis=true)?
Also, here's a method you could use to implement GetAllTypes (not really
less convoluted than using SelectMany with an Y-combinator, but at least
more efficient):
/// <summary>
/// Converts a recursive data structure into a flat list.
/// </summary>
/// <param name="input">The root elements of the recursive data
structure.</param>
/// <param name="recursion">The function that gets the children of an
element.</param>
/// <returns>Iterator that enumerates the tree structure in
preorder.</returns>
public static IEnumerable<T> Flatten<T>(this IEnumerable<T> input,
Func<T, IEnumerable<T>> recursion)
{
Stack<IEnumerator<T>> stack = new Stack<IEnumerator<T>>();
try {
stack.Push(input.GetEnumerator());
while (stack.Count > 0) {
while (stack.Peek().MoveNext()) {
T element = stack.Peek().Current;
yield return element;
IEnumerable<T> children = recursion(element);
if (children != null) {
stack.Push(children.GetEnumerator());
}
}
stack.Pop().Dispose();
}
} finally {
while (stack.Count > 0) {
stack.Pop().Dispose();
}
}
}
Daniel
signature.asc
Description: OpenPGP digital signature
