public InterfaceType GetRootType()
{
lock (_cacheLock)
{
if (_rootTypeCache.ContainsKey(this)) return _rootTypeCache[this];
var self = this.Type.IsGenericType ? this.Type.GetGenericTypeDefinition() : this.Type;
// the base of the interface we're looking for
var baseInterface = BaseInterfaces.Where(t => t.IsAssignableFrom(self)).First();
var allInherited = GetInterestingInterfaces(baseInterface, this.Type);
var candidates = allInherited
.Select(intf => new { Interface = intf, Inherited = GetInterestingInterfaces(baseInterface, intf) })
.ToList();
candidates.Add(new { Interface = this.Type, Inherited = allInherited });
return _rootTypeCache[this] = Create(candidates.OrderBy(i => i.Inherited.Length).First().Interface, _typeChecker);
}
}