public override IMutablePicoContainer MakeChildContainer() { ImplementationHidingPicoContainer pc = new ImplementationHidingPicoContainer(caf, this, lifecycleManager); DelegateContainer.AddChildContainer(pc); return(pc); }
private DelegateContainer AddInternal(ServiceDescriptor serviceDescriptor) { AutoDIServiceDescriptor autoDIDescriptor = serviceDescriptor as AutoDIServiceDescriptor; Lifetime lifetime = autoDIDescriptor?.AutoDILifetime ?? serviceDescriptor.Lifetime.ToAutoDI(); Type targetType = autoDIDescriptor?.TargetType; var container = new DelegateContainer(lifetime, targetType, GetFactory(serviceDescriptor)); _accessors[serviceDescriptor.ServiceType] = container; return(container); Func <IServiceProvider, object> GetFactory(ServiceDescriptor descriptor) { if (descriptor.ImplementationType != null) { //TODO, resolve parameters return(sp => Activator.CreateInstance(descriptor.ImplementationType)); } if (descriptor.ImplementationFactory != null) { return(descriptor.ImplementationFactory); } //NB: separate the instance from the ServiceDescriptor to avoid capturing both object instance = descriptor.ImplementationInstance; return(_ => instance); } }
static void Main() { DelegateContainer <MyDelegate> delegates = new DelegateContainer <MyDelegate>(); delegates.Add(EntryPoint.PrintInt); }
static void Main(string[] args) { /* * Deletages Tasks */ DelegateContainer.del(); Console.WriteLine(DelegateContainer.floatDel()); DelegateContainer.intakeDel("yeetus", "deletus", "the fetus"); //Bonus task: AddDel addDel = MathClass.Add; AddFloatDel addFloatDel = MathClass.Add; Console.WriteLine(addDel(1, 4)); Console.WriteLine(addFloatDel(1.5f, 4.2f)); /* * Lambda Tasks */ LambdaTwoTimes lambdaTwoTimes = (a) => a * 2; Console.WriteLine(lambdaTwoTimes(4)); LambdaFloatSum lambdaFloatSum = (a, b, c) => a + b + c; Console.WriteLine(lambdaFloatSum(2.4f, 2.6f, 7.3f)); LambdaString lambdaString = () => "Hello world"; Console.WriteLine(lambdaString()); }
public static void GenericDelegateContainerTest() { var delegates = new DelegateContainer <int>(); delegates.Add(PrintInt); delegates.CallDelegates(55); delegates.CallDelegates(33); delegates.CallDelegates(44);
static void Main() { DelegateContainer <int> delegates = new DelegateContainer <int>(); delegates.Add(EntryPoint.PrintInt); delegates.CallDelegates(42); }
//Формирует контейнер с функциями, которые нужны для отрисовки фигур private DelegateContainer GetDeleateContainer() { DelegateContainer dlc = new DelegateContainer(); dlc.fGetGraphics = new DelegateContainer.dGetGraphics(GetGraphics); dlc.fRealToSreeen = new DelegateContainer.dRealToScreen(RealToScreen); dlc.fScreenToReal = new DelegateContainer.dScreenToReal(ScreenToReal); return(dlc); }
public override IComponentAdapter RegisterComponentImplementation(Object componentKey, Type componentImplementation) { if (componentKey is Type) { Type clazz = (Type)componentKey; if (clazz.IsInterface) { IComponentAdapter caDelegate = caf.CreateComponentAdapter(componentKey, componentImplementation, null); return (DelegateContainer.RegisterComponent(new ImplementationHidingComponentAdapter(caDelegate, true))); } } return(DelegateContainer.RegisterComponentImplementation(componentKey, componentImplementation)); }
public override IComponentAdapter RegisterComponentImplementation(Object componentKey, Type componentImplementation, IParameter[] parameters) { if (componentKey is Type) { Type clazz = (Type)componentKey; if (clazz.IsInterface) { IComponentAdapter caDelegate = caf.CreateComponentAdapter(componentKey, componentImplementation, parameters); ImplementationHidingComponentAdapter ihDelegate = new ImplementationHidingComponentAdapter(caDelegate, true); return(DelegateContainer.RegisterComponent(new CachingComponentAdapter(ihDelegate))); } } return(DelegateContainer.RegisterComponentImplementation(componentKey, componentImplementation, parameters)); }
public void Add(IServiceCollection services) { //TODO: This re-grouping seems off somewhere... foreach (IGrouping <Type, ServiceDescriptor> serviceDescriptors in from ServiceDescriptor service in services let autoDIService = service as AutoDIServiceDescriptor group service by autoDIService?.TargetType into @group select @group ) { DelegateContainer container = null; foreach (ServiceDescriptor serviceDescriptor in serviceDescriptors) { //Build up the container if it has not been generated or we do not have multiple AutoDI target types if (container == null || serviceDescriptors.Key == null) { container = AddInternal(serviceDescriptor); } _accessors[serviceDescriptor.ServiceType] = container; } } }
public void Delegate_With_MemoryStream() { using (var stream = new MemoryStream()) { { var container = new DelegateContainer(); container.Owner = new DelegateOwner(); container.User = new DelegateUser(); container.Owner.Event += container.User.EventHappened; var writer = new ObjectWriter(stream); writer.Write(container); } var reader = new ObjectReader(stream); var readContainer = reader.Read() as DelegateContainer; Assert.AreEqual(readContainer.Owner.GetDelegate().Target, readContainer.User); Assert.AreEqual(readContainer.Owner.GetDelegate().Target.GetType(), typeof(DelegateUser)); Assert.AreEqual(readContainer.Owner.GetDelegate().Method.Name, "EventHappened"); } }
public ExternPersistentContainer(Card c, DelegateContainer.ObjectParam f) { OwnerCard = c; func = f; }
public void AddExternPersistent(Card c, DelegateContainer.ObjectParam func) { ExternPersistent.Add(new ExternPersistentContainer(c, func)); }
public TaskItem(IDownloader downloader, DelegateContainer delegates) { resourceDownloader = downloader; downloader.delegates = delegates; }