我使用反射来获取属性名称和值在ASP.NET需要在优化一些建议 [英] I am using reflection to get property names and values in ASP.NET need some advice on optimization

查看:209
本文介绍了我使用反射来获取属性名称和值在ASP.NET需要在优化一些建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用反射来获取属性(如{获得;}设置属性)的名字和他们的价值。我想优化这个反思。我没有访问我使用的反射的客户端类的code,但搞清楚所涉及的类的属性名后,我会一次又一次地重复使用相同的属性。

I am using reflection to get property (as in {get; set} properties) names and their value. I would like to optimize this reflection. I don't have access to the code of the client classes I am using the reflection on, but after figuring out the property names of the class involved I will be reusing the same properties again and again.

我在ASP.NET应用程序这样做的,所以我想存储在应用程序(HttpContext.Current.Application),所以第一个用户将有增加的主要性能负载一些缓存的结果,但作为请求其他扩展用户可以使用第一用户的缓存结果

I am doing this in an ASP.NET application and so I was thinking of storing some cached results in the Application (HttpContext.Current.Application) so the first user would have the primary increased performance load, but as requests scale other users can use the cached results of the first user.

  • NHibernate
  • Marc Gravell's HyperDescripter

能否有人为给我一个非常深入浅出,如果马克砾石的解决方案是适当的解释在这里,或者类似的NHibernate是好的这种情况呢?或者我应该只是缓存通过反射在列表aquiring在类的属性名的结果,然后使用,当我需要枚举属性名称?

Can somone give me a very laymans explanation of if Marc Gravel's solution is appropriate here, or if something like NHibernate is good for this situation? Or should I just cache the results of aquiring the property names in the class via reflection in a list and then use that when I need to enumerate property names?

推荐答案

HyperDescriptor是专为装配的的ComponentModel 的API里面的具体目的。如果你不使用,它可能是矫枉过正。只是缓存静态通用类型中的数据可以是pretty有效,使用静态构造来填充数据。我的意思是:存储数据每-T:

HyperDescriptor is designed for the specific purpose of fitting inside the ComponentModel API. If you don't use that, it may be overkill. Just caching the data inside a static generic type can be pretty effective, using a static constructor to populate the data. By which I mean: store the data per-T:

public static class PropertyCache<T>
{
    public static SomeType SomeName { get { return someField; } }
    static PropertyCache() {
        // init someField
    }
}
...
var foo = PropertyCache<Foo>.SomeName;

这篇关于我使用反射来获取属性名称和值在ASP.NET需要在优化一些建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆