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.
CslaReaderWriterFactory.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Runtime.Serialization;
4
6{
11 public static class CslaReaderWriterFactory
12 {
13 private static Type _readerType;
14 private static Type _writerType;
15
21 public static DataContractSerializer GetDataContractSerializer()
22 {
23 return new DataContractSerializer(
24 typeof(List<SerializationInfo>),
25 new Type[] { typeof(List<int>), typeof(byte[]), typeof(DateTimeOffset), typeof(char[]) });
26 }
27
32 public static void SetCslaWriterType(Type writerType)
33 {
34 _writerType = writerType;
35 }
36
41 public static void SetCslaReaderType(Type readerType)
42 {
43 _readerType = readerType;
44 }
45
50 public static ICslaWriter GetCslaWriter()
51 {
52 if (_writerType == null)
53 {
54 string writerType = Csla.Configuration.ConfigurationManager.AppSettings["CslaWriter"];
55 if (string.IsNullOrEmpty(writerType))
56 {
57 _writerType = typeof(CslaBinaryWriter);
58 }
59 else
60 {
61 _writerType = Type.GetType(writerType);
62 }
63 }
64 return (ICslaWriter)Reflection.MethodCaller.CreateInstance(_writerType);
65 }
66
71 public static ICslaReader GetCslaReader()
72 {
73 if (_readerType == null)
74 {
75 string readerType = Csla.Configuration.ConfigurationManager.AppSettings["CslaReader"];
76 if (string.IsNullOrEmpty(readerType))
77 {
78 _readerType = typeof(CslaBinaryReader);
79 }
80 else
81 {
82 _readerType = Type.GetType(readerType);
83 }
84 }
85 return (ICslaReader)Reflection.MethodCaller.CreateInstance(_readerType);
86 }
87 }
88}