Access internal C#/. NET code structures

Asked

Viewed 89 times

5

You can access the internal structures of a C# core code or C System.Core do . NET? For example, how is the method implemented First()?

Alerta alerta = query.First();

I wanted to see how it’s done behind the scenes, considering that a lot of stuff is being released by MS, compilers and such. Which way for me to access this backstage code?

  • 1

    You can use a decompiler, here you can download a good and free.

2 answers

5


Microsoft has adopted an "Open Source" policy on its products. With this, it has released in various media the codes of various products, such as the ASP.NET and the Entity Framework, for example.

In this article is explained how it happened and what is Open Source today. It is worth noting that something may have been added to the list since the date of the article, so it is worth checking the Github and see if there’s anything new.

It is worth mentioning in this answer the mono project. You can find more details about him in this answer.

The code you requested, specifically the method First(), can be seen below:

    public static TSource First<TSource>(this IQueryable<TSource> source) {
        if (source == null)
            throw Error.ArgumentNull("source");
        return source.Provider.Execute<TSource>(
            Expression.Call(
                null,
                GetMethodInfo(Queryable.First, source),
                new Expression[] { source.Expression }
                ));
    }

    public static TSource First<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate) {
        if (source == null)
            throw Error.ArgumentNull("source");
        if (predicate == null)
            throw Error.ArgumentNull("predicate");
        return source.Provider.Execute<TSource>(
            Expression.Call(
                null,
                GetMethodInfo(Queryable.First, source, predicate),
                new Expression[] { source.Expression, Expression.Quote(predicate) }
                ));
    }

Link to the original code.

  • Thank you Randrade. It was this structure I wanted to see. I knew there was greater freedom in this sense but I didn’t know where to start. vlww

4

Microsoft provides a dedicated website for code consultation with easy navigation. One of several implementations of First(), for example. No .NET Core.

In addition it is possible to see the official repositories of the various projects already placed in the Randrade response.

  • I didn’t know this site, +1

  • Thanks bigow, the site will give me a cool help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.