private UnionContext GetContext(Type type) { if (!_contexts.TryGetValue(type, out var context)) { var rootType = UnionHelper.GetRootType(type); if (rootType != null) { if (!_contexts.TryGetValue(rootType.AsType(), out var rootContext)) { rootContext = _contexts[rootType.AsType()] = new UnionContext(rootType); } context = _contexts[type] = rootContext; } } return(context); }