Blazor 枚举范围,CS1729 'RangeAttribute' 不包含采用 4 个参数的构造函数
Blazor Enum range, CS1729 'RangeAttribute' does not contain a constructor that takes 4 arguments
我正在重写从 BlazorApp 到基于 BlazorApp Core 的应用程序的代码片段。突然现在它在定义 RangeAttribute 时抛出错误。
为什么我收到错误:
“CS1729 'RangeAttribute' 不包含采用 4 个参数的构造函数 TradeNow.Client”
我的代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace TradeNow.Client.Pages.Adverts.Data
{
public class SellBuy
{
[Required]
[Range(typeof(SellBuyN), nameof(SellBuyN.Sell), typeof(SellBuyN), nameof(SellBuyN.Buy), ErrorMessage = "Select if you are buying or selling")]
public SellBuyN SellBuyN { get; set; }
}
public enum SellBuyN { Sell, Unknown, net, smth, Buy }
}
您可以看到构造函数从不接受 4 个参数:
Constructors
CONSTRUCTORS
RangeAttribute(Double, Double)
Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.
RangeAttribute(Int32, Int32)
Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.
RangeAttribute(Type, String, String)
Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values and the specific type.
我正在重写从 BlazorApp 到基于 BlazorApp Core 的应用程序的代码片段。突然现在它在定义 RangeAttribute 时抛出错误。
为什么我收到错误:
“CS1729 'RangeAttribute' 不包含采用 4 个参数的构造函数 TradeNow.Client”
我的代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace TradeNow.Client.Pages.Adverts.Data
{
public class SellBuy
{
[Required]
[Range(typeof(SellBuyN), nameof(SellBuyN.Sell), typeof(SellBuyN), nameof(SellBuyN.Buy), ErrorMessage = "Select if you are buying or selling")]
public SellBuyN SellBuyN { get; set; }
}
public enum SellBuyN { Sell, Unknown, net, smth, Buy }
}
您可以看到构造函数从不接受 4 个参数:
Constructors
CONSTRUCTORS
RangeAttribute(Double, Double)
Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.
RangeAttribute(Int32, Int32)
Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values.
RangeAttribute(Type, String, String)
Initializes a new instance of the RangeAttribute class by using the specified minimum and maximum values and the specific type.