Esempio n. 1
0
        /// <summary>
        /// Validate input value against spec schema
        /// </summary>
        /// <param name="ioBase"></param>
        /// <param name="value"></param>
        /// <returns>Returns true, otherwise throw ArgumentException if value is not valid</returns>
        public static bool ValidateWithSpec(this Interface.Io.Inputs.IoBase ioBase, object value)
        {
            if (!ioBase.ValidateWithSpec(value, out var messages))
            {
                var msg = string.Join("\n", messages);
                throw new System.ArgumentException(msg);
            }

            return(true);
        }
Esempio n. 2
0
        private static JsonSchema GetSpecSchema(this Interface.Io.Inputs.IoBase ioBase)
        {
            if (ioBase.Spec == null)
            {
                return(null);
            }
            var specJson = ioBase.Spec.ToString();

            return(JsonSchema.Parse(specJson));
        }
Esempio n. 3
0
        public static bool ValidateWithSpec(this Interface.Io.Inputs.IoBase ioBase, object value, out IList <string> outputMessages)
        {
            outputMessages = null;
            if (ioBase.Spec == null)
            {
                return(true);
            }
            var spec = ioBase.GetSpecSchema();

            var data  = JToken.FromObject(value);
            var valid = data.IsValid(spec, out outputMessages);


            return(valid);
        }
Esempio n. 4
0
 private static object GetPropertyValue(this Interface.Io.Inputs.IoBase ioBase, string propertyName)
 {
     return(ioBase.GetType().GetProperty(propertyName).GetValue(ioBase, null));
 }