-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
C# dynamic feature #154
Comments
I have a partial implementation of this in sq@f65f90b . I may never finish it, since it currently provides all the metadata I need (I use ILAst instead of C# AST), but if anyone wants to own finishing this I'd be glad to help you out. |
Implementation idea: Replace call site delegate invocations with special IL instructions. Create a bunch of new types of IL instructions, one for each method in the Microsoft.CSharp.RuntimeBinder.Binder class:
These instructions would contain the information from the dynamic call-site, and have child-instructions for the arguments passed to the delegate call.
All the dynamic instruction types should probably derive from a common base class ( Create a new ILAst transform that detects the The transform should probably not expect the call site initialization to be directly before the target delegate invocation -- while this assumption held true in all our tests so far, I wouldn't count on it; and it's easy to keep the transform flexible in this regard. Extend the C# Now, some instructions (e.g. |
Implemented in 58c174c |
I've pasted only a part of the original and generated code but you can find it all in here: ICSharpCode.SharpDevelop.Project.WebProjectService.CreateVirtualDirectory
Original:
dynamic manager = webAdministrationAssembly.CreateInstance("Microsoft.Web.Administration.ServerManager");
if (manager.Sites[DEFAULT_WEB_SITE] != null) {
...
} else {...}
Generated:
object arg2 = assembly.CreateInstance("Microsoft.Web.Administration.ServerManager");
if (WebProjectService.o__SiteContainer0.<>p__Site1 == null)
{
WebProjectService.o__SiteContainer0.<>p__Site1 = CallSite<Func<CallSite, object, bool>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.UnaryOperation(CSharpBinderFlags.None, ExpressionType.IsTrue, typeof(WebProjectService), new CSharpArgumentInfo[]
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
}));
}
Func<CallSite, object, bool> arg_1CB_0 = WebProjectService.o__SiteContainer0.<>p__Site1.Target;
CallSite arg_1CB_1 = WebProjectService.o__SiteContainer0.<>p__Site1;
if (WebProjectService.o__SiteContainer0.<>p__Site2 == null)
{
WebProjectService.o__SiteContainer0.<>p__Site2 = CallSite<Func<CallSite, object, object, object>>.Create(Microsoft.CSharp.RuntimeBinder.Binder.BinaryOperation(CSharpBinderFlags.None, ExpressionType.NotEqual, typeof(WebProjectService), new CSharpArgumentInfo[]
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.Constant, null)
}));
}
The text was updated successfully, but these errors were encountered: