in src/BindingExtractor.cs [15:53]
static BindingExtractor()
{
// We want this behavior to be extensible by third parties who may want to add binding definitions.
// To accomplish this, we parse through all loaded assemblies to find any class which implements
// IBinding, and load it manually into our supportedBindings
// Find all types that implement IBinding
IEnumerable<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies();
List<Type> types = new List<Type>();
foreach (Assembly assembly in assemblies)
{
try
{
types.AddRange(assembly.GetTypes().Where(type => type.IsSubclassOf(typeof(IBinding))));
}
catch (ReflectionTypeLoadException)
{
// Do nothing, ReflectionTypeLoadExceptions seem to be thrown in the virtualized PowerShell environments used
// by GitHub in the test environment. So far, ignoring them hasn't changed the behavior of the app, they seem
// to be thrown only by assemblies that come packaged with .NET.
}
}
foreach (Type type in types)
{
try
{
// Instantiate an object of this type, and call its method to load it into supportedBindings for use later
object? obj = Activator.CreateInstance(type);
if (!BindingExtractor.hasSupportedBinding(type) && obj is not null)
{
BindingExtractor.addSupportedBinding((IBinding)obj);
}
}
catch (MissingMethodException)
{
//Do nothing, it's an abstract class or improperly declared.
}
}
}