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.
ObjectFactoryAttribute.cs
Go to the documentation of this file.
1//-----------------------------------------------------------------------
2// <copyright file="ObjectFactoryAttribute.cs" company="Marimer LLC">
3// Copyright (c) Marimer LLC. All rights reserved.
4// Website: https://cslanet.com
5// </copyright>
6// <summary>Specifies that the data portal</summary>
7//-----------------------------------------------------------------------
8using System;
9using System.Collections.Generic;
10using System.Linq;
11using System.Text;
12using Csla.Reflection;
13
14namespace Csla.Server
15{
21 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false)]
22 public class ObjectFactoryAttribute : Attribute
23 {
24 internal static ObjectFactoryAttribute GetObjectFactoryAttribute(Type objectType)
25 {
26 var result = objectType.GetCustomAttributes(typeof(ObjectFactoryAttribute), true);
27 if (result != null && result.Length > 0)
28 return result[0] as ObjectFactoryAttribute;
29 else
30 return null;
31 }
32
40 public string FactoryTypeName { get; private set; }
48 public string CreateMethodName { get; private set; }
56 public string FetchMethodName { get; private set; }
64 public string UpdateMethodName { get; private set; }
72 public string DeleteMethodName { get; private set; }
80 public string ExecuteMethodName { get; private set; }
81
92 public ObjectFactoryAttribute(string factoryType)
93 {
94 this.FactoryTypeName = factoryType;
95 this.CreateMethodName = "Create";
96 this.FetchMethodName = "Fetch";
97 this.UpdateMethodName = "Update";
98 this.DeleteMethodName = "Delete";
99 this.ExecuteMethodName = "Execute";
100 }
101
113 public ObjectFactoryAttribute(string factoryType, string createMethod, string fetchMethod)
114 {
115 this.FactoryTypeName = factoryType;
116 this.CreateMethodName = createMethod;
117 this.FetchMethodName = fetchMethod;
118 this.UpdateMethodName = "Update";
119 this.DeleteMethodName = "Delete";
120 this.ExecuteMethodName = "Execute";
121 }
122
132 public ObjectFactoryAttribute(string factoryType, string fetchMethod)
133 {
134 this.FactoryTypeName = factoryType;
135 this.FetchMethodName = fetchMethod;
136 this.CreateMethodName = "Create";
137 this.UpdateMethodName = "Update";
138 this.DeleteMethodName = "Delete";
139 this.ExecuteMethodName = "Execute";
140 }
141
142
159 string factoryType, string createMethod, string fetchMethod, string updateMethod, string deleteMethod)
160 {
161 this.FactoryTypeName = factoryType;
162 this.CreateMethodName = createMethod;
163 this.FetchMethodName = fetchMethod;
164 this.UpdateMethodName = updateMethod;
165 this.DeleteMethodName = deleteMethod;
166 this.ExecuteMethodName = "Execute";
167 }
168
191 string factoryType, string createMethod, string fetchMethod, string updateMethod, string deleteMethod, string executeMethod)
192 {
193 this.FactoryTypeName = factoryType;
194 this.CreateMethodName = createMethod;
195 this.FetchMethodName = fetchMethod;
196 this.UpdateMethodName = updateMethod;
197 this.DeleteMethodName = deleteMethod;
198 this.ExecuteMethodName = executeMethod;
199 }
200
207 public ObjectFactoryAttribute(Type factoryType)
208 : this(GetAssemblyQualifiedName(factoryType))
209 { }
210
220 public ObjectFactoryAttribute(Type factoryType, string fetchMethod)
221 : this(GetAssemblyQualifiedName(factoryType), fetchMethod)
222 { }
223
236 public ObjectFactoryAttribute(Type factoryType, string createMethod, string fetchMethod)
237 : this(GetAssemblyQualifiedName(factoryType), createMethod, fetchMethod)
238 { }
239
258 public ObjectFactoryAttribute(Type factoryType, string createMethod, string fetchMethod, string updateMethod, string deleteMethod)
259 : this(GetAssemblyQualifiedName(factoryType), createMethod, fetchMethod, updateMethod, deleteMethod)
260 { }
261
283 public ObjectFactoryAttribute(Type factoryType, string createMethod, string fetchMethod, string updateMethod, string deleteMethod, string executeMethod)
284 : this(GetAssemblyQualifiedName(factoryType), createMethod, fetchMethod, updateMethod, deleteMethod, executeMethod)
285 { }
286
292 private static string GetAssemblyQualifiedName(Type type)
293 {
294#if NETFX_CORE
295 if (type.IsGenericType())
296#else
297 if (type.IsGenericType)
298#endif
299 {
300 return type.AssemblyQualifiedName;
301 }
302 else
303 {
304 if (type.AssemblyQualifiedName == null) return string.Empty;
305
306 var elements = type.AssemblyQualifiedName.Split(',');
307 return string.Format("{0},{1}", elements[0], elements[1]);
308
309 }
310 }
311 }
312}
Specifies that the data portal should invoke a factory object rather than the business object.
ObjectFactoryAttribute(string factoryType, string fetchMethod)
Creates an instance of the attribute.
string FetchMethodName
Name of the method to call for a fetch operation.
string DeleteMethodName
Name of the method to call for a delete operation.
ObjectFactoryAttribute(Type factoryType)
Creates an instance of the attribute.
ObjectFactoryAttribute(Type factoryType, string createMethod, string fetchMethod, string updateMethod, string deleteMethod, string executeMethod)
Creates an instance of the attribute.
ObjectFactoryAttribute(Type factoryType, string createMethod, string fetchMethod)
Creates an instance of the attribute.
ObjectFactoryAttribute(string factoryType, string createMethod, string fetchMethod, string updateMethod, string deleteMethod)
Creates an instance of the attribute.
ObjectFactoryAttribute(string factoryType, string createMethod, string fetchMethod)
Creates an instance of the attribute.
ObjectFactoryAttribute(string factoryType)
Creates an instance of the attribute.
ObjectFactoryAttribute(Type factoryType, string fetchMethod)
Creates an instance of the attribute.
ObjectFactoryAttribute(Type factoryType, string createMethod, string fetchMethod, string updateMethod, string deleteMethod)
Creates an instance of the attribute.
string ExecuteMethodName
Name of the method to call for a Execute operation.
string UpdateMethodName
Name of the method to call for a update operation.
ObjectFactoryAttribute(string factoryType, string createMethod, string fetchMethod, string updateMethod, string deleteMethod, string executeMethod)
Creates an instance of the attribute.
string CreateMethodName
Name of the method to call for a create operation.
string FactoryTypeName
Assembly qualified type name of the factory object.