mardi 12 septembre 2017

How to invoke Custom Attribute using reflection ib C#?

I have a method in which I am invoking methods of different classes at run time using reflection, code is below :

var assembly = System.Reflection.Assembly.GetExecutingAssembly();
string[] assemblyInfo = assembly.FullName.Split(',');
var controllerType = assembly.GetType(assemblyInfo[0] + ".Class1");
var controllerObj = System.Activator.CreateInstance(controllerType);
var method = controllerObj.GetType().GetMethod("Method1");
object[] parameters = new object[] { "-SomeParameterObject-" };
var obj = method.Invoke(controllerObj, parameters);

And each invoked method has Custom Attribute but it's not getting invoked in reflection. E.g.

[ReadWrite]
public Object SomeMethodName(Object param)

Is there any way in reflection by which custom attribute should get invoked automatically with method invocation ?

Thanks in advance.





Aucun commentaire:

Enregistrer un commentaire