Access internal code structures C # / .NET

5

Is it possible to access the inner structures of a C # core code or .NET System.Core libraries? For example, how is the First() method implemented?

Alerta alerta = query.First();

I wanted to see how this is done behind the scenes, considering that a lot is being released by MS, the compilers and such. What is the way for me to access this code behind the scenes?

    
asked by anonymous 16.06.2016 / 19:42

2 answers

5

Microsoft has adopted an "Open Source" policy on its products. As a result, it has released various product codes, such as ASP.NET , and the Entity Framework , for example.

This article explains how it happened and what is Open Source today. It's worth mentioning that something may have been added to the list since the date of the article, so check out the GitHub and see if there's anything new.

Note in this answer the mono project . You can find more details about it in this answer .

The code you requested, specifically the First() method, 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

    
16.06.2016 / 20:34
4

Microsoft provides a dedicated code query site with navigation facilities. One of several implementations of First() , for example.

In addition, it is possible to see the official repositories of the various projects already placed in Randrade's answer.

    
16.06.2016 / 21:45