Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# pull appart property chain in expression

public static class PropertyPath<TSource>
{
    public static IReadOnlyList<MemberInfo> Get<TResult>(Expression<Func<TSource, TResult>> expression)
    {
        var visitor = new PropertyVisitor();
        visitor.Visit(expression.Body);
        visitor.Path.Reverse();
        return visitor.Path;
    }

    private class PropertyVisitor : ExpressionVisitor
    {
        internal readonly List<MemberInfo> Path = new List<MemberInfo>();

        protected override Expression VisitMember(MemberExpression node)
        {
            if (!(node.Member is PropertyInfo))
            {
                throw new ArgumentException("The path can only contain properties", nameof(node));
            }

            this.Path.Add(node.Member);
            return base.VisitMember(node);
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: converting alpha1 into int unity 
Csharp :: c# open explorer and select file 
Csharp :: who is dani? game dev 
Csharp :: c# words return first 20 items of array 
Csharp :: c# try catch multiple catches 
Csharp :: c# sort a list of objects 
Csharp :: sterge element din coada c# 
Csharp :: c# string is all zeros 
Csharp :: C# if...else Statement 
Csharp :: c# access control from another thread 
Csharp :: temp^late php table for mysql 
Csharp :: unity AppDomain 
Csharp :: c# (sharp) varibles 
Csharp :: Implementing Banner Ads Unity 
Csharp :: how to disable button until the value is selected c# 
Csharp :: how to set an expiry date on a program 
Csharp :: asp.net Read raw Body 
Csharp :: attribute decorator to require email format of string c# 
Csharp :: switch case c# enum tostring 
Csharp :: 1.1 0da14962afa287e5ba55c7d30c902392.cloudfront.net w 
Csharp :: c# open config file by path 
Csharp :: webtest fullscreen extend window maximize 
Csharp :: c# fastest way to find item in list 
Csharp :: sort number in dynamo 
Csharp :: unity Polymorphism 
Csharp :: UnitType parameter revit 2022 
Csharp :: mac osx enable hidpi terminal 
Csharp :: how to validate decimal number with percision of (25, 4) iin c# 
Csharp :: multiple lines in string c# parameterized 
Csharp :: c# stack 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =