public T Get <T> () where T : SState, new () { SState state = null; this.states.TryGetValue(typeof(T), out state); if (state != null) { return((T)state); } FactoryFunc <SState> factoryMethod = null; this.factories.TryGetValue(typeof(T), out factoryMethod); if (factoryMethod != null) { return((T)factoryMethod.Invoke()); } var newState = new T(); newState.Context = this; return(newState); }
public static void RegisterFactory <T>(FactoryFunc <T> factory) { FactoryFunc factoryWrapper = delegate { return(factory()); }; customFactoryTable[typeof(T)] = factoryWrapper; }
static FactoryBuilder() { FactoryFunc nonPolymorphicFactory; var ctor = typeof(TProxy).GetConstructor(new[] { typeof(DkmProcess), typeof(ulong) }); if (ctor != null) { var processParam = Expression.Parameter(typeof(DkmProcess)); var addressParam = Expression.Parameter(typeof(ulong)); var polymorphicParam = Expression.Parameter(typeof(bool)); nonPolymorphicFactory = Expression.Lambda <FactoryFunc>( Expression.New(ctor, processParam, addressParam), new[] { processParam, addressParam, polymorphicParam }) .Compile(); } else { nonPolymorphicFactory = (process, address, polymorphic) => { Debug.Fail("IDebuggeeReference-derived type " + typeof(TProxy).Name + " does not have a (DkmProcess, ulong) constructor."); throw new NotSupportedException(); }; } if (typeof(IPyObject).IsAssignableFrom(typeof(TProxy))) { Factory = (process, address, polymorphic) => { if (polymorphic) { return((TProxy)(object)PyObject.FromAddress(process, address)); } else { return(nonPolymorphicFactory(process, address, polymorphic)); } }; } else { Factory = nonPolymorphicFactory; } }
public AnomalieCabFactory(FactoryFunc factoryFunc) { _factoryFunc = factoryFunc ?? throw new ArgumentNullException(nameof(factoryFunc)); }
public void AddFactoryFor <T> (FactoryFunc <T> method) where T : SState { }
public InfosOpérationDépôtFactory(FactoryFunc factoryFunc) { _factoryFunc = factoryFunc; }
public CabFactory(IDépôtParutions dépôtParutions, FactoryFunc factoryFunc) { _dépôtParutions = dépôtParutions ?? throw new ArgumentNullException(nameof(dépôtParutions)); _factoryFunc = factoryFunc ?? throw new ArgumentNullException(nameof(factoryFunc)); }