我正在使用几个代码转换器,它们产生相同的 VB.Net 编码,但除了这行代码之外,VS 不会:
Private Overridable m_Products As ICollection(Of Product)
VS 状态:
'Overridable' 在成员变量声明中无效。
C# 编码来自 ASP.Net 网站上的教程:
http://www.asp.net/web-forms/tutorials/aspnet-45/getting-started-with-aspnet-45-web-forms/create_the_data_access_layer
VS 还声明我应该删除 Overridable 关键字。如果我这样做,我会破坏教程中的内容吗?
这是我通过转换器运行的 C# 编码:
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace WingtipToys.Models
{
public class Category
{
[ScaffoldColumn(false)]
public int CategoryID { get; set; }
[Required, StringLength(100), Display(Name = "Name")]
public string CategoryName { get; set; }
[Display(Name = "Product Description")]
public string Description { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
}
这是转换的结果:
Imports System.Collections.Generic
Imports System.ComponentModel.DataAnnotations
Namespace WingtipToys.Models
Public Class Category
<ScaffoldColumn(False)> _
Public Property CategoryID() As Integer
Get
Return m_CategoryID
End Get
Set
m_CategoryID = Value
End Set
End Property
Private m_CategoryID As Integer
<Required, StringLength(100), Display(Name := "Name")> _
Public Property CategoryName() As String
Get
Return m_CategoryName
End Get
Set
m_CategoryName = Value
End Set
End Property
Private m_CategoryName As String
<Display(Name := "Product Description")> _
Public Property Description() As String
Get
Return m_Description
End Get
Set
m_Description = Value
End Set
End Property
Private m_Description As String
Public Overridable Property Products() As ICollection(Of Product)
Get
Return m_Products
End Get
Set
m_Products = Value
End Set
End Property
Private Overridable m_Products As ICollection(Of Product)
End Class
End Namespace