1

i am creating instance of class by using Activator in c# mvc. but i have to add attribute for example

[required]

dynamically to the instance. so how can i do it.

MaTya
  • 782
  • 6
  • 11
  • possible duplicate of [Can attributes be added dynamically in C#?](http://stackoverflow.com/questions/129285/can-attributes-be-added-dynamically-in-c) – Alexander Manekovskiy Feb 03 '14 at 05:28
  • simply, you **can't.** – Selman Genç Feb 03 '14 at 05:29
  • @MaTya You cannot add attributes at runtime to already existent type. Maybe you will benefit from approach similar to Fluent Validation project (http://fluentvalidation.codeplex.com/). If you need dynamically determine input validation rules you can take for example a Builder pattern and combined with Fluent Validation you can achieve the goal. Anyways providing more background will help people here to help you find an answer. – Alexander Manekovskiy Feb 03 '14 at 05:35
  • thanks but can i add attribute when i creating object of class? becoz i creating class using xml data. http://blogs.microsoft.co.il/gilf/2012/04/23/generating-aspnet-mvc-view-controls-according-to-xml-configurations/ plz see this for reference here i want to add attribute. – MaTya Feb 03 '14 at 05:40

0 Answers0