C
C#3mo ago
hutoanhill

✅ Understanding and working around `this`

I am developing an API that uses .NET 8 Identity. i had it all up and running, but i needed the default endpoints defined in app.MapIdentityApi<IdentityUser>() to work a little differently. i was told in order to get this functionality i needed to re impliment those endpoints. So i dug into the libraries (spesificly IdentityApiEndpointRouteBuilderExtensions.cs in the namespace Microsoft.AspNetCore.Routing), found MapIdentityApi, and coppied it into Program.cs. So far so good. ive coppied in a bunch of other code and ive got it all working... Except... the signiture:
public static IEndpointConventionBuilder MapIdentityApi<TUser>(this IEndpointRouteBuilder endpoints)
where TUser : class, new(){
public static IEndpointConventionBuilder MapIdentityApi<TUser>(this IEndpointRouteBuilder endpoints)
where TUser : class, new(){
I have no idea what to do about this IEndpointRouteBuilder endpoints. What does the this keyword do? how can i simulate the functionality of the endpoints parameter? Is this a lost cause? Why don't libraries have comments?
11 Replies
jcotton42
jcotton423mo ago
The this modifier makes it an extension method
jcotton42
jcotton423mo ago
Extension Methods - C#
Extension methods in C# enable you to add methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.
hutoanhill
hutoanhill3mo ago
its an extention of IEndpointRuteBuilder?
jcotton42
jcotton423mo ago
Yes
hutoanhill
hutoanhill3mo ago
huge. thanks a ton!
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX3mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
canton7
canton73mo ago
@TeBeCo You can just close it yourself I think?
hutoanhill
hutoanhill3mo ago
yea but now i know
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server