static class and method script hosting pattern

41 views
Skip to first unread message

silveroak

unread,
Feb 8, 2012, 11:18:44 AM2/8/12
to CS-Script
Oleg and users, I have been wondering why this works without
conflicts. When we need some variable actions that do different
pieces of work, we have been using this pattern to execute various
methods with variable bodies:

(new AsmHelper(CSScript.LoadCode("public static class Scripts {public
static void Do(...) {....} }").Invoke("Scripts.Do", ...);

apparently we can use the same "Scripts" static class name any number
of times to encaplsulate the action. We have been making method names
different such as Do, Do1, Do2 but wondering if that is even necessary
since using same class names apparently does not cause any problems
with assembly loading.

Appreciate any insight on how using same class name does not lead to
any conflicts.

Oleg Shilo

unread,
Feb 8, 2012, 7:42:16 PM2/8/12
to CS-Script
You do not need to bother with the unique class/method name.

The uniqueness of the type in .NET is defined by the following
components
[assembly][namespace][class_name]

Because every script has its own assembly there is no collision.
Assembly component of the class identifier is always different.

BTW you may also consider the following API usage pattern:

var PrintSum = CSScript.LoadMethod(
@"public static void PrintSum(int a, int b)
{
Console.WriteLine((a+b));
}")
.GetStaticMethod();

PrintSum(1, 2);

silveroak

unread,
Feb 10, 2012, 8:53:29 AM2/10/12
to CS-Script
This makes much sense. Thanks!
> > any conflicts.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages