예제 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var obj = JObject.Load(reader);
            ProfitSharingStrategy strategy;

            var method = obj["Method"];
            if (method == null)
            {
                throw new ArgumentNullException("Type", "Order type is null");
            }

            var profitSharingMethod = (ProfitSharingMethod)Enum.Parse(typeof(ProfitSharingMethod), method.Value<string>());
            switch (profitSharingMethod)
            {
                case ProfitSharingMethod.FLAT_RATE:
                    strategy = new FlatRateStrategy();
                    break;
                case ProfitSharingMethod.PRICE_PERCENTAGE:
                    strategy = new PricePercentageStrategy();
                    break;
                default:
                    throw new NotImplementedException($"{profitSharingMethod.ToString()} is invalid/not supported");
            }

            serializer.Populate(obj.CreateReader(), strategy);
            return strategy;
        }
예제 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var obj = JObject.Load(reader);
            ProfitSharingStrategy strategy;

            var method = obj["Method"];

            if (method == null)
            {
                throw new ArgumentNullException("Type", "Order type is null");
            }

            var profitSharingMethod = (ProfitSharingMethod)Enum.Parse(typeof(ProfitSharingMethod), method.Value <string>());

            switch (profitSharingMethod)
            {
            case ProfitSharingMethod.FLAT_RATE:
                strategy = new FlatRateStrategy();
                break;

            case ProfitSharingMethod.PRICE_PERCENTAGE:
                strategy = new PricePercentageStrategy();
                break;

            default:
                throw new NotImplementedException($"{profitSharingMethod.ToString()} is invalid/not supported");
            }

            serializer.Populate(obj.CreateReader(), strategy);
            return(strategy);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var obj = JObject.Load(reader);
            ProfitSharingStrategy profitSharingStgy;

            var method = obj["Method"];

            if (method == null)
            {
                throw new ArgumentNullException("Method", "ProfitSharingMethod is null");
            }

            var profitSharingMethod = method.Value <ProfitSharingMethod>();

            switch (profitSharingMethod)
            {
            case ProfitSharingMethod.FLAT_RATE:
                profitSharingStgy = new FlatRateStrategy();
                break;

            case ProfitSharingMethod.PRICE_PERCENTAGE:
                profitSharingStgy = new PricePercentageStrategy();
                break;

            default:
                throw new NotSupportedException(string.Concat("Profit Sharing Method invalid/not supported - ", profitSharingMethod));
            }

            serializer.Populate(obj.CreateReader(), profitSharingStgy);
            return(profitSharingStgy);
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var obj = JObject.Load(reader);
            ProfitSharingStrategy profitSharingStgy;

            var method = obj["Method"];
            if (method == null)
            {
                throw new ArgumentNullException("Method", "ProfitSharingMethod is null");
            }

            var profitSharingMethod = method.Value<ProfitSharingMethod>();
            switch (profitSharingMethod)
            {
                case ProfitSharingMethod.FLAT_RATE:
                    profitSharingStgy = new FlatRateStrategy();
                    break;
                case ProfitSharingMethod.PRICE_PERCENTAGE:
                    profitSharingStgy = new PricePercentageStrategy();
                    break;
                default:
                    throw new NotSupportedException(string.Concat("Profit Sharing Method invalid/not supported - ", profitSharingMethod));
            }

            serializer.Populate(obj.CreateReader(), profitSharingStgy);
            return profitSharingStgy;
        }