I ended up implementing a Hash set that is initialized in the static constructor and gets all the type I want to pass trough.
private static HashSet<Type> m_PassableTypes; //
static SynthesisExtensions() { //
m_PassableTypes = new HashSet<Type>();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) {
foreach (Type type in assembly.GetTypes()) {
if (type.IsValueType || type == typeof (string) || type.Module.Name == "FSharp.Core.dll" ||
type.IsDefined(typeof (MessageAttribute), false)) {
m_PassableTypes.Add(type);
}
}
}
}
This allows me to then perform a really fast HashSet look up which is way more performant.
Type type = instance.GetType();
if (m_PassableTypes.Contains(type)) {
// cache the self-reference
referenceCache.Add(instance, instance);
// return the value itself
return instance;
}
Thanks for all the help! I'd welcome any thoughts on this solution