.NET 3.5 中 ExpandoObject 的替代品,开销最小
如何以最少的开销在 .NET 3.5 应用程序中模仿 ExpandoObject 的功能?到目前为止,我最好的方法是使用 Lin Fu 框架 ( http://www.codeproject. com/KB/cs/LinFuPart2.aspx ),但我认为可能有更好的东西。
为了更好地了解我在这里的目的,我的目标是从 MethodInfo
的参数动态创建类型。所以,基本上我想
public class ServiceObject
{
public void Execute(string TransformMeIntoAProperty);
}
将其转变为
public class ServiceObjectExecuteSignature
{
public string TransformMeIntoAProperty{ get; set;}
}
在运行时 :。我必须能够使用反射访问参数,因为我正在使用 Linq 表达式。
How can I imitate the functionality of the ExpandoObject in a .NET 3.5 application with the least overhead? My best lead so far is to use the Lin Fu framework ( http://www.codeproject.com/KB/cs/LinFuPart2.aspx ), but I'm thinking there may be something better.
To give a better idea of what I am going for here, my objective is to dynamically create the type from the parameters of a MethodInfo
. So, basically I want to turn this:
public class ServiceObject
{
public void Execute(string TransformMeIntoAProperty);
}
into
public class ServiceObjectExecuteSignature
{
public string TransformMeIntoAProperty{ get; set;}
}
at runtime. I have to be able to access the Parameters using Reflection, because I am using Linq Expressions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 CodeDom 在运行时动态编译一些新类型。显然,这样做是有前期成本的……我想这取决于您生成的类型的生命周期。
http://www.codeproject.com/Articles/ 26312/Dynamic-Code-Integration-with-CodeDom
http://www.c-sharpcorner.com/uploadfile/mgold/codedomcalculator08082005003253am/codedomcalculator.aspx
http://igorshare.wordpress.com/2008/01/11/codedom-extensions-and-dynamic-linq-stringscript-to-linq-emitting/
You could use the CodeDom to dynamically compile some new types at runtime. Obviously there's an upfront cost of doing that....I suppose it depends on the lifetime of the types you are generating.
http://www.codeproject.com/Articles/26312/Dynamic-Code-Integration-with-CodeDom
http://www.c-sharpcorner.com/uploadfile/mgold/codedomcalculator08082005003253am/codedomcalculator.aspx
http://igorshare.wordpress.com/2008/01/11/codedom-extensions-and-dynamic-linq-stringscript-to-linq-emitting/