No, that stuff depends on ILSpy's context for the "current class".
But here's the extension method for point 2:
public static bool IsCompilerGenerated(this ICustomAttributeProvider
provider)
{
if (provider.HasCustomAttributes) {
foreach (CustomAttribute a in provider.CustomAttributes) {
if (a.AttributeType.FullName
== "System.Runtime.CompilerServices.CompilerGeneratedAttribute")
return true;
}
}
return false;
}
public static bool IsCompilerGeneratedOrIsInCompilerGeneratedClass(this
IMemberDefinition
member)
{
if (member == null)
return false;
if (member.IsCompilerGenerated())
return true;
return
IsCompilerGeneratedOrIsInCompilerGeneratedClass(member.DeclaringType);
}On 3/5/2011 01:24, Greg Young wrote: > Do you happen to have an extension method for this? :) > > On Fri, Mar 4, 2011 at 12:21 PM, Daniel Grunwald > <[email protected]> wrote: >> You mean anonymous methods / lambdas? >> That's not possible; there isn't any unique attribute identifying them. >> >> The logic we're currently using in ILSpy is: >> 1) Method name must start with "<" >> 2) The [CompilerGenerated] attribute must be applied to the method or to >> one of the method's declaring types (doesn't have to be the direct >> containing type if there are nested lambdas) >> 3) The method must be declared in the current class or in one of its >> nested classes. >> >> Daniel >> >> On 3/4/2011 17:35, Greg Young wrote: >>> Is there any way to reliably find delegate methods? I know I can >>> identify them as compiler generated. I also know they follow a naming >>> standard but would prefer to not lock myself into such decisions by >>> the compiler writer. >>> >>> My guess is that I will have to make the latter dependency but if >>> anyone has another way? >>
signature.asc
Description: OpenPGP digital signature
