Unregister functions & constants#21
Open
mibe wants to merge 2 commits into
Open
Conversation
Contributor
Author
|
I'm using "a" to "z" as variables. To achieve this I had to remove "e" as the Euler's number constant. And since I was already into it, I implemented a method for removing functions, too. Since I'm currently using version 0.8.7, I implemented a reflection hack for this again: /// <summary>
/// Remove a constant of the calculation engine.
/// </summary>
/// <param name="engine">Instance of the engine</param>
/// <param name="constantName">Name of the constant</param>
/// <returns>TRUE if the constant was removed successfully.</returns>
public static bool RemoveConstant(CalculationEngine engine, string constantName)
{
// Retrieve ConstantRegistry
ConstantRegistry registry = (ConstantRegistry)getProperty(engine, "ConstantRegistry");
// Retrieve & invoke method for converting the constant name
MethodInfo method = registry.GetType().GetMethod("ConvertConstantName", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);
constantName = (String)method.Invoke(registry, new object[] { constantName });
// Retrieve internal Dictionary
Dictionary<string, ConstantInfo> constants = (Dictionary<string, ConstantInfo>)getField(registry, "constants");
return constants.Remove(constantName);
}
private static object getProperty(object @object, string propertyName)
{
PropertyInfo property = @object.GetType().GetProperty(propertyName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty);
return property.GetValue(@object);
}
private static object getField(object @object, string fieldName)
{
FieldInfo field = @object.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField);
return field.GetValue(@object);
} |
Owner
|
Jace 0.9 now has a parameter in the constructor of CalculcationEngine to prevent loading the default contstants |
Contributor
Author
|
I saw that, thanks. Still, removing unwanted constants and functions is a nice feature, IMHO. |
Owner
|
The main issue, I see is that it might mess up the cache of generated formulas if some functions are suddenly gone. But I will give the request an additional thought. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the ability to remove functions & constants from the CalculationEngine.