【问题标题】:Unable to use data annotations in .net core 1.0无法在 .net core 1.0 中使用数据注释
【发布时间】:2016-07-26 18:02:48
【问题描述】:

就像早期 beta (dnx) 时期的 this question 一样,我正在尝试将代码移植到 .net core 1.0 rtm,并且代码回复了以下单元,其中包含 ValidationAttribute 类型和其他内容:

using System.ComponentModel.DataAnnotations;

namespace Hl7.Fhir.Introspection
{
    [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    public sealed class FhirElementAttribute : ValidationAttribute
    ...

如何将此类代码移植到 dotnet core 1.0 rtm?

【问题讨论】:

  • 一些早期的测试版建议单元名称更改为 System.ComponentModel.Annotations,但这不起作用。
  • 你试过this吗?
  • 哦,这是预发布的位,但不是 dotnet-RC2 级别的位
  • 哎呀...我的错 :) This one 应该是你要找的人

标签: c# visual-studio-2015 data-annotations .net-core


【解决方案1】:

我使用非官方的Reverse Package Search 在新的 Microsoft 开源包中搜索类。

您正在寻找System.Runtime.AttributeUsageAttribute 内的System.Runtime 包。它适用于.NET Standard 1.0 及更高版本。

编辑: 对不起。你问的是ValidationAttribute,而不是AttributeUsage,我的错。反向包search指向System.ComponentModel.Annotations

【讨论】:

  • 谢谢。为我节省了很多时间。
猜你喜欢
  • 2016-11-02
  • 1970-01-01
  • 2015-08-08
  • 1970-01-01
  • 1970-01-01
  • 2017-05-01
  • 1970-01-01
  • 2017-05-28
  • 1970-01-01
相关资源
最近更新 更多