Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1033091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:10:49+00:00 2026-05-16T14:10:49+00:00

This is a very complicated question even though it looks simple. I think I

  • 0

This is a very complicated question even though it looks simple. I think I would have to traverse the entire expression tree unless someone knows a better way.

Let’s say I have a user object

class User
{
    public UserAccount Account {get;set;}
}
class UserAccount
{
    public Name {get;set;}
}
var user = new User() { Account = new UserAccount()};

How could I use linq expressions to set the property of Name

SetValue(c => c.Account.Name, "Test");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:10:49+00:00Added an answer on May 16, 2026 at 2:10 pm

    Well, you’d not only have to traverse the expression tree: you’d also have to convert final property “getter” you encounter into a property “setter”. Essentially you’d want to find the expression which acts as the “target” of the getter (i.e. the object it’s going to get the property of), evaluate it to get the target, then find the corresponding setter for the final property, and call it with the target and the new value.

    Note that by only requiring the expression tree to represent the “getter”, you’re losing some of the compile-time safety you might expect… because a caller could pass in a read-only property:

    SetValue(c => c.Account.Name.Length, 0); // string.Length is read-only
    

    Another alternative would be to change your code to make the lambda expression represent the setter instead:

    SetValue((c, value) => c.Account.Name = value, "Test");
    

    Then you wouldn’t even need an expression tree – you could use a simple delegate, and just execute it appropriately.

    Unfortunately you haven’t really given us enough information about what you’re trying to achieve to know whether this is a feasible suggestion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a very complicated question concerning how to serialize data via a web
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
This very simple code gives me tons of errors: #include <iostream> #include <string> int
I've written this very simple function to replace a file extension using LINQ in
I'm sorry for this very newbish question, I'm not much given into web development.
i am trying to compile this very simple piece of code class myList {
Let's make this very easy. What I want: @array = qw/one two one/; my
I find this very strange, must be something I'm doing wrong, but still... I'm
I was told this a few times in this very site, but I wanted
I seem to run into this very often. I need to build a Hash

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.