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.
That’s totally impossible. Attributes are baked into the metadata of the assembly at compile-time so talking about passing an instance of a class to an attribute doesn’t make any sense because instances exist only at runtime.
On the other hand attributes are always consumed by reflection, so I guess that at the moment you are checking for the presence of this custom attribute on the class metadata you could use the the instance.