Skip to content

Backport Has() function from Serilog.Filters.Expressions #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ calling a function will be undefined if:
| `IndexOf(s, t)` | Returns the first index of substring `t` in string `s`, or -1 if the substring does not appear. |
| `IndexOfMatch(s, p)` | Returns the index of the first match of regular expression `p` in string `s`, or -1 if the regular expression does not match. |
| `IsMatch(s, p)` | Tests whether the regular expression `p` matches within the string `s`. |
| `IsDefined(x)` | Returns `true` if the expression `x` has a value, including `null`, or `false` if `x` is undefined. |
| `IsDefined(x)` | Returns `true` if the expression `x` has a value, including `null`, or `false` if `x` is undefined. If coming from Serilog.Filters.Expressions depercated package this was previously called Has() |
| `LastIndexOf(s, t)` | Returns the last index of substring `t` in string `s`, or -1 if the substring does not appear. |
| `Length(x)` | Returns the length of a string or array. |
| `Now()` | Returns `DateTimeOffset.Now`. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ public static LogEventPropertyValue IsDefined(LogEventPropertyValue? value)
return ScalarBoolean(value != null);
}

/// <summary>
/// Used to backport anyone coming from Serilog.Filters.Expressions that used Has()
/// Before it was renamed to IsDefined()
/// </summary>
public static LogEventPropertyValue Has(LogEventPropertyValue? value)
{
return IsDefined(value);
}

public static LogEventPropertyValue? ElementAt(StringComparison sc, LogEventPropertyValue? items, LogEventPropertyValue? index)
{
// ReSharper disable once ConvertIfStatementToSwitchStatement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ Culture-specific {42.34} ⇶ Culture-specific 42,34
{rest()} ⇶ {"Name":"nblumhardt"}
{Name} {rest()} ⇶ nblumhardt {}
{rest(true)} ⇶ {}
{Name} ⇶ nblumhardt
{Name = 'nblumhardt'} ⇶ True
{Name = 'jdoe'} ⇶ False
{IsDefined(Name)} ⇶ True
{IsDefined(NonExistantProperty)} ⇶ False
{Has(Name)} ⇶ True
{Has(NonExistantProperty)} ⇶ False