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

  • SEARCH
  • Home
  • 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 7504271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:31:10+00:00 2026-05-29T21:31:10+00:00

I am using C# to create a view model that I later serialize into

  • 0

I am using C# to create a view model that I later serialize into Json for use with KnockoutJs.

Now I need to add information on a property level if a certain user has access to view and/or edit the property.

Since Javascript has little to no reflection possibilities I want to do this with C# before serializing to Json.

My view model could look like this:

class ViewModel {
    public string Name { get; set; }        
}

I want to use a User Access Service that would take the user, which has some Roles, and the view model and go through the Roles and apply the access rights. Something like this:

class AccessService {
    public void Apply(IUser user, ViewModel viewModel) {
        if(user.Roles.Contains(Roles.Admin)) {
            viewModel.AllowRead(vm => vm.Name);
        }
    }
}

The viewModel.AllowRead(..) method would be an extension method that would take an object (or maybe an interface or type if necessary) and this is where the magic would happen.

I would like the result of this operation to be that the viewModel would get a new property with the name CanRead which in turn would have a boolean property with the name Name.

The resulting viewModel would look like this:

class ViewModel {
    public string Name { get; set; }
    public object CanRead { // Could non anonymous as well.
        return new {
            Name = true;
        };
    }
}

Can this be done with dynamics or do I have to use Reflection.Emit? I’m not asking for “show me the codez”. I just want to know if my idea is mental or if it’s possible.

Any ideas?

  • 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-29T21:31:12+00:00Added an answer on May 29, 2026 at 9:31 pm

    I think it would be possible and you could use the Lambdanator to help achieve this.

    Example usage:

    Lambda.Reflect<SomeClass>(x => x.AMethod());    
    Lambda.Reflect<SomeClass>(x => x.AProperty);    
    Lambda.Reflect(() => local);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATED: I am using MySQL statement to create a view: I need to show
I'm trying to use a view to create an ADO.NET entity using a view.
I'm using MVC3 and I wanted to use a partial view to create dynamic
How do I create a view dynamically in SQL Server using C#?
I am using the Qt Graphics View framework to create a scene and attach
I'm trying to create a page by using view 2. This page list all
I am using the HtmlHelper to create a checkbox in my view like so:
I want to create 2 separate pickers in the same view using the same
I have a partial view that has a create button on it however it
I'm using javascript with backbone and adobe air. In my view model, I have

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.