Skip to content
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

Attempt to expose a functions metadata #135

Merged
merged 4 commits into from
Feb 28, 2024
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
10 changes: 10 additions & 0 deletions Source/Expressive/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ public class Context

internal char DecimalSeparator { get; }

/// <summary>
/// Gets the currently registered functions described by <see cref="IFunctionMetadata"/>.
/// </summary>
public IEnumerable<IFunctionMetadata> RegisteredFunctions => this.registeredFunctions.Values.OfType<IFunctionMetadata>();

/// <summary>
/// Gets the currently registered operators described by <see cref="IOperatorMetadata"/>.
/// </summary>
public IEnumerable<IOperatorMetadata> RegisteredOperators => this.registeredFunctions.Values.OfType<IOperatorMetadata>();

internal IEnumerable<string> FunctionNames => this.registeredFunctions.Keys.OrderByDescending(k => k.Length);

internal IEnumerable<string> OperatorNames => this.registeredOperators.Keys.OrderByDescending(k => k.Length);
Expand Down
10 changes: 10 additions & 0 deletions Source/Expressive/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public IReadOnlyCollection<string> ReferencedVariables
}
}

/// <summary>
/// Gets the currently registered functions described by <see cref="IFunctionMetadata"/>.
/// </summary>
public IEnumerable<IFunctionMetadata> RegisteredFunctions => this.context.RegisteredFunctions;

/// <summary>
/// Gets the currently registered operators described by <see cref="IOperatorMetadata"/>.
/// </summary>
public IEnumerable<IOperatorMetadata> RegisteredOperators => this.context.RegisteredOperators;

#endregion

#region Constructors
Expand Down
7 changes: 1 addition & 6 deletions Source/Expressive/Functions/IFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Expressive.Functions
/// <summary>
/// Interface definition for a Function that can be evaluated.
/// </summary>
public interface IFunction
public interface IFunction : IFunctionMetadata
{
/// <summary>
/// Gets or sets the Variables and their values to be used in evaluating an <see cref="Expression"/>.
Expand All @@ -15,11 +15,6 @@ public interface IFunction
IDictionary<string, object> Variables { get; set; }
#pragma warning restore CA2227 // Collection properties should be read only

/// <summary>
/// Gets the name of the Function.
/// </summary>
string Name { get; }

/// <summary>
/// Forces the Function to evaluate itself using the supplied parameters.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions Source/Expressive/Functions/IFunctionMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Expressive.Functions
{
/// <summary>
/// Interface definition for an <see cref="IFunction"/>s metadata.
/// </summary>
public interface IFunctionMetadata
{
/// <summary>
/// Gets the name of the Function.
/// </summary>
string Name { get; }
}
}
7 changes: 1 addition & 6 deletions Source/Expressive/Operators/IOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ namespace Expressive.Operators
/// <summary>
/// Definition for all Operators (i.e. +, -, etc.) that are available in Expressive.
/// </summary>
public interface IOperator
public interface IOperator : IOperatorMetadata
{
/// <summary>
/// Gets the list of tags that can be used to identify this IOperator.
/// </summary>
IEnumerable<string> Tags { get; }

/// <summary>
/// Builds the operator in to an <see cref="IExpression"/> ready for evaluation.
/// </summary>
Expand Down
15 changes: 15 additions & 0 deletions Source/Expressive/Operators/IOperatorMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace Expressive.Operators
{
/// <summary>
/// Interface definition for an <see cref="IOperator"/>s metadata.
/// </summary>
public interface IOperatorMetadata
{
/// <summary>
/// Gets the list of tags that can be used to identify this IOperator.
/// </summary>
IEnumerable<string> Tags { get; }
}
}
Loading