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.AspNetCore.Shared/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;
9using System.Linq;
10using System.Collections.Generic;
11using System.ComponentModel;
12using System.Text;
13using Csla.Rules;
14
15namespace Csla.AspNetCore
16{
20 public class PropertyInfo : INotifyPropertyChanged
21 {
22 private object Model { get; }
23 private string PropertyName { 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
61 public string ErrorText
62 {
63 get
64 {
65 var result = string.Empty;
66 if (Model is Core.BusinessBase obj)
67 result = obj.BrokenRulesCollection.ToString(",", RuleSeverity.Error, PropertyName);
68 return result;
69 }
70 }
71
77 public string WarningText
78 {
79 get
80 {
81 var result = string.Empty;
82 if (Model is Core.BusinessBase obj)
83 result = obj.BrokenRulesCollection.ToString(",", RuleSeverity.Warning, PropertyName);
84 return result;
85 }
86 }
87
93 public string InformationText
94 {
95 get
96 {
97 var result = string.Empty;
98 if (Model is Core.BusinessBase obj)
99 result = obj.BrokenRulesCollection.ToString(",", RuleSeverity.Information, PropertyName);
100 return result;
101 }
102 }
103
109 public bool CanRead
110 {
111 get
112 {
113 if (Model is Security.IAuthorizeReadWrite obj)
114 return obj.CanReadProperty(PropertyName);
115 else
116 return true;
117 }
118 }
119
125 public bool CanWrite
126 {
127 get
128 {
129 if (Model is Security.IAuthorizeReadWrite obj)
130 return obj.CanWriteProperty(PropertyName);
131 else
132 return true;
133 }
134 }
135
141 public bool IsBusy
142 {
143 get
144 {
145 if (Model is Core.BusinessBase obj)
146 return obj.IsPropertyBusy(PropertyName);
147 else
148 return false;
149 }
150 }
151
155 public event PropertyChangedEventHandler PropertyChanged;
156
157 private void OnPropertyChanged(string propertyName)
158 {
159 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
160 }
161 }
162}
string InformationText
Gets the validation information messages for a property on the Model
bool CanRead
Gets a value indicating whether the current user is authorized to read the property on the Model
string WarningText
Gets the validation warning messages for a property on the Model
string ErrorText
Gets the validation error messages for a property on the Model
bool CanWrite
Gets a value indicating whether the current user is authorized to change the property on the Model
PropertyInfo(object model, string propertyName)
Creates an instance of the type.
PropertyChangedEventHandler PropertyChanged
Event raised when a property changes.
void Refresh()
Indicate that all properties have changed to trigger a UI refresh of all values.
bool IsBusy
Gets a value indicating whether the property on the Model is busy
RuleSeverity
Values for validation rule severities.
Definition: RuleSeverity.cs:16