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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:17:21+00:00 2026-06-17T09:17:21+00:00

When .NET 4.5 was released i started using such great Attribute as CallerMemberName .

  • 0

When .NET 4.5 was released i started using such great Attribute as CallerMemberName. It’s easier to understand code, developers can write it faster also. It’s like a snippet, not only a feature for debug/test purposes.

So I have a question. Is it normal to create and use something like this?

public class PropertyStore
{
    Dictionary<string, object> data = new Dictionary<string,object>();
    ViewModelBase modelBase;

    internal PropertyStore(ViewModelBase _base)
    {
        modelBase = _base;
    }

    public void SetValue<T>(T value = default(T), [CallerMemberName] string prop = "")
    {
        T prev = GetValue<T>(prop);
        if ((prev == null && value == null) || (prev != null && prev.Equals(value))) return;
        data[prop] = value;
        modelBase.OnPropertyChanged(prop);
    }

    public T GetValue<T>([CallerMemberName] string prop = "")
    {
        if (!data.ContainsKey(prop))
            data[prop] = default(T);
        return (T)data[prop];
    }
}

Class-helper, that makes other class more readable, and also we have list of our properties without need to use Reflection.
The usage is:

public class SampleClass : ViewModelBase
{
    PropertyStore PropertyStore;

    public SampleClass ()
    {
        PropertyStore = new PropertyStore(this);
    }

    public string Key
    {
        get { return PropertyStore.GetValue<string>(); }
        set { PropertyStore.SetValue(value); }
    }
    public DateTime Date
    {
        get { return PropertyStore.GetValue<DateTime>(); }
        set { PropertyStore.SetValue(value); }
    }
    public bool IsSelected
    {
        get { return PropertyStore.GetValue<bool>(); }
        set { PropertyStore.SetValue(value); }
    }
}

The class ViewModelBase here simply implements INotifyPropertyChanged interface.

As I understand, this approach is something like Microsoft Dependency Properties, but I don’t need all power of DependencyObject class, and I don’t want inherit it.
With something like this I can use Binding, because it’s enough to implement INotifyPropertyChanged, also we have no fields (as for me, i try to use properties smarter, than using fields directly (however, there is no problem to use Dictionary directly ^_^))

Sorry for my bad English… Not main language and not much practice.

Another Sample (after moving Methods to base class)

public class SampleClass : ViewModelBase
{
    public string Key
    {
        get { return GetValue<string>(); }
        set { SetValue(value); }
    }
    public DateTime Date
    {
        get { return GetValue<DateTime>(); }
        set { SetValue(value); }
    }
    public bool IsSelected
    {
        get { return GetValue<bool>(); }
        set { SetValue(value); }
    }
}

No diff with Microsoft’s WPF Property System.

  • 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-17T09:17:21+00:00Added an answer on June 17, 2026 at 9:17 am

    Nice idea, property bag without reflection and it will even work with obfuscation.

    I don’t see major problems with it but you may consider the following:

    1. The prop parameter is optional so potentially a bug can be introduced by given a value in the call.
    2. Value types will get boxed.
    3. Access to the fields is relatively more expensive, can be a factor more expensive as you have much more code in a simple get (especially with boxing).
    4. Dictionary takes more space than the number of properties you keep in (especially with boxing).
    5. Each property also stores a string of the property name adding to the overhead.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I always designed/developed/released a software or web project myself/independent activity using java/vb.net and php
I want to create a .NET assembly that can be accessed from unmanaged code
We are working on a .NET application and recently started using Git for version
We are currently using Quartz.NET 1.1. (I see that Quartz.NET 2.0 was released a
When will ASP.NET 4.0 be released?
I have recently seen new Iron languages get released into the .Net realm. So
I'm building a product that will ship after .Net 4.0 is released. Is MEF
Does anyone know if this has been released yet? I went to asp.net and
<project name=aa default=createqueue xmlns=http://nant.sf.net/release/0.85/nant.xsd> <target name=createqueue> <echo message=started /> <script language=C# > <references> <lib>
Can I use EF4.0 relased with .NET framework 4.0 with VS2008?

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.