CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Authorization/ReadOnlyPerson.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ReadOnlyPerson.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>no summary</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
13using System.Diagnostics;
14
16{
17#if TESTING
18 [DebuggerNonUserCode]
19#endif
20 [Serializable()]
21 public class ReadOnlyPerson : ReadOnlyBase<ReadOnlyPerson>
22 {
23 private ReadOnlyPerson()
24 {
25 LoadProperty(FirstNameProperty, "John");
26 LoadProperty(LastNameProperty, "Doe");
27 LoadProperty(MiddleNameProperty, "A");
28 LoadProperty(PlaceOfBirthProperty, "New York");
29 }
31 {
32 return new ReadOnlyPerson();
33 }
34 private static PropertyInfo<string> FirstNameProperty = RegisterProperty<string>(new PropertyInfo<string>("FirstName"));
35 public string FirstName
36 {
37 get
38 {
39 return GetProperty(FirstNameProperty, Csla.Security.NoAccessBehavior.ThrowException);
40 }
41 }
42
43
44 private static PropertyInfo<string> LastNameProperty = RegisterProperty<string>(new PropertyInfo<string>("LastName"));
45
46 public string LastName
47 {
48 get
49 {
50 return GetProperty(LastNameProperty, Csla.Security.NoAccessBehavior.ThrowException);
51 }
52 }
53
54 private static PropertyInfo<string> MiddleNameProperty = RegisterProperty<string>(new PropertyInfo<string>("MiddleName"));
55 public string MiddleName
56 {
57 get
58 {
59 return GetProperty(MiddleNameProperty, Csla.Security.NoAccessBehavior.ThrowException);
60 }
61 }
62
63
64 private static PropertyInfo<string> PlaceOfBirthProperty = RegisterProperty<string>(new PropertyInfo<string>("PlaceOfBirth"));
65
66 public string PlaceOfBirth
67 {
68 get
69 {
70 return GetProperty(PlaceOfBirthProperty, Csla.Security.NoAccessBehavior.ThrowException);
71 }
72 }
73
74 protected override void AddBusinessRules()
75 {
76 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsInRole(Rules.AuthorizationActions.ReadProperty, FirstNameProperty, new List<string> { "Admin" }));
77 BusinessRules.AddRule(new Csla.Rules.CommonRules.IsNotInRole(Rules.AuthorizationActions.ReadProperty, MiddleNameProperty, new List<string> { "Admin" }));
78 }
79 //protected override void AddInstanceAuthorizationRules()
80 //{
81 // base.AddInstanceAuthorizationRules();
82 // AuthorizationRules.InstanceAllowRead("LastName", "Admin");
83 // AuthorizationRules.InstanceDenyRead("PlaceOfBirth", "Admin");
84 //}
85
86 //protected override object GetIdValue()
87 //{
88 // return null;
89 //}
90 }
91}
Maintains metadata about a property.
This is a base class from which readonly business classes can be derived.
Definition: ReadOnlyBase.cs:55
virtual void LoadProperty(IPropertyInfo propertyInfo, object newValue)
Loads a property's managed field with the supplied value calling PropertyHasChanged if the value does...
object GetProperty(IPropertyInfo propertyInfo)
Gets a property's value as a specified type.
BusinessRules BusinessRules
Provides access to the broken rules functionality.
IsInRole authorization rule.
IsNotInRole authorization rule.
override void AddBusinessRules()
Override this method to add per-type authorization rules for your type's properties.
@ Serializable
Prevents updating or inserting until the transaction is complete.