private IProductScope GetProduct(ProductType productType) { if (_productGetters == null) { _productGetters = ProductType .GetAll <ProductType>() .Select(pt => new { ProductType = pt, Getter = pt.Selector.ToGetter() }) .ToDictionary(x => x.ProductType, x => x.Getter); } return(_productGetters[productType](this)); }
private void SetProduct(ProductType productType, IProductScope product) { if (_productSetters == null) { _productSetters = ProductType .GetAll <ProductType>() .Select(pt => new { ProductType = pt, Setter = pt.Selector.ToSetter() }) .ToDictionary(x => x.ProductType, x => x.Setter); } _productSetters[productType](this, product); }
private IProductScope NewProduct(ProductType productType) { if (_productConstructors == null) { _productConstructors = ProductType .GetAll <ProductType>() .Select(pt => new { ProductType = pt, Constructor = ExpressionUtils.CreateDefaultConstructor <IProductScope>(pt.Type) }) .ToDictionary(x => x.ProductType, x => x.Constructor); } return(_productConstructors[productType]()); }