TypeDescriptorProvider limited in actual implementation?

  • Thread starter Thread starter Anthony Paul
  • Start date Start date
A

Anthony Paul

Hello everyone,

I've been fooling around with what's possible and not with the
TypeDescriptorProvider and found a limitation that I would like
confirmed if possible. I derived a class from CustomTypeDescriptor
and
did an override on the GetAttributes method and added a
Serializeable
attribute; this way any type registered with my
TypeDescriptorProvider
would supposedly be marked as Serializeable without having to
actually
modify that class's code. However, when I tried to serialize it with
a
BinaryFormatter I found that I get the usual "not marked
Serializeable" exception. I believe that this is due to the formatter
using reflection rather than the TypeDescriptor in order to get the
attributes. Am I correct in my assumption and if so, then how useful
is the TypeDescriptor system?

Regards,

Anthony
 
Serializable is a "special" attribute, kinda like MethodImpl. It has meaning
to the compiler, but not the CLR. In fact if you look in Reflector you'll
see that serializable types don't even have the attribute in their metadata.
Instead it's a core property of the type itself.

Type.IsSerializable tells you if a type is serializable or not, but you
can't really change that fact at runtime. You could, on the other hand,
build a dynamic serializable type at runtime and copy the members in.

Josh Einstein
 
Ahhh, then that explains it... it is, in fact, a pseudo custom
attribute, quite different from a normal attribute. Thank you Josh.

Regards,

Anthony
 
Back
Top