scriptcs/scriptcs — pull request #506 by adamralph (2013-11-06 20:56:59+00:00)
Title: make IScriptHostFactory generic to allow custom script hosts

speculative PR for discussion/feedback or even a merge! :wink:

So finally worked out how to get my own methods and properties on my script host, as per the discussion at https://github.com/scriptcs/scriptcs/issues/315#issuecomment-19854517

It occurred to me that the properties/methods I was adding to my own host derived from `IScriptHost` were not available to scripts because `RoslynScriptEngine` was is always calling `Roslyn.Scripting.CommonScriptEngine.CreateSession()` with an `IScriptHost` object, so Roslyn was only surfacing the members defined on `IScriptHost` to scripts.

Now, perhaps I'm missing something obvious and someone can shame here with a much simpler solution, but I found that by writing my own script engine based on `RoslynScriptEngine` but using my own script host interface fixed things for me - https://github.com/config-r/config-r/blob/dev/src/ConfigR/Scripting/ConfigRScriptEngine.cs. This has a lot of duplicated code from `RoslynScriptEngine` and it's only effective purpose is to use a different type parameter when calling `CreateSession()`.

If `IScriptHostFactory` becomes generic, then I can just reuse `RoslynScriptEngine` and rip all that duplication out of ConfigR.

I believe the ability to define custom hosts is essential for scriptcs so I'm keen to get this in.

Or of course if I'm being dumb then it would be great if someone could point out the easy way :innocent:.