Do Not Resolve Members

Warning

Be careful, because Context.Module (ModuleDefinition) doesn’t affected by DoNotResolveAttribute.

For comfort BitMono provides an API which able to do not pass specfic members inside of the protection for easier understanding and abstraction let’s call members as - types/methods/fields/properties, etc.

public override Task ExecuteAsync()
{
    Context.Parameters.Members
}

Everything which is passed inside of the Context.Parameters.Members is all members which were found inside of the module and sorted by BitMono (skipped members with [ObfuscationAttribute] and [DoNotResolveAttribute], etc), and passed using IMetadataMember AsmResolver’s APIs.

public List<IMetadataMember> Members { get; }

That’s mean if you will specify attribute on your protection and say I want all members but please, I’m writing my own renamer and I don’t want to get members which were used somewhere by reflection, right? Add attribute [DoNotResolve(MemberInclusionFlags.Reflection)] with MemberInclusionFlags.Reflection parameter.

[UsedImplicitly] // This is not intentional, but suppresses warnings by ReSharper
[DoNotResolve(MemberInclusionFlags.Reflection)]
public class MagicProtection : Protection

You can specify multiple inclusion flags.

[UsedImplicitly]
[DoNotResolve(MemberInclusionFlags.SpecialRuntime | MemberInclusionFlags.Reflection)]
public class MagicProtection : Protection

THIS IS TOTALLY BAD AND WRONG! Sorting doesn’t affects to the actual Module.

public override Task ExecuteAsync(ProtectionParameters parameters)
{
    foreach (var type in Context.Module.GetAllTypes())
    {

    }
}

Instead highly recommend to use this.

public override Task ExecuteAsync(ProtectionParameters parameters)
{
    foreach (var type in parameters.Members.OfType<TypeDefinition>())
    {

    }
}

This is also was wrong because if you will try to get access to the type.Methods, etc, methods are not sorted, use specificly what you need, for example.

Need access to the types and methods? Then do this.

public override Task ExecuteAsync(ProtectionParameters parameters)
{
    foreach (var type in parameters.Members.OfType<TypeDefinition>())
    {

    }
    foreach (var type in parameters.Members.OfType<MethodDefinition>())
    {

    }
}

Need access to the methods? Then just iterrate through the methods.

public override Task ExecuteAsync(ProtectionParameters parameters)
{
    foreach (var type in parameters.Members.OfType<MethodDefinition>())
    {

    }
}