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.
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 Csla.Core;
10using Csla.Properties;
11using Csla.Reflection;
12
13namespace Csla.Server
14{
19 public abstract class ObjectFactory
20 {
25 public ObjectFactory(ApplicationContext applicationContext)
26 {
27 ApplicationContext = applicationContext;
28 }
29
33 protected ApplicationContext ApplicationContext { get; set; }
34
41 protected void SetIsReadOnly(object obj, bool value)
42 {
43 var list = obj as Csla.Core.IReadOnlyBindingList;
44 if (list != null)
45 list.IsReadOnly = value;
46 }
47
55 protected void CheckRules(object obj)
56 {
57 var target = obj as IDataPortalTarget;
58 if (target != null)
59 target.CheckRules();
60 else
61 MethodCaller.CallMethodIfImplemented(obj, "CheckRules", null);
62 }
63
71 protected void MarkOld(object obj)
72 {
73 var target = obj as IDataPortalTarget;
74 if (target != null)
75 target.MarkOld();
76 else
77 MethodCaller.CallMethodIfImplemented(obj, "MarkOld", null);
78 }
79
87 protected void MarkNew(object obj)
88 {
89 var target = obj as IDataPortalTarget;
90 if (target != null)
91 target.MarkNew();
92 else
93 MethodCaller.CallMethodIfImplemented(obj, "MarkNew", null);
94 }
95
103 protected void MarkAsChild(object obj)
104 {
105 var target = obj as IDataPortalTarget;
106 if (target != null)
107 target.MarkAsChild();
108 else
109 MethodCaller.CallMethodIfImplemented(obj, "MarkAsChild", null);
110 }
111
131 protected void LoadProperty<P>(object obj, PropertyInfo<P> propertyInfo, P newValue)
132 {
133 var target = obj as Core.IManageProperties;
134 if (target != null)
135 target.LoadProperty<P>(propertyInfo, newValue);
136 else
137 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
138 }
139
152 protected void LoadProperty(object obj, IPropertyInfo propertyInfo, object newValue)
153 {
154 var target = obj as Core.IManageProperties;
155 if (target != null)
156 target.LoadProperty(propertyInfo, newValue);
157 else
158 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
159 }
160
173 protected P ReadProperty<P>(object obj, PropertyInfo<P> propertyInfo)
174 {
175 var target = obj as Core.IManageProperties;
176 if (target != null)
177 return target.ReadProperty(propertyInfo);
178 else
179 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
180 }
181
191 protected object ReadProperty(object obj, IPropertyInfo propertyInfo)
192 {
193 var target = obj as IManageProperties;
194 if (target != null)
195 return target.ReadProperty(propertyInfo);
196 else
197 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
198 }
199
215 protected IDisposable BypassPropertyChecks(Csla.Core.BusinessBase businessObject)
216 {
217 return businessObject.BypassPropertyChecks;
218 }
219
226 protected bool FieldExists(object obj, Csla.Core.IPropertyInfo property)
227 {
228 var target = obj as Core.IManageProperties;
229 if (target != null)
230 return target.FieldExists(property);
231 else
232 throw new ArgumentException(Resources.IManagePropertiesRequiredException);
233 }
234
241 protected Csla.Core.MobileList<C> GetDeletedList<C>(object obj)
242 {
243 var target = obj as Core.IEditableCollection;
244 if (target != null)
245 return (Csla.Core.MobileList<C>)target.GetDeletedList();
246 else
247 throw new ArgumentException(Resources.IEditableCollectionRequiredException);
248 }
249 }
250}
Provides consistent context information between the client and server DataPortal objects.
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.
ObjectFactory(ApplicationContext applicationContext)
Creates an instance of the type.
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.