Skip to content
Merged
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
16 changes: 8 additions & 8 deletions src/Ramstack.ExpressionParser/DefaultBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ namespace Ramstack.Parsing;
/// </remarks>
public class DefaultBinder : Binder
{
private static readonly Dictionary<string, (Type type, bool isStatic)> Empty = new();
private static readonly Dictionary<string, (Type type, bool isStatic)> s_empty = new();

/// <summary>
/// A predefined dictionary of safe common .NET types.
/// </summary>
private static readonly Dictionary<string, (Type type, bool isStatic)> PredefinedType = new(StringComparer.OrdinalIgnoreCase)
private static readonly Dictionary<string, (Type type, bool isStatic)> s_predefinedTypes = new(StringComparer.OrdinalIgnoreCase)
{
{ "bool", (typeof(bool), false) },
{ "boolean", (typeof(bool), false) },
Expand Down Expand Up @@ -81,7 +81,7 @@ public class DefaultBinder : Binder
/// <summary>
/// A dictionary of user-registered types.
/// </summary>
private Dictionary<string, (Type type, bool isStatic)> _types = Empty;
private Dictionary<string, (Type type, bool isStatic)> _types = s_empty;

/// <summary>
/// Registers a custom type for use in binding operations, allowing it to be resolved by name.
Expand All @@ -96,9 +96,9 @@ public class DefaultBinder : Binder
/// </remarks>
public void RegisterType(Type type, bool importAsStatic = false)
{
if (!PredefinedType.ContainsKey(type.Name))
if (!s_predefinedTypes.ContainsKey(type.Name))
{
if (ReferenceEquals(_types, Empty))
if (ReferenceEquals(_types, s_empty))
_types = new Dictionary<string, (Type, bool)>(StringComparer.OrdinalIgnoreCase);

_types[type.Name] = (type, importAsStatic);
Expand All @@ -108,7 +108,7 @@ public void RegisterType(Type type, bool importAsStatic = false)
/// <inheritdoc />
public override Type? BindToType(Identifier name)
{
if (!PredefinedType.TryGetValue(name.Name, out var value))
if (!s_predefinedTypes.TryGetValue(name.Name, out var value))
_types.TryGetValue(name.Name, out value);

return value.type;
Expand All @@ -119,7 +119,7 @@ public void RegisterType(Type type, bool importAsStatic = false)
{
var q = type is not null
? GetMethods(type, methodName.Name, isStatic)
: PredefinedType
: s_predefinedTypes
.Concat(_types)
.Where(t => t.Value.isStatic)
.SelectMany(t => GetMethods(t.Value.type, methodName.Name, isStatic));
Expand All @@ -143,7 +143,7 @@ public void RegisterType(Type type, bool importAsStatic = false)
: BindingFlags.Public | BindingFlags.Instance;

var q = type?.GetMembers(bindingFlags)
?? PredefinedType
?? s_predefinedTypes
.Concat(_types)
.Where(t => t.Value.isStatic)
.SelectMany(t => t.Value.type.GetMembers(bindingFlags));
Expand Down
4 changes: 2 additions & 2 deletions src/Ramstack.ExpressionParser/ExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class ExpressionBuilder(Binder binder) : ExprVisitor<Expression>
/// <summary>
/// The overloads of the <c>string.Concat</c> method that the <c>+</c> operator with a string operand is bound to.
/// </summary>
private static readonly MethodBase[] ConcatMethods = typeof(string)
private static readonly MethodBase[] s_concatMethods = typeof(string)
.GetMethods(BindingFlags.Public | BindingFlags.Static)
.Where(m =>
m.Name == nameof(string.Concat)
Expand Down Expand Up @@ -117,7 +117,7 @@ protected internal override Expression VisitBinary(Expr.Binary expr)
}
}

var cmi = (MethodInfo?)MethodResolver.ResolveMethod(ConcatMethods, argumentTypes.ToArray())!;
var cmi = (MethodInfo?)MethodResolver.ResolveMethod(s_concatMethods, argumentTypes.ToArray())!;
Debug.Assert(cmi is not null);

var args = CreateInjectingArguments(cmi, arguments);
Expand Down