Skip to content

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

@Gorphi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageIndicates that an issue needs to be categorized.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions