@@ -24,20 +24,27 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424
2525namespace Experica
2626{
27+ /// <summary>
28+ /// The purpose of this class is to have a multion capable of formatting (serializing/deserializing) in
29+ /// any format class that is derived from IFormat. This class will have a list of singleton objects
30+ /// corresponding to each format possible. To add a type of format, simply create the class, have it
31+ /// end in Format, and add the type to the enum DataType in Extension.cs
32+ /// </summary>
2733 public sealed class Formatter
2834 {
29- // This can be static in a console/desktop application, just be wary of potential memory issues
3035 private Dictionary < DataFormat , IFormat > _formats = new Dictionary < DataFormat , IFormat > ( ) ;
3136
37+ // With lazy instantiation, it is only created once referenced.
3238 private static readonly Lazy < Formatter > lazy = new Lazy < Formatter > ( ( ) => new Formatter ( ) ) ;
3339
40+ // The singleton Instance of the Formatter, its thread safe.
3441 public static Formatter Instance { get { return lazy . Value ; } }
3542
3643 /// <summary>
37- /// Get the current active policy of the given type.
44+ /// Gets the active singleton object for the corresponding data format
3845 /// </summary>
39- /// <param name="type">The type of policy to retrieve.</param>
40- /// <returns>The current active policy of the given type</returns>
46+ /// <param name="type">The type of DataFormat to retrieve.</param>
47+ /// <returns>The current active DataFormat of the given type</returns>
4148 private IFormat GetActiveFormat ( DataFormat format )
4249 {
4350 if ( ! _formats . ContainsKey ( format ) )
@@ -51,12 +58,26 @@ private IFormat GetActiveFormat(DataFormat format)
5158 return _formats [ format ] ;
5259 }
5360
61+ /// <summary>
62+ /// Serializes the object using a specific type of DataFormat
63+ /// </summary>
64+ /// <typeparam name="T">type of the object to serialize.</typeparam>
65+ /// <param name="obj">Object to serialize.</param>
66+ /// <param name="format">The format to serialize the Object to.</param>
67+ /// <returns></returns>
5468 public string SerialzeDataToFormat < T > ( T obj , DataFormat format )
5569 {
5670 IFormat formatToUse = GetActiveFormat ( format ) ;
5771 return formatToUse . Serialize ( obj ) ;
5872 }
5973
74+ /// <summary>
75+ /// Deserializes an object
76+ /// </summary>
77+ /// <typeparam name="T">Type to deserialize to</typeparam>
78+ /// <param name="data">The data in the specific format to deserialize</param>
79+ /// <param name="format">The format the the string is in to deserialize.</param>
80+ /// <returns></returns>
6081 public T DeserializeUsingFormat < T > ( string data , DataFormat format )
6182 {
6283 IFormat formatToUse = GetActiveFormat ( format ) ;
0 commit comments