private IInstance Resolve(Type serviceType) { if (serviceType.IsArray) { Type elmType = serviceType.GetElementType(); MockArrayInstance instance = new MockArrayInstance(elmType); if (typeMap.TryGetValue(elmType, out var element)) { instance.Add(element); } return(instance); } var resolved = Resolve(serviceType, null); switch (resolved) { case Mock mock: return(new MockInstance(mock)); case IInstance instance: return(instance); case object _: return(new RealInstance(resolved)); default: return(null); } }
private IInstance CreateMockObjectAndStore(Type type) { if (type.IsArray) { Type elmType = type.GetElementType(); MockArrayInstance instance = new MockArrayInstance(elmType); if (typeMap.ContainsKey(elmType)) { instance.Add(typeMap[elmType]); } return(typeMap[type] = instance); } return(typeMap[type] = new MockInstance(type, mockBehavior)); }
private IInstance CreateMockObjectAndStore(Type type) { if (type.IsArray) { Type elmType = type.GetElementType(); MockArrayInstance instance = new MockArrayInstance(elmType); if (typeMap.ContainsKey(elmType)) { instance.Add(typeMap[elmType]); } return(typeMap[type] = instance); } var args = type.IsInterface ? null : CreateArguments(GetBindingFlags(true), type); var mockInstance = new MockInstance(type, mockBehavior, args); return(typeMap[type] = mockInstance); }
private IInstance Resolve(Type serviceType, ObjectGraphContext resolutionContext) { if (serviceType.IsArray) { Type elmType = serviceType.GetElementType() ?? throw new InvalidOperationException($"Could not determine element type for '{serviceType}'"); MockArrayInstance instance = new MockArrayInstance(elmType); if (_typeMap.TryGetValue(elmType, out var element)) { instance.Add(element); } return(instance); } object?resolved = Resolve(serviceType, null, resolutionContext); return(resolved switch { Mock mock => new MockInstance(mock), IInstance instance => instance, _ => new RealInstance(resolved), });
private IInstance Resolve(Type serviceType) { if (serviceType.IsArray) { Type elmType = serviceType.GetElementType(); MockArrayInstance instance = new MockArrayInstance(elmType); if (_typeMap.TryGetValue(elmType, out var element)) { instance.Add(element); } return(instance); } object?resolved = Resolve(serviceType, null); return(resolved switch { Mock mock => new MockInstance(mock), IInstance instance => instance, _ => new RealInstance(resolved), });