如何替换.NET Standard的System.ComponentModel.DataAnnotations类?

cof*_*unk 10 .net-core .net-standard

.NET Standard不支持'System.ComponentModel.DataAnnotations'和'System.Type.Properties',如何与它保持兼容?

svi*_*ick 19

从类型System.ComponentModel.DataAnnotations命名空间是在System.ComponentModel.Annotations,这是不是默认在.NET标准库安装,所以你需要手动安装它那里使用它.

如果您的意思是Type.GetProperties(),那么该方法在.Net Core和.Net Standard中作为扩展方法存在.在.Net标准库中,您需要安装System.Reflection.TypeExtensions软件包.在.Net Core应用程序和.Net标准库中,您都需要添加using System.Reflection;到源代码中.