Refection problems

  • Thread starter csharpula csharp
  • Start date
C

csharpula csharp

Hello ,
I would like to ask about the following issue:

I am activating this code after i created the InitializationAttribute
and added it above objects:

PropertyInfo[] properties = this.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
object[] attributes =
property.GetCustomAttributes(typeof(InitializationAttribute),true);
}

I get an empty list of object[] attributes although I have objects
which are signed with this attribute in code.
Why is that?
Thank u!
 
L

Lasse Vågsæther Karlsen

csharpula said:
Hello ,
I would like to ask about the following issue:

I am activating this code after i created the InitializationAttribute
and added it above objects:

PropertyInfo[] properties = this.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
object[] attributes =
property.GetCustomAttributes(typeof(InitializationAttribute),true);
}

I get an empty list of object[] attributes although I have objects
which are signed with this attribute in code.
Why is that?
Thank u!

It is unclear what you're doing.

1. Are you marking the class with the attribute? or
2. Are you marking the properties with the attribute?

And,

3. Are you checking the "attributes" array for each iteration? or
4. Only after the last one?

It would help if you could post a short, but complete, project that
demonstrates your problem. See
http://www.yoda.arachsys.com/csharp/complete.html
for a description of what a short and complete program is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top