roslyn: Extension Member Properties: Properties Not Available in Outside Assembly

Version Used: Visual Studio 17.14.2 Preview 1.0 10.0.100-preview.4.25258.110

Steps to Reproduce:

  1. Created an extension member property for an interface (code below)
  2. If I create the Person in the same assembly, I can use the property.
  3. If I write a unit test in a separate assembly, the property is not available.

Expected Behavior: The property should be available.

Actual Behavior: I can only access the property using code like this: PersonExtensions.get_Age(person);

Note

  1. Extension member extension methods work fine.

Other Behavior I’m not sure if any of the below is working yet.

  1. I have to manually add the namespace for the extension. Visual Studio does not seem to recognize it.
  2. In the assembly where the extension property is, “Find All References” does not work.
  3. CoPilot has issues creating XML documentation. Also recommends that I change to normal extension methods.

Interface and Extension Member Property

namespace DotNetTips.Spargine.Tester.Extensions;

public static class PersonExtensions
{

    extension([NotNull] IPerson person)
    {
        public string FullName => $"{person.FirstName} {person.LastName}";

        public TimeSpan Age => DateTimeOffset.UtcNow.Subtract(person.BornOn);
    }
}

namespace DotNetTips.Spargine.Tester.Models.RefTypes;

public interface IPerson
{
    [DataType(DataType.Date)]
    public DateTimeOffset BornOn { get; set; }

    [Phone(ErrorMessage = "The cell phone number is not in a valid format.")]
    public string CellPhone { get; set; }

    [EmailAddress(ErrorMessage = "The email address is not in a valid format.")]
    public string Email { get; set; }

    [StringLength(50, ErrorMessage = "The first name must not exceed 50 characters.")]
    public string FirstName { get; set; }

    [StringLength(50, ErrorMessage = "The last name must not exceed 50 characters.")]
    public string LastName { get; set; }

    [Phone(ErrorMessage = "The phone number is not in a valid format.")]
    public string Phone { get; set; }
}

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I did the same to my open-source project and it seems to be working too.

Thanks for your help, David McCarter