예제 #1
0
        public static string If(dynamic model, Action <string> then)
        {
            string value = DynamicHelper.Value(model);

            if (value != null)
            {
                try {
                    then(value);
                }
                catch (FileLoadException e) {
                    throw new LockedException(model.Path, e);
                }
                catch (Exception e) {
                    if (model is JValue)
                    {
                        throw new ApiArgumentException(model.Path, e);
                    }
                    throw;
                }
            }

            return(value);
        }
예제 #2
0
        public static T?If <T>(dynamic model, Action <T> then) where T : struct
        {
            T?value = DynamicHelper.To <T>(model);

            if (value != null)
            {
                try {
                    then(value.Value);
                }
                catch (FileLoadException e) {
                    throw new LockedException(model.Path, e);
                }
                catch (Exception e) {
                    if (model is JValue)
                    {
                        throw new ApiArgumentException(model.Path, e);
                    }
                    throw;
                }
            }

            return(value);
        }
예제 #3
0
        public static long?If(dynamic model, long min, long max, Action <long> then)
        {
            long?value = DynamicHelper.To(model, min, max);

            if (value != null)
            {
                try {
                    then(value.Value);
                }
                catch (FileLoadException e) {
                    throw new LockedException(model.Path, e);
                }
                catch (Exception e) {
                    if (model is JValue)
                    {
                        throw new ApiArgumentException(model.Path, e);
                    }
                    throw;
                }
            }

            return(value);
        }
예제 #4
0
        public static long?ToLong(dynamic value, int fromBase, long min = long.MinValue, long max = long.MaxValue)
        {
            string val = DynamicHelper.Value(value);

            if (val == null)
            {
                return(null);
            }

            try {
                var v = Convert.ToInt64(val, fromBase);

                Validator.WithinRange(min, max, v, value is JValue ? ((JValue)value).Path : string.Empty);

                return(v);
            }
            catch (FormatException e) {
                if (value is JValue)
                {
                    throw new ApiArgumentException(value.Path, e);
                }
                throw;
            }
        }