Files
Umbraco-CMS/umbraco.MacroEngines.Juno/RazorDynamicNode/DynamicNodeWhereHelpers.cs
agrath@gmail.com a32e8894cd Added support for calling non standard extension method style helpers within a .Where
Intended as a future extensibility point, provides a way for the parser to redirect into a static method library of helpers
Currently, only one method is available - ContainsAny
Functions like string.Contains but uses needles from a List<string>

var values = new Dictionary<string,object>();
var keywords = new List<string>();
keywords.Add("Five");
keywords.Add("Four");
values.Add("keywords",keywords);
var items = @Model.Children.Where("Name.ContainsAny(keywords)", values);
2011-02-26 11:12:06 -13:00

60 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace umbraco.MacroEngines
{
public static class DynamicNodeWhereHelpers
{
public static bool ContainsAny(string haystack, List<string> needles)
{
if (!string.IsNullOrEmpty(haystack) || needles.Count > 0)
{
foreach (string value in needles)
{
if (haystack.Contains(value))
return true;
}
}
return false;
}
public static bool ContainsAny(string haystack, params string[] needles)
{
if (!string.IsNullOrEmpty(haystack) || needles.Length > 0)
{
foreach (string value in needles)
{
if (haystack.Contains(value))
return true;
}
}
return false;
}
public static bool ContainsAny(string haystack, StringComparison comparison, List<string> needles)
{
if (!string.IsNullOrEmpty(haystack) || needles.Count > 0)
{
foreach (string value in needles)
{
if (haystack.IndexOf(value, comparison) >= 0)
return true;
}
}
return false;
}
public static bool ContainsAny(string haystack, StringComparison comparison, params string[] needles)
{
if (!string.IsNullOrEmpty(haystack) || needles.Length > 0)
{
foreach (string value in needles)
{
if (haystack.IndexOf(value, comparison) >= 0)
return true;
}
}
return false;
}
}
}