Can I serialize a C# Type object?

前端 未结 6 1562
南方客
南方客 2020-12-04 17:18

I\'m trying to serialize a Type object in the following way:

Type myType = typeof (StringBuilder);
var serializer = new XmlSerializer(typeof(Type));
TextWrit         


        
6条回答
  •  难免孤独
    2020-12-04 17:56

    Just looked at its definition, it is not marked as Serializable. If you really need this data to be serialize, then you may have to convert it to a custom class that is marked as such.

    public abstract class Type : System.Reflection.MemberInfo
        Member of System
    
    Summary:
    Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types.
    
    Attributes:
    [System.Runtime.InteropServices.ClassInterfaceAttribute(0),
    System.Runtime.InteropServices.ComDefaultInterfaceAttribute(System.Runtime.InteropServices._Type),
    System.Runtime.InteropServices.ComVisibleAttribute(true)]
    

提交回复
热议问题