Markdig.Extensions.ScriptCs icon indicating copy to clipboard operation
Markdig.Extensions.ScriptCs copied to clipboard

Can I give input parameters as context?

Open pethopal opened this issue 7 years ago • 2 comments
trafficstars

I would like to give input objects to the ScriptCs (in new ScriptCsOptions() only ExceptionStackTrace property exists) so I can use those object's public properties, call it's public methods from the cs script...

pethopal avatar Sep 04 '18 08:09 pethopal

Thinking out loud:

This is technically possible by creating a ScriptHostFactory and adding something like a Context ExpandoObject as a property on the ScriptHostFactory perhaps.

The usage would be something like: dynamic context = new ExpandoObject(); context.aString = "Hello World";

....UseScriptCs(new ScriptCsOptions() { ExceptionStackTrace = false, Context = context })

This would mean the CSX scripts could access context objects like Context.aString.

More detail here: https://github.com/scriptcs/scriptcs/wiki/Hosting#creating-a-custom-script-host

I don't currently have any time to look at this. :)

macaba avatar Sep 04 '18 10:09 macaba

Yes, thank you, this is exactly what I would need... I mean ExpandoObject would give very much flexibility...

pethopal avatar Sep 04 '18 12:09 pethopal