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

Add new method CSScript.CodeDomEvaluator.ReferenceAssembliesByName(list<string) #267

Closed
TomBruns opened this issue Dec 17, 2021 · 6 comments

Comments

@TomBruns
Copy link

Request:
Enable loading referenced assemblies from a list of strings (assy names) instead of explicit individual ReferenceAssemblyByName(string) for each assy,

Current State:
We must add a ReferenceAssemblyByName line for the number of referenced assys that we want to be able to load.

Scenario:
We are executing scripts written by a separate team that may have 0..N referenced assys. This would make our code that wraps the CSScript library support this use case.

@oleg-shilo
Copy link
Owner

Well, I can understand what you are trying to solve and will consider converting the signature to the "params" version. It is because I am trying to keep the API as lean as possible. And "params" will completely address your issue.

Saying that, I would prefer users to extend the engine interface as much as possible instead of modifying it.

Thus this simple extension in your code will completely address your issue even without waiting the the next release:

static class CSScriptExtensions
{
    public static IEvaluator ReferenceAssemblyByNames(this IEvaluator  evaluator, string[] assemblyNames)
        => assemblyNames.ToList().ForEach(asm => evaluator.ReferenceAssemblyByName(asm));
}

@TomBruns
Copy link
Author

TomBruns commented Dec 28, 2021 via email

@oleg-shilo
Copy link
Owner

Correct. 👍

Though the signature can be improved even further:

static class CSScriptExtensions
{
    public static IEvaluator ReferenceAssemblyByNames(this IEvaluator evaluator, IEnumerable<string> assemblyNames)
    {
            foreach(var assemblyName in assemblyNames)
                evaluator.ReferenceAssemblyByName(assemblyName);
            return evaluator;
     }
}

oleg-shilo added a commit that referenced this issue Jan 3, 2022
@oleg-shilo
Copy link
Owner

Done. Will be available in the very next release.

@TomBruns
Copy link
Author

TomBruns commented Jan 3, 2022 via email

@TomBruns
Copy link
Author

A follow-up for people interested in this new feature...

The v4.3 release notes reference this enhancement request:
Issue #267: CSScript.CodeDomEvaluator.ReferenceAssembliesByName(list<string)

The actual implementation is a change to the signature of this method
public IEvaluator ReferenceAssemblyByName(params string[] assemblyName);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants