none
Generics reflection and instantiation RRS feed

  • Question

  • I am writing a custom serializer and I need to serialize IEnumerable<> objects in a special way.

    Write now I am checking if the object is generic and implements the old IEnumerable, e.g.:

    IEnumerable enumer = (IEnumerable)obj;
    Type expected = obj.GetGenericArguments()[0];
    foreach(object o in enumer) {
         if(!expected.IsAssignableFrom(o.GetType()))
              return false;
          ....
    }

    Is it possible to emit/generate using reflection code that works with the specific generic types to increase performance?

    • Moved by Jason Dot Wang Tuesday, April 9, 2013 3:22 AM This thread is about Common Language Runtime Internals and Architecture
    Sunday, April 7, 2013 6:23 AM

Answers

All replies