CSLA.NET 5.4.2
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
Csla.Blazor/PropertyInfo.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="PropertyInfo.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Exposes metastate for a property</summary>
7//-----------------------------------------------------------------------
8using System.ComponentModel;
9using Csla.Rules;
10
11namespace Csla.Blazor
12{
16 public class PropertyInfo : IPropertyInfo, INotifyPropertyChanged
17 {
18 private const string TextSeparator = ", ";
19
23 protected object Model { get; }
24
30 public PropertyInfo(object model, string propertyName)
31 {
32 Model = model;
33 PropertyName = propertyName;
34 if (Model is INotifyPropertyChanged npc)
35 {
36 npc.PropertyChanged += Npc_PropertyChanged;
37 }
38 }
39
40 private void Npc_PropertyChanged(object sender, PropertyChangedEventArgs e)
41 {
42 if (e.PropertyName == "IsBusy")
43 OnPropertyChanged(nameof(IsBusy));
44 }
45
50 public void Refresh()
51 {
52 foreach (var item in this.GetType().GetProperties())
53 OnPropertyChanged(item.Name);
54 }
55
59 public object Value
60 {
61 get
62 {
63 var result = Csla.Utilities.CallByName(Model, PropertyName, CallType.Get);
64 if (result != null)
65 return result;
66 else
67 return default;
68 }
69 set => Csla.Utilities.CallByName(Model, PropertyName, CallType.Set, value);
70 }
71
75 public string FriendlyName
76 {
77 get
78 {
79 var pi = Core.FieldManager.PropertyInfoManager.GetRegisteredProperty(Model.GetType(), PropertyName);
80 return pi.FriendlyName;
81 }
82 }
83
87 public string PropertyName { get; }
88
94 public string ErrorText
95 {
96 get
97 {
98 var result = string.Empty;
99 if (Model is Core.BusinessBase obj)
100 result = obj.BrokenRulesCollection.ToString(TextSeparator, RuleSeverity.Error, PropertyName);
101 return result;
102 }
103 }
104
110 public string WarningText
111 {
112 get
113 {
114 var result = string.Empty;
115 if (Model is Core.BusinessBase obj)
116 result = obj.BrokenRulesCollection.ToString(TextSeparator, RuleSeverity.Warning, PropertyName);
117 return result;
118 }
119 }
120
126 public string InformationText
127 {
128 get
129 {
130 var result = string.Empty;
131 if (Model is Core.BusinessBase obj)
132 result = obj.BrokenRulesCollection.ToString(TextSeparator, RuleSeverity.Information, PropertyName);
133 return result;
134 }
135 }
136
142 public bool CanRead
143 {
144 get
145 {
146 if (Model is Security.IAuthorizeReadWrite obj)
147 return obj.CanReadProperty(PropertyName);
148 else
149 return true;
150 }
151 }
152
158 public bool CanWrite
159 {
160 get
161 {
162 if (Model is Security.IAuthorizeReadWrite obj)
163 return obj.CanWriteProperty(PropertyName);
164 else
165 return true;
166 }
167 }
168
174 public bool IsBusy
175 {
176 get
177 {
178 if (Model is Core.BusinessBase obj)
179 return obj.IsPropertyBusy(PropertyName);
180 else
181 return false;
182 }
183 }
184
188 public event PropertyChangedEventHandler PropertyChanged;
189
190 private void OnPropertyChanged(string propertyName)
191 {
192 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
193 }
194 }
195}
Exposes metastate for a property.
PropertyInfo(object model, string propertyName)
Creates an instance of the type.
string ErrorText
Gets the validation error messages for a property on the Model
bool IsBusy
Gets a value indicating whether the property on the Model is busy
bool CanRead
Gets a value indicating whether the current user is authorized to read the property on the Model
bool CanWrite
Gets a value indicating whether the current user is authorized to change the property on the Model
string InformationText
Gets the validation information messages for a property on the Model
string WarningText
Gets the validation warning messages for a property on the Model
string PropertyName
Gets the property name for the property.
PropertyChangedEventHandler PropertyChanged
Event raised when a property changes.
object Value
Gets or sets the value of the property
void Refresh()
Indicate that all properties have changed to trigger a UI refresh of all values.
string FriendlyName
Gets the friendly name for the property.
Exposes metastate for a property.
RuleSeverity
Values for validation rule severities.
Definition: RuleSeverity.cs:16
CallType
Valid options for calling a property or method via the Csla.Utilities.CallByName method.
Definition: Utilities.cs:318