Skip to content

Instantly share code, notes, and snippets.

View aashishkoirala's full-sized avatar
🏠
Working from home

Aashish Koirala aashishkoirala

🏠
Working from home
View GitHub Profile
@aashishkoirala
aashishkoirala / MEFDuplicateAvoid1.cs
Last active December 20, 2015 20:59
Handling duplicate assemblies in MEF.
var assemblyFiles = new List<string>();
foreach (var modulesDirectory in modulesDirectories)
{
using (var directoryCatalog = new DirectoryCatalog(modulesDirectory))
assemblyFiles.AddRange(directoryCatalog.LoadedFiles);
}
var assemblyCatalogs = assemblyFiles
.Distinct()
.Select(Assembly.LoadFrom)
@aashishkoirala
aashishkoirala / MEFDuplicateAvoid2.cs
Last active December 20, 2015 20:59
Handling duplicate assemblies with MEF - AssemblyEqualityComparer class.
private class AssemblyEqualityComparer : IEqualityComparer<Assembly>
{
public bool Equals(Assembly x, Assembly y)
{
return x.FullName == y.FullName;
}
public int GetHashCode(Assembly obj)
{
return obj.GetHashCode();
// Example 1: Dictionaries.
// Using "string" as key/value for example; could be anything.
IDictionary<string, string> myDictionary;
// ...
// ...
// Returns Perhaps<string>.NotThere if not found.
var dictionaryResult = myDictionary.LookFor("MyKey");