LINQ To Reflection

This is a linq extension set for faster and easier reflection.


  • .Metadata() : get metadata collection for query
        public static Metadata Metadata(this object instance)
            return MetadataCache.Create(instance);
  • .Proxy() : get dynamic access/invoke proxy
        public static Proxy Proxy(this object instance)
            return new Proxy(instance);
  • .Dynamic(): get a proxy as dynamic object
        public static dynamic Dynamic(this object instance)
            return new Proxy(instance);



A benchmark project is provided with the source of Sparrow. Here's part of the results (the benchmarks were run on my pc with release build):

Execute the following method 1,000,000 times:
        public void CallMe()

The way to excute Time elapsed (in second)
directly invoke 0.000
instance.Proxy().Methods["CallMe"].Invoke() 0.070
instance.Metadata().Methods["CallMe"].Invoke(instance) 0.078 (Recommended: lesser memory,higher performance)
instance.Dynamic().CallMe() 0.805
build-in reflection 1.419

Last edited Aug 30, 2010 at 2:34 PM by cnlangzi, version 14


No comments yet.