Beispiel #1
0
        protected override object CreateModel(ModelBindingContext bindingContext)
        {
            if (bindingContext == null)
            {
                throw new ArgumentNullException(nameof(bindingContext));
            }

            if (_modelCreator == null)
            {
                var modelTypeInfo = bindingContext.ModelType.GetTypeInfo();
                var constructor   = modelTypeInfo.GetConstructor(new[] { typeof(int) });
                var parameter     = Expression.Parameter(typeof(int), "p");

                _modelCreator = Expression
                                .Lambda <Func <int, object> >(Expression.New(constructor, parameter), parameter)
                                .Compile();
            }

            var codePage = bindingContext.CodePage();

            if (codePage == 0)
            {
                var option = bindingContext.HttpContext.RequestServices.GetRequiredService <IOptions <MT4NativeOption> >();
                codePage = option?.Value?.codePage ?? 0;
            }

            return(_modelCreator(codePage));
        }
Beispiel #2
0
        protected virtual object CreateModel(MT4Manager manager, ModelBindingContext bindingContext)
        {
            var codePage = bindingContext.CodePage();

            switch (bindingContext.ModelType.Name)
            {
            case "ConSymbol":
                var value = bindingContext.GetParameterValue("Name");
                return(manager.CfgRequestSymbol(codePage).Where(p => p.Name == value).First());

            default: break;
            }

            return(null);
        }