pagates,
Ok, I understand now.
So, when you have theattributelike this:
[ACustomAttribute("Some CustomAttributeValue")]
public string SomeProperty
The runtime constructs an instance of ACustomAttribute passing the value
of "Some CustomAttributeValue". What the constructor does with this is up
to theattributeclass. It's like any other class in this sense.
Typically, however, it will be exposed as aproperty. So, on the
ACustomAttribute class, there should be some sort ofpropertythat exposes
the value. When you call GetCustomAttributes, you can cast the return value
to an instance of ACustomAttribute and then access thepropertytogetthe
value (assuming it is exposed as such).
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Sure - it's a general question, but I wasn't sure how to word it...
Say I have something like this:
public class Class1
{
public Class1()
{
}
string _someProperty;
[ACustomAttribute("Some CustomAttributeValue")]
public string SomeProperty
{
get{ return _someProperty; }
set { _someProperty = value; }
}
}
I simply want to usereflectiontoget"Some CustomAttributeValue" from
the ACustomAttributeattributein a program that loads the assembly that
contains Class1. I can use GetCustomAttributes togettheattribute
itself,
but I can't quitegethow togetthe value of the parameter contained
therein.
Does that make sense? I can see what I want in my head, but getting it
out
of there might be a problem.... : )
pagates,
Custom attributes are classes, they are not methods with parameters.
Getting any information from them usingreflectionis like using
reflection
togetinformation from any other class. You have to have some
expectation
of what you are looking for.
Can you provide an example of what you are trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Hello All,
I am sure that I am just overlooking something, but here's something I
can't
quitegetright...
I want to be able togetthe value of a parameter of an unknown custom
attributeat runtime. All of the examples I have seen use casting of
known
custom attributes togetthesevalues.
Thanks,
pagates- Hide quoted text -
- Show quoted text -