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 8636585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:15:52+00:00 2026-06-12T10:15:52+00:00

I wish to give a Person as defined below, the ability to print a

  • 0

I wish to give a Person as defined below, the ability to print a vCard out of my system. To provide the user with privacy options, the user can select whether to show/hide certain properties. In it’s simplest form, I need to have a separate table that would hold the user’s choices.

I was wondering if it was possible to build this configurator table using reflection. As shown in the Person model below, I could decorate properties with a custom attribute, and then using those properties, construct and persist a model that would have a bool property for every decorated Person property.

public class Person
{
    public string UserName { get; set; }
    public string FirstName { get; set; }

    [DisplayOnVCard]
    public string LastName { get; set; }

    [DisplayOnVCard]
    public string Email { get; set; }

    [DisplayOnVCard]
    public string MobilePhone { get; set; }
}

** where [DisplayOnVCard] is a custom attribute.*

At the end of this, I expect a table in the db that would correspond to this:

public class VCardConfigurator
{
    public bool LastName { get; set; }
    public bool Email { get; set; }
    public bool MobilePhone { get; set; }
}

This is just a sample representation of what is actually a huge entity. Which is why I hope to avoid manually mapping a bool field to each optional property.

I believe this problem domain is quite similar to how, for instance, privacy settings work on social networking sites, yes?

While I was typing this, I did ponder upon the possibility that if down the line I was to remove the attribute from one of the properties, what implications that might have. Needs some thought!

Further reading for self:

  • Programmatically adding properties to an MVC model at runtime

There is a huge possibility that I am galloping down a totally wrong path! If that is the case, please advice so!

  • 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-06-12T10:15:54+00:00Added an answer on June 12, 2026 at 10:15 am

    #1 Update

    I am not sure its possible to add or remove attributes for an instance since attributes are at the class level, but their property values can be changed (Since they are instances).

    My suggested solusion

    I am not sure what you mean in “I expect a table in the db that would correspond to this”,
    since you can’t have a table in the database that contains only the columns of the non-privacy properties for each user.

    You will need a dedicated table for this mapping (Lets say ‘PrivacyMappings’ table), with these columns:
    UserId, PropertyName, IsPrivate.

    When a user is added, all the properties will be added to this table with a default privacy settings (for instance, all properties are non-private by default).
    You can add the properties by iterating over them and insert them as you said.

    You can use the following class in entity framework:

    public class PrivacyMapping
    {
    public int UserId {get;set;}
    public string PropertyName {get;set;}
    public bool IsPrivate {get;set;}
    }
    

    Adding the default privacy settings when a user being added:

    // retrieve user model properties.
    
    foreach (property in properties)
    {
    //iterrate over the user Properties.
    context.PrivacyMapping.Add(new PrivacyMapping(user.userId, propertyName, isPrivate);
    }
    
    context.SaveChanges()
    

    Now you can take all the user non-private properties by

    context.PrivacyMapping.Where(p=>p.UserId == user.id && !IsPrivate).Select(p=>p.PropertyName);
    

    And now you can deal with information any way you want.

    For example, you can have a VCardItems class, that receive an user id/object in its c’tor and stores a dictionary of the allowed properties by their names.

    public class VCardItems{
    
    private Dictionary<string, object> properties{get;set;}
    
    public VCardItems(User user)
    {
    // initiate values..
    }
            public object this[string name] {
                get 
                { 
                    if (properties.ContainsKey(name))
                    {
                        return properties[name];
                    }
    
                    // A private property.
                    return null;
    
                }
                set 
                {
                    properties[name] = value;
                }
            }
        }
    

    There is other options of how to use the data, for example with ActionFilter that in this case sets the private properties to null or storing the non-private data in the HttpContext.Items dictionary,
    but it really up to you.

    First message

    Before we get into details, I wonder how you expect to use this class.

    If a view (or whatever going to handle it), going to receive have a runtime-generated class for example, how you gonna handle it?

    How you gonna know what properties this model has?

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

Sidebar

Related Questions

I am creating a login menu in C++ i wish to give the user
In MFC application,i wish it can give me a tag when i update a
In the following code, I wish to give an option to the user to
In my published app, I wish to give the user a button that will
I wish I could figure this out. I need to produce a table with
The best example I can give is located at: http://www.mathopenref.com/arclength.html In that Java applet,
I wish to have a hash containing references to sub-functions where I can call
I wish to give my users only vertical scroll and that too up to
I wish to provide a quick demo about the contents of my website and
Hi i wish to implement push notification in my own android application. how can

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.