Alex Rivera | Logout

Pass instance of Class as parameter to Attribute constructor

Asked 2010-11-26T11:19:33.157
24

I need an instance of class/model(for the purpose of accessing a non-static member) within my custom attribute.

public class LoginModel
{
     [AutoComplete(currentInstance)]  //pass instance of class or CompanyNames
     public string DepartmentName { get; set; }


     public string[] DepartmentNames { get {...} }
}

Is there a way to do this without using new() or Reflection.

Edit
Report

1 Answer

3

You can only use primitives, or arrays of primitives as Attribute parameters, this is because they need to be 'in-lined' by the compiler at compile-time.

answered 2010-11-26T11:26:40.130

Your Answer