【问题标题】:Specify an Inline Array to Custom Attribute in VB.NET在 VB.NET 中为自定义属性指定内联数组
【发布时间】:2011-04-20 20:45:39
【问题描述】:

我想知道是否有任何方法可以指定内联数组(比如说字符串) 在 vb.net 中自定义属性。

我有以下示例在 vb.net (.net 1.1) 中无法编译:

Attributes.ManyToOne(New String() {"a", "b", "c"})> _
Public Property PaymentTerms() As PaymentTerms

该属性在另一个程序集中定义为:

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
 public class ManyToOne : System.Attribute
 {
  private string[] _columns;


  public ManyToOne(string[] columns)
  {
   _columns = columns;
  }

  public string[] Columns
  {
   get { return _columns; }
   set { _columns = value; }
  }
 }

当我将数组提供给 vb.net 中的自定义属性时,出现编译器错误。 我在 C# 中没有问题,只是 vb.net。这种愚蠢的语言的正确语法是什么?

重要提示:使用 .net 1.1。

【问题讨论】:

  • 在 VS2008 中尝试时效果很好。我的 VS2003 安装早已不复存在,您也许找到了升级的好理由。
  • 这是我的恐惧。我担心,VB.net 1.1 不支持属性中的数组声明。我需要有人来验证 .net 1.1 上的 VB.net 是否如此。

标签: vb.net arrays custom-attributes


【解决方案1】:

框架的 .net 1.1 不支持 VB.net 属性声明中的数组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 2013-05-25
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多