Registry Mirror
Skip to content

MethodMember.Parameters doesn't return the expected amount of entries when having the same type for parameters #447

Closed

Description

@Gorphi

Hello everybody,

I was writing a Custom condition (ICondition<IType>), which validates the existence of a constructor with exactly one parameter having an expected type.

Code used for the evaluation:

private bool TypeHasMatchingConstructor(IType type)
    {
        foreach (var constructor in type.GetConstructors())
        {
            if (constructor.Parameters.Count() == 1 && constructor.Parameters.Single().FullName.Equals(_parameterType.FullName, StringComparison.Ordinal))
            {
                return true;
            }
        }

        return false;
    }

Expectation:
The constructor.Parameters returns an IEnumerable<IType> containing the types of all parameters.

However, analyzing types with multiple parameter having the same type, results in only returning one entry in the property Parameters.

// Analyzing the following type returns one entry in the Parameters Enumerable [IType: UInt32]
internal sealed record SignatureOne(uint Signature);

// Analyzing the following type returns two entries in the Parameters Enumerable [IType: UInt32, IType: String]
internal sealed record SignatureCustom(uint Signature, string SignatureString);

// ERROR: Analyzing the following type returns only one entry in the Parameters Enumerable [IType: UInt32]
internal sealed record SignatureTwo(uint Signature, uint SignatureTwo);

Let me know if you have any questions!

Cheerz

Activity

  1. added
    needs-triage
    on Jan 22, 2026
  2. Gorphi commented on Jan 23, 2026

    @Gorphi
    Author

    I think I found the potential cause for this in MonoCecilMemberExtensions.GetParameters and MonoCecilMemberExtensions.GetGenericParameters.

    Maybe this behaviour is on purpose?

  3. added
    kind/feature
    triage/accepted
    and removed
    needs-triage
    on Mar 2, 2026
  4. alexanderlinne commented on Mar 2, 2026

    @alexanderlinne
    Collaborator

    Hi @Gorphi, this is on purpose in so far as this has not been a use case of this library in the past. I've created a PR that ensures the parameters stored for a method are not deduplicated for the type itself, but only when instantiating the dependencies.

  5. Gorphi commented on Mar 6, 2026

    @Gorphi
    Author

    v0.13.3 works like a charm. 🚀

    ty for your fast response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featuretriage/accepted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions