Created
July 21, 2011 14:26
-
-
Save chgeuer/1097299 to your computer and use it in GitHub Desktop.
MEF Debugging - Spit out values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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