Click here to Skip to main content
15,889,462 members
Home / Discussions / C#
   

C#

 
AnswerRe: Reflection - dynamically adding custom attributes Pin
Not Active18-Aug-10 8:43
mentorNot Active18-Aug-10 8:43 
GeneralRe: Reflection - dynamically adding custom attributes Pin
Ian Shlasko18-Aug-10 9:00
Ian Shlasko18-Aug-10 9:00 
AnswerRe: Reflection - dynamically adding custom attributes Pin
I Believe In GOD18-Aug-10 9:18
I Believe In GOD18-Aug-10 9:18 
GeneralRe: Reflection - dynamically adding custom attributes Pin
Not Active18-Aug-10 15:45
mentorNot Active18-Aug-10 15:45 
AnswerRe: Reflection - dynamically adding custom attributes Pin
AspDotNetDev18-Aug-10 10:17
protectorAspDotNetDev18-Aug-10 10:17 
AnswerRe: Reflection - dynamically adding custom attributes Pin
Member 267876219-Aug-10 3:08
Member 267876219-Aug-10 3:08 
AnswerRe: Reflection - dynamically adding custom attributes Pin
Chris Trelawny-Ross19-Aug-10 6:04
Chris Trelawny-Ross19-Aug-10 6:04 
QuestionReflection - Dynamically invoking property Pin
imak18-Aug-10 7:13
imak18-Aug-10 7:13 
My class exposes some controls via properties. I need to invoke certain properties of these controls that are decorated with my custom attributes. So let’s take example. Here is how my class look like

public partial class Form1 : Form
{

public Control Button1
{
get { return this.btn1; }
}

[MyCustomAttributes]
public Control Button2
{
get { return this.btn2; }
}
}

Now I want to dyanmically call Visible property to false on the Control properties that are decorated with MyCustomAttributes attribute.


PropertyInfo[] PI = typeof(Form1).GetProperties();

foreach (PropertyInfo property in PI)
{
MyCustomAttributes myAtt = (MyCustomAttributes)Attribute.GetCustomAttribute(property, typeof(MyCustomAttributes));
if (myAtt == null) continue;
property.SetValue("Visible", false, null); }

But I get exception that "Property set method not found". Any ideas what I am doing wrong here?
AnswerRe: Reflection - Dynamically invoking property Pin
Ian Shlasko18-Aug-10 7:28
Ian Shlasko18-Aug-10 7:28 
GeneralRe: Reflection - Dynamically invoking property Pin
Ennis Ray Lynch, Jr.18-Aug-10 7:29
Ennis Ray Lynch, Jr.18-Aug-10 7:29 
GeneralRe: Reflection - Dynamically invoking property Pin
Ian Shlasko18-Aug-10 8:59
Ian Shlasko18-Aug-10 8:59 
GeneralRe: Reflection - Dynamically invoking property Pin
imak18-Aug-10 8:07
imak18-Aug-10 8:07 
GeneralRe: Reflection - Dynamically invoking property Pin
Ian Shlasko18-Aug-10 8:58
Ian Shlasko18-Aug-10 8:58 
AnswerRe: Reflection - Dynamically invoking property Pin
Ennis Ray Lynch, Jr.18-Aug-10 7:28
Ennis Ray Lynch, Jr.18-Aug-10 7:28 
GeneralRe: Reflection - Dynamically invoking property Pin
harold aptroot18-Aug-10 7:47
harold aptroot18-Aug-10 7:47 
GeneralRe: Reflection - Dynamically invoking property Pin
Ennis Ray Lynch, Jr.18-Aug-10 8:02
Ennis Ray Lynch, Jr.18-Aug-10 8:02 
GeneralRe: Reflection - Dynamically invoking property Pin
harold aptroot18-Aug-10 8:41
harold aptroot18-Aug-10 8:41 
GeneralRe: Reflection - Dynamically invoking property Pin
Ennis Ray Lynch, Jr.18-Aug-10 8:43
Ennis Ray Lynch, Jr.18-Aug-10 8:43 
AnswerRe: Reflection - Dynamically invoking property Pin
Luc Pattyn18-Aug-10 13:41
sitebuilderLuc Pattyn18-Aug-10 13:41 
GeneralRe: Reflection - Dynamically invoking property Pin
Eddy Vluggen18-Aug-10 9:56
professionalEddy Vluggen18-Aug-10 9:56 
GeneralRe: Reflection - Dynamically invoking property Pin
harold aptroot18-Aug-10 10:38
harold aptroot18-Aug-10 10:38 
GeneralRe: Reflection - Dynamically invoking property Pin
Ian Shlasko18-Aug-10 10:58
Ian Shlasko18-Aug-10 10:58 
AnswerRe: Reflection - Dynamically invoking property Pin
Luc Pattyn18-Aug-10 13:44
sitebuilderLuc Pattyn18-Aug-10 13:44 
GeneralRe: Reflection - Dynamically invoking property Pin
imak18-Aug-10 8:09
imak18-Aug-10 8:09 
GeneralRe: Reflection - Dynamically invoking property Pin
Ennis Ray Lynch, Jr.18-Aug-10 8:10
Ennis Ray Lynch, Jr.18-Aug-10 8:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.