Statiq.Framework icon indicating copy to clipboard operation
Statiq.Framework copied to clipboard

The "If" module should have a simpler way to test meta values

Open deanebarker opened this issue 6 years ago • 1 comments

The If module should have a convenience signature that evaluates meta keys

If(string key, object value)

I often find myself testing meta keys in the If module, and I feel like this is common enough to be made simpler. For example:

If("SourceFileBase", "introduction")

// Which is easier and clearer than...

If((doc, ctx) => { return doc["SourceFileBase"] == "introduction"; })

This wouldn't replace anything, just make a common scenario easier.

Any reason why I shouldn't write this and submit it? Should it be another signature on If, or should it be another module (IfMeta) that wraps If?

deanebarker avatar Jun 03 '19 12:06 deanebarker

I like it as another couple constructors on the If module - it probably wouldn't even need a body:

public If(string key, object value)
    : this(key, value, EqualityComparer<object>.Default)
{
}

public If(string key, object value, IEqualityComparer<object> comparer)
    : this((doc, ctx) => comparer.Equals(doc[key], value))
{
}

(just a first thought - feel free to enhance or whatever if you end up taking on a PR).

daveaglick avatar Jun 09 '19 19:06 daveaglick