// Show company info.
DisplayCompanyData(t);
}
return foundSnapIn;
}
Using the incoming type, simply reflect over the [CompanyInfo] attribute:
private void DisplayCompanyData(Type t)
{
// Get [CompanyInfo] data.
var compInfo = from ci in t.GetCustomAttributes(false) where
(ci.GetType() == typeof(CompanyInfoAttribute))
select ci;
// Show data.
foreach (CompanyInfoAttribute c in compInfo)
{
MessageBox.Show(c.Url,
string.Format("More info about {0} can be found at", c.Name));
}
}
Figure 16-12 shows one possible run.
Figure 16-12.
Snapping in external assemblies
Excellent! That wraps up the example application. I hope at this point you can see that the top-
ics presented in this chapter can be quite helpful in the real world and are not limited to the tool
builders of the world.
Do'stlaringiz bilan baham: |