public ActionResult Index()
    {
        TestViewModel vm = new TestViewModel {
            ChangeMe = "a1", DontChangeMe = "b1"
        };

        ProtectedPropertyAttribute.LockObject(vm);
        return(View(vm));
    }
Ejemplo n.º 2
0
    public static void LockProperty(object obj, PropertyInfo property)
    {
        ProtectedPropertyAttribute protectedAttribute =
            (ProtectedPropertyAttribute)
            property.GetCustomAttributes(typeof(ProtectedPropertyAttribute), false).FirstOrDefault();

        if (protectedAttribute == null)
        {
            return;
        }
        if (protectedAttribute.Identifier == null)
        {
            protectedAttribute.Identifier = property.Name;
        }
        LinkedList <object> list;

        if (!savedValues.TryGetValue(protectedAttribute.Identifier, out list))
        {
            list = new LinkedList <object>();
            savedValues.Add(protectedAttribute.Identifier, list);
        }
        list.AddLast(property.GetValue(obj, null));
    }