using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Sdaleo.Systems { /// /// To Deal with Data Return Type validaton / retrieval /// public static class DataRet { /// /// Quickly retrieve a value for a given type /// Will use default value of the type if object is null /// /// /// /// public static T Retrieve(object oToRetrieve) { // Create a Default Type T T retVal = default(T); if (oToRetrieve != null) return ObjTool.ConvertStringToObj(oToRetrieve.ToString()); return retVal; } /// /// Quickly retrieve a value for a given type /// Will use default value passed in, if object is null /// /// /// /// public static T Retrieve(object oToRetrieve, T defaultValue) { // Create a Default Type T T retVal = default(T); if (ObjTool.IsNotNullAndNotEmpty(oToRetrieve)) return ObjTool.ConvertStringToObj(oToRetrieve.ToString()); else retVal = defaultValue; return retVal; } /// /// Quickly retrieve a string value /// Will use default value passed in, if string is null /// /// /// set to true to Trim() the string /// public static string Retrieve(object oToRetrieve, string defaultValue, bool bTrim) { string retVal = String.Empty; if (ObjTool.IsNotNullAndNotEmpty(oToRetrieve)) { retVal = oToRetrieve.ToString(); if (bTrim) retVal = retVal.Trim(); return retVal; } else { retVal = defaultValue; } return retVal; } /// /// Quickly retrieve a string value /// Will use "", if string is null. /// Will automatically call Trim(). /// /// public static string Retrieve(object oToRetrieve) { return Retrieve(oToRetrieve, String.Empty, true); } } }