예제 #1
0
        /// <summary>
        /// Parses a list from a scriban argument
        /// </summary>
        /// <param name="arguments">Scriban arguments</param>
        /// <param name="index">Index of the parameter to parse</param>
        /// <typeparam name="T">Type</typeparam>
        /// <returns>Parsed list</returns>
        public static List <T> GetArrayFromScribanArgument <T>(ScriptArray arguments, int index)
        {
            if (arguments.Count <= index)
            {
                return(null);
            }

            object argumentValue = arguments[index];

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

            if (argumentValue is List <T> )
            {
                return((List <T>)argumentValue);
            }

            if (argumentValue is ScriptArray)
            {
                ScriptArray argumentArray = (ScriptArray)argumentValue;
                if (!argumentArray.Any(a => !(a is T)))
                {
                    return(argumentArray.Cast <T>().ToList());
                }
            }

            return(null);
        }