postsharp / Metalama

Metalama is a Roslyn-based meta-programming framework. Use this repo to report bugs or ask questions.
174 stars 5 forks source link

Feature: Specify 'this' keyword on introduced parameters #339

Open WhitWaldo opened 1 month ago

WhitWaldo commented 1 month ago

I would like to introduce a static extension method to a type and am able to create the method and mark it as static without issue. But when introducing the parameters to the introduced method, there isn't an option to indicate that the 'this' keyword should be inserted, leaving one unable to actually create an extension method.

        var serviceCollectionType = (INamedType)TypeFactory.GetType(typeof(IServiceCollection));

        builderType.IntroduceMethod(nameof(BuildMethodTemplate),
            IntroductionScope.Static,
            buildMethod: b =>
            {
                b.Name = "RegisterAllEntities";
                b.Accessibility = Accessibility.Public;
                //b.AddParameter("serviceCollection", serviceCollectionType); //Need some way to specify 'this'
            });

I would like to request such a capability. Thank you for the consideration!

gfraiteur commented 1 month ago

Thank you for spotting this gap.