void isType(EncodedTextWriter writer, BlockHelperOptions options, Context context, Arguments arguments) { Type[] expectedType; var strType = (string)arguments[1]; switch (strType) { case "IEnumerable<string>": expectedType = new[] { typeof(IEnumerable <string>) }; break; case "IEnumerable<KeyValuePair<string, string>>": expectedType = new[] { typeof(IEnumerable <KeyValuePair <string, string> >) }; break; default: throw new ArgumentException("Invalid type: " + strType); } var t = arguments[0]?.GetType(); if (expectedType.Any(x => x.IsAssignableFrom(t))) { options.Template(writer, context); } else { options.Inverse(writer, context); } }
void footer(EncodedTextWriter writer, BlockHelperOptions options, Context context, Arguments arguments) { IDictionary <string, object> viewBag = context["ViewBag"] as IDictionary <string, object>; if (viewBag.TryGetValue("ShowFooter", out var show) && (bool)show == true) { options.Template(writer, (object)context); } }
void eachPair(EncodedTextWriter writer, BlockHelperOptions options, Context context, Arguments arguments) { void OutputElements <T>() { if (arguments[0] is IEnumerable <T> pairs) { foreach (var item in pairs) { options.Template(writer, item); } } } OutputElements <KeyValuePair <string, string> >(); OutputElements <KeyValuePair <string, object> >(); }