/// <summary> /// Returns the size of the input object. /// - If the input object is a string, it will return the length /// - If the input is a list, it will return the number of elements /// - If the input is an object, it will return the number of members /// </summary> /// <param name="context">The template context</param> /// <param name="span">The source span</param> /// <param name="value">The input object.</param> /// <returns>The size of the input object.</returns> /// <remarks> /// ```scriban-html /// {{ [1, 2, 3] | object.size }} /// ``` /// ```html /// 3 /// ``` /// </remarks> public static int Size(TemplateContext context, SourceSpan span, object value) { if (value is string) { return(StringFunctions.Size((string)value)); } if (value is IEnumerable) { return(ArrayFunctions.Size((IEnumerable)value)); } // Should we throw an exception? return(0); }
/// <summary> /// Returns the size of the input object. /// - If the input object is a string, it will return the length /// - If the input is a list, it will return the number of elements /// - If the input is an object, it will return the number of members /// </summary> /// <param name="value">The input object.</param> /// <returns>The size of the input object.</returns> /// <remarks> /// ```scriban-html /// {{ [1, 2, 3] | object.size }} /// ``` /// ```html /// 3 /// ``` /// </remarks> public static int Size(object value) { if (value is string) { return(StringFunctions.Size((string)value)); } if (value is IEnumerable) { return(ArrayFunctions.Size((IEnumerable)value)); } // Should we throw an exception? return(0); }