C# using reflection to create a struct

前端 未结 3 1608
时光取名叫无心
时光取名叫无心 2020-12-20 11:57

I am currently writing some code to save general objects to XML using reflection in c#.

The problem is when reading the XML back in some of the objects are structs a

3条回答
  •  伪装坚强ぢ
    2020-12-20 12:39

    CreateInstance will not help you with structs with no explicitly defined constructors.

    FormatterServices.GetUninitializedObject(Type type);
    

    This does the trick with blank structs.

提交回复
热议问题