Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Created July 21, 2011 14:26
Show Gist options
  • Save chgeuer/1097299 to your computer and use it in GitHub Desktop.
Save chgeuer/1097299 to your computer and use it in GitHub Desktop.
MEF Debugging - Spit out values
try
{
// Just try to check whether the actual service instance can be created.
var svc = container.GetExportedValue<AppStoreServiceImpl>();
Debug.Assert(
svc != null,
"container.GetExportedValue<AppStoreServiceImpl>() != null");
}
catch (CompositionException ce)
{
Func<string, string> getVal = s =>
{
try
{
return container.GetExportedValueOrDefault<string>(s);
}
catch (Exception ex)
{
return ex.GetType().Name + " " + ex.Message;
}
};
var sb = new StringBuilder();
sb.AppendLine(ce.GetFullDetail());
sb.AppendLine("ImportDefinitions");
container.Catalog.Parts.ToList().ForEach(c => c.ImportDefinitions.ToList().ForEach(ed => sb.AppendLine("IMPORT" + "\t" + ed.ContractName + "\t" + c.ToString() + "\t" + getVal(ed.ContractName))));
sb.AppendLine("ExportDefinitions");
container.Catalog.Parts.ToList().ForEach(c => c.ExportDefinitions.ToList().ForEach(ed => sb.AppendLine("EXPORT" + "\t" + ed.ContractName + "\t" + c.ToString())));
throw new NotImplementedException(sb.ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment