C#的问题[MyClass(IsAutoInc = true, IsPrimaryKey = true)]

[复制链接]
查看11 | 回复1 | 2011-6-6 18:23:49 | 显示全部楼层 |阅读模式
public class Employees
{

[MyClass(IsAutoInc = true, IsPrimaryKey = true)]

private int _EmployeesID;

public int EmployeesID

{

get { return _EmployeesID; }

set { _EmployeesID = value; }

}

private string _Name;

public string Name

{

get { return _Name; }

set { _Name = value; }

}

private string _Birthday;

public string Birthday

{

get { return _Birthday; }

set { _Birthday = value; }

}

private string _Orgin;

public string Orgin

{

get { return _Orgin; }

set { _Orgin = value; }

}

private string _Sex;

public string Sex

{

get { return _Sex; }

set { _Sex = value; }

}

private string _Title;

public string Title

{

get { return _Title; }

set { _Title = value; }

}

private string _Degree;

public string Degree

{

get { return _Degree; }

set { _Degree = value; }

}

private string _Education;

public string Education

{

get { return _Education; }

set { _Education = value; }

}

private string _Phone;

public string Phone

{

get { return _Phone; }

set { _Phone = value; }

}

private string _Email;

public string Email

{

get { return _Email; }

set { _Email = value; }

}

private string _Adress;

public string Adress

{

get { return _Adress; }

set { _Adress = value; }

}

private string _Department;

public string Department

{

get { return _Department; }

set { _Department = value; }

}
}
[AttributeUsage(AttributeTargets.Property)]
class MyClass : Attribute
{

public MyClass()

{

IsPrimaryKey = false;

IsAutoInc = false;

}

private bool _IsPrimaryKey;

public bool IsPrimaryKey

{

get { return _IsPrimaryKey; }

set { _IsPrimaryKey = value; }

}
private bool _IsAutoInc;

public bool IsAutoInc

{

get { return _IsAutoInc; }

set { _IsAutoInc = value; }

}
}
会提示这样的错误
错误        1        属性“MyClass”在该声明类型中无效。它只在“property, indexer”声明中有效。        C:\Users\Administrator\Documents\Visual Studio 2005\WebSites\闽江学院软件学院人才管理系统\App_Code\Train.cs        22        6        C:\...\闽江学院人才管理系统\

回复

使用道具 举报

千问 | 2011-6-6 18:23:49 | 显示全部楼层
private int _EmployeesID; [MyClass(IsAutoInc = true, IsPrimaryKey = true)]
public int EmployeesID
{
get { return _EmployeesID; }
set { _EmployeesID = value; }
}这样呗...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行