How to properly diagram lambda expressions or traversals through them in Architecture Explorer?
Posted
by
MainMa
on Programmers
See other posts from Programmers
or by MainMa
Published on 2013-03-05T01:55:57Z
Indexed on
2013/07/03
5:18 UTC
Read the original article
Hit count: 359
I'm exploring a piece of code in Architecture Explorer in Visual Studio 2010 to study the relations between methods. I noticed a strange behavior.
Take the following source code. It generates a hello message based on a template and a template engine, the template engine being a method (a sort of strategy pattern simplified at a maximum for demo purposes).
public string GenerateHelloMessage(string personName)
{
return this.ApplyTemplate(
this.DefaultTemplateEngine, this.GenerateLocalizedHelloTemplate(), personName);
}
private string GenerateLocalizedHelloTemplate()
{
return "Hello {0}!";
}
public string ApplyTemplate(
Func<string, string, string> templateEngine, string template, string personName)
{
return templateEngine(template, personName);
}
public string DefaultTemplateEngine(string template, string personName)
{
return string.Format(template, personName);
}
The graph generated from this code is this one:
Change the first method from this:
public string GenerateHelloMessage(string personName)
{
return this.ApplyTemplate(
this.DefaultTemplateEngine, this.GenerateLocalizedHelloTemplate(), personName);
}
to this:
public string GenerateHelloMessage(string personName)
{
return this.ApplyTemplate(
(a, b) => this.DefaultTemplateEngine(a, b),
this.GenerateLocalizedHelloTemplate(), personName);
}
and the graph becomes:
While semantically identical, those two versions of code produce different dependency graphs, and Architecture Explorer shows no trace of the lambda expression (while Visual Studio's code coverage, for example, shows them, as well as Code analysis seems to be able to understand that the link exists).
How would it be possible, without changing the source code, to:
Either force Architecture Explorer to display everything, including lambda expressions,
Or make it traverse lambda expressions while drawing a dependency through them (so in this case, drawing the dependency from
GenerateHelloMessage
toDefaultTemplateEngine
in the second example)?
© Programmers or respective owner