I have a custom attribute class SoftwareAttribute where i need to set some string and datetime value.
[AttributeUsage(AttributeTargets.All)]
class SoftwareAttribute : Attribute
{
string projectName;
DateTime startDate, endDate;
public SoftwareAttribute(string pname, DateTime start, DateTime end)
{
projectName = pname;
startDate = start;
endDate = end;
}
public virtual string ProjectName
{
get { return projectName; }
set { projectName = value; }
}
public virtual DateTime StartDate
{
get { return startDate; }
set { startDate = value; }
}
public virtual DateTime EndDate
{
get { return endDate; }
set { endDate = value; }
}
}
Now Payroll class is as follow
[Software("Payroll ,new DateTime(2013,10,15), new DateTime(2013,11,10))]
class Payroll
{
}
As i am trying to add 'new DateTime(2013,10,15)'. This statement raises error:-
'An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type'
How can i set datetime for startdate and enddate attribute from Payroll class.
And I don't want to use string for datetime.
Thank you.