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.
ObjectFactory.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ObjectFactory.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Base class to be used when creating a data portal</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
12using Csla.Core;
13using Csla.Properties;
14using Csla.Reflection;
15
16namespace Csla.Server
17{
22 public abstract class ObjectFactory
23 {
30 protected void SetIsReadOnly(object obj, bool value)
31 {
32 var list = obj as Csla.Core.IReadOnlyBindingList;
33 if (list != null)
34 list.IsReadOnly = value;
35 }
36
44 protected void CheckRules(object obj)
45 {
46 var target = obj as IDataPortalTarget;
47 if (target != null)
48 target.CheckRules();
49 else
50 MethodCaller.CallMethodIfImplemented(obj, "CheckRules", null);
51 }
52
60 protected void MarkOld(object obj)
61 {
62 var target = obj as IDataPortalTarget;
63 if (target != null)
64 target.MarkOld();
65 else
66 MethodCaller.CallMethodIfImplemented(obj, "MarkOld", null);
67 }
68
76 protected void MarkNew(object obj)
77 {
78 var target = obj as IDataPortalTarget;
79 if (target != null)
80 target.MarkNew();
81 else
82 MethodCaller.CallMethodIfImplemented(obj, "MarkNew", null);
83 }
84
92 protected void MarkAsChild(object obj)
93 {
94 var target = obj as IDataPortalTarget;
95 if (target != null)
96 target.MarkAsChild();
97 else
98 MethodCaller.CallMethodIfImplemented(obj, "MarkAsChild", null);
99 }
100
120 protected void LoadProperty<P>(object obj, PropertyInfo<P> propertyInfo, P newValue)
121 {
122 var target = obj as Core.IManageProperties;
123 if (target != null)
124 target.LoadProperty<P>(propertyInfo, newValue);
125 else
126 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
127 }
128
141 protected void LoadProperty(object obj, IPropertyInfo propertyInfo, object newValue)
142 {
143 var target = obj as Core.IManageProperties;
144 if (target != null)
145 target.LoadProperty(propertyInfo, newValue);
146 else
147 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
148 }
149
162 protected P ReadProperty<P>(object obj, PropertyInfo<P> propertyInfo)
163 {
164 var target = obj as Core.IManageProperties;
165 if (target != null)
166 return target.ReadProperty(propertyInfo);
167 else
168 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
169 }
170
180 protected object ReadProperty(object obj, IPropertyInfo propertyInfo)
181 {
182 var target = obj as IManageProperties;
183 if (target != null)
184 return target.ReadProperty(propertyInfo);
185 else
186 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
187 }
188
204 protected IDisposable BypassPropertyChecks(Csla.Core.BusinessBase businessObject)
205 {
206 return businessObject.BypassPropertyChecks;
207 }
208
215 protected bool FieldExists(object obj, Csla.Core.IPropertyInfo property)
216 {
217 var target = obj as Core.IManageProperties;
218 if (target != null)
219 return target.FieldExists(property);
220 else
221 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
222 }
223
230 protected Csla.Core.MobileList<C> GetDeletedList<C>(object obj)
231 {
232 var target = obj as Core.IEditableCollection;
233 if (target != null)
234 return (Csla.Core.MobileList<C>)target.GetDeletedList();
235 else
236 throw new ArgumentException(Resources.IEditableCollectionRequiredException);
237 }
238 }
239}
This is the non-generic base class from which most business objects will be derived.
Implements a list that is serializable using the SerializationFormatterFactory.GetFormatter().
Definition: MobileList.cs:29
A strongly-typed resource class, for looking up localized strings, etc.
static string IManagePropertiesRequiredException
Looks up a localized string similar to Target object must implement IManageProperties.
static string IEditableCollectionRequiredException
Looks up a localized string similar to Target object must implement IEditableCollection.
Maintains metadata about a property.
Base class to be used when creating a data portal factory object.
void MarkOld(object obj)
Calls the MarkOld method on the specified object, if possible.
void MarkNew(object obj)
Calls the MarkNew method on the specified object, if possible.
void SetIsReadOnly(object obj, bool value)
Sets the IsReadOnly property on the specified object, if possible.
void LoadProperty(object obj, IPropertyInfo propertyInfo, object newValue)
Loads a property's managed field with the supplied value.
Csla.Core.MobileList< C > GetDeletedList< C >(object obj)
Gets the list of deleted items from an editable collection.
void LoadProperty< P >(object obj, PropertyInfo< P > propertyInfo, P newValue)
Loads a property's managed field with the supplied value.
bool FieldExists(object obj, Csla.Core.IPropertyInfo property)
Gets a value indicating whether a managed field exists for the specified property.
P ReadProperty< P >(object obj, PropertyInfo< P > propertyInfo)
Reads a property's managed field value.
void MarkAsChild(object obj)
Calls the MarkAsChild method on the specified object, if possible.
void CheckRules(object obj)
Calls the ValidationRules.CheckRules() method on the specified object, if possible.
IDisposable BypassPropertyChecks(Csla.Core.BusinessBase businessObject)
By wrapping this property inside Using block you can set property values on businessObject business o...
object ReadProperty(object obj, IPropertyInfo propertyInfo)
Reads a property's managed field value.
Maintains metadata about a property.