Skip to content

Add support to skip scanning some methods when building TypeDetails #2959

@bfcamara

Description

@bfcamara

From a .net core lib I am consuming a legacy lib written in .net 3.5. I am configuring some mappings with classes that live in that lib. Some of these classes are exposing some non-static public methods that returns or receives as arguments non-compatible types with .net core (types residing in System.Web or System.Web.Services). Even though, I am sure that these methods won't be used from the code I am building, I am getting an error in startup because of the following method that runs when creating internally the type details

        private MethodInfo[] BuildPublicNoArgMethods()
        {
            return Type.GetAllMethods()
                .Where(mi => mi.IsPublic && !mi.IsStatic && mi.DeclaringType != typeof(object))
                .Where(m => (m.ReturnType != typeof(void)) && (m.GetParameters().Length == 0))
                .ToArray();
        }

Since the return or parameter type cannot be loaded, the initialization process stops with a TypeLoadException.

Changing the legacy assembly is not an option because is out of my control. And I am trying to avoid to add a reference to System.Web or System.Web.Services just for the purpose to fool the initialization mapping.

To prevent this issue, it would be great if we could limit what is being scanned during type details creation. I can think of several solutions

  1. Add new config property SkipScanPublicNoArgMethods - In this case non-static public methods won't be scanned at all
  2. Add new config property IgnoreTypeLoadErrorsInPublicMethods
  3. Add a new config property ShouldScanPublicMethod (Func<MethodInfo, bool>)

I think 1) is very simple. Do you think any of these solutions is reasonable?

Please let me know yout thoughts.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions