Identifing Deprecated Functions via reflection

  • Thread starter Thread starter Rich Noons
  • Start date Start date
R

Rich Noons

Hi,

I'm trying to recognise whether a function is deprecated or not when
reflecting a method.

eg.

[Obsolete ("This function will error",true)]

or

[Obsolete]

Am I right in saying that the attributes value
(System.Reflection.MethodAttributes) is 6278? - is this a safe assumption?,
I guess the value could vary which is why I'm a bit worried.

I've been looking through the example on MSDN

http://msdn.microsoft.com/library/d...ystemreflectionmethodattributesclasstopic.asp

and created a sample app, but there doesn't look to be any difference. Is
there any way of telling via reflection that the obsolete method has the
true parameter?

Many thanks

Rich

Using the sample on MSDN, and reflecting an assembly with these two methods

[Obsolete ("This function will error",true)]
public string UsingDeprecatedFunction(string aString)
{
}

public string UsingaNormalFunction(string aString)
{
}

The results are
UsingDeprecatedFunction

(System.String aString)

Attributes :

PrivateScope

FamANDAssem

Family

Public

HideBySig

ReuseSlot

UsingaNormalFunction

(System.String aString)

Attributes :

PrivateScope

FamANDAssem

Family

Public

HideBySig

ReuseSlot
 
Am I right in saying that the attributes value
(System.Reflection.MethodAttributes) is 6278? - is this a safe assumption?,
No


and created a sample app, but there doesn't look to be any difference. Is
there any way of telling via reflection that the obsolete method has the
true parameter?

Just use MethodInfo.GetCustomAttributes and check if the
ObsoleteAttribute is present. If so, check the IsError property.



Mattias
 
Back
Top