I'm using reflection to create a manifest of all assets, strongly typed.

It's working fine for my own types: I get the type of the asset, if a processor is ran on it I get the output type. Then I check to see if there's a ContentSerializerRuntimeTypeAttribute applied to the type. If so, then I get the RuntimeType value and do a Type.GetType() to get the type back.

The problem I have is if the type is Texture2DContent (for example) as that doesn't have the ContentSerializerRuntimeTypeAttribute.

How can I go from a Type representing Texture2DContent to a Type representing Texture2D?

I know I can just check for EndsWith("Content") as a last resort, but how to I get the namespace qualified type so I can get my Type object?


Find all Types that inherit from ContentTypeWriter and have generic argument of Texture2DContent (actualy i think writer exists only for TextureContent), create instance of them and then call GetRuntimeType

  • \$\begingroup\$ Instead of getting only ContentTypeWriter<T> for my T i got all writers that had the ContentTypeWriterAttribute and were inherited from ContentTypeWriter. I then instanciated them all and picked the one that had the correct .TargetType. \$\endgroup\$ – George Duckett Feb 13 '12 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.