本文整理汇总了C#中EmptyValue类的典型用法代码示例。如果您正苦于以下问题:C# EmptyValue类的具体用法?C# EmptyValue怎么用?C# EmptyValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EmptyValue类属于命名空间,在下文中一共展示了EmptyValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SmartDate
/// <summary>
/// Creates a new SmartDate object.
/// </summary>
/// <param name="emptyIsMin">Indicates whether an empty date is the min or max date value.</param>
public SmartDate(bool emptyIsMin)
{
_emptyValue = GetEmptyValue(emptyIsMin);
_format = null;
_initialized = false;
// provide a dummy value to allow real initialization
_date = DateTime.MinValue;
SetEmptyDate(_emptyValue);
}
示例2: SmartDate
/// <summary>
/// 创建SmartDate的实例
/// </summary>
/// <param name="emptyIsMin">空日期是否转换成最小日期</param>
public SmartDate(bool emptyIsMin)
{
//将空日期的布尔标识转成枚举标识
_emptyValue = GetEmptyValue(emptyIsMin);
//设置格式字符串
_format = null;
//设置初始化标识
_initialized = false;
//将日期最小值赋给日期字段
_date = _minDate;
//设置空日期
SetEmptyDate(_emptyValue);
}
示例3: SetEmptyDate
/// <summary>
/// 为空日期赋值
/// </summary>
/// <param name="emptyValue">空日期的类型</param>
private void SetEmptyDate(EmptyValue emptyValue)
{
if (emptyValue == EmptyValue.MinDate)
{
this.Date = _minDate;
}
else
{
this.Date = DateTime.MaxValue;
}
}
示例4: StringToDate
/// <summary>
/// Converts a text date representation into a Date value.
/// </summary>
/// <remarks>
/// An empty string is assumed to represent an empty date. An empty date
/// is returned as the MinValue or MaxValue of the Date datatype depending
/// on the EmptyIsMin parameter.
/// </remarks>
/// <param name="value">The text representation of the date.</param>
/// <param name="emptyValue">Indicates whether an empty date is the min or max date value.</param>
/// <returns>A Date value.</returns>
public static DateTime StringToDate(string value, EmptyValue emptyValue)
{
DateTime result = DateTime.MinValue;
if (TryStringToDate(value, emptyValue, ref result))
return result;
else
throw new ArgumentException(Resources.StringToDateException);
}
示例5: Parse
/// <summary>
/// Converts a string value into a SmartDate.
/// </summary>
/// <param name="value">String containing the date value.</param>
/// <param name="emptyValue">Indicates whether an empty date is the min or max date value.</param>
/// <returns>A new SmartDate containing the date value.</returns>
public static SmartDate Parse(string value, EmptyValue emptyValue)
{
return new SmartDate(value, emptyValue);
}
示例6: DateToString
/// <summary>
/// 将DateTime类型日期转换为指定格式的字符串
/// </summary>
/// <param name="value">要转换的日期</param>
/// <param name="formatString">格式字符串</param>
/// <param name="emptyValue">空日期的取值类型</param>
public static string DateToString(DateTime value, string formatString, EmptyValue emptyValue)
{
//如果日期为最大日期或最小日期,则转换为空字符串
if (emptyValue == EmptyValue.MinDate)
{
if (value == _minDate)
{
return string.Empty;
}
}
else
{
if (value == DateTime.MaxValue)
{
return string.Empty;
}
}
//将日期以指定格式的字符串返回
return string.Format("{0:" + formatString + "}", value);
}
示例7: Parse
/// <summary>
/// 将字符串转换为SmartDate类型,可指定空日期的取值类型
/// </summary>
/// <param name="date">字符串形式的日期</param>
/// <param name="emptyDateType">空日期的取值类型</param>
public static SmartDate Parse(string date, EmptyValue emptyDateType)
{
return new SmartDate(date, emptyDateType);
}
示例8: StringToDate
/// <summary>
/// 将字符串转换为DateTime类型日期
/// </summary>
/// <param name="value">日期字符串</param>
/// <param name="emptyValue">空日期的取值类型</param>
public static DateTime StringToDate(string value, EmptyValue emptyValue)
{
//要返回的的日期
DateTime result = _minDate;
//如果string成功转换为DateTime,则返回
if (TryStringToDate(value, emptyValue, ref result))
{
return result;
}
else
{
//转换失败,抛出异常
throw new ArgumentException(SmartDateString.StringToDateException);
}
}
示例9: TryParse
/// <summary>
/// 判断字符串是否能转换为一个SmartDate日期,并返回转换成功后的日期
/// </summary>
/// <param name="value">要转换的日期字符串</param>
/// <param name="emptyValue">空日期的取值类型</param>
/// <param name="result">返回转换成功后的日期</param>
public static bool TryParse(string value, EmptyValue emptyValue, ref SmartDate result)
{
//定义用于存储日期字符串转换的DateTime日期
DateTime dateResult = _minDate;
//将日期字符串转换为DateTime日期
if (TryStringToDate(value, emptyValue, ref dateResult))
{
//如果转换成功,则返回该日期的SmartDate类型
result = new SmartDate(dateResult, emptyValue);
return true;
}
else
{
return false;
}
}
示例10: SetEmptyDate
private void SetEmptyDate(EmptyValue emptyValue)
{
if (emptyValue == SmartDate.EmptyValue.MinDate)
this.Date = DateTime.MinValue;
else
this.Date = DateTime.MaxValue;
}
示例11: TryStringToDate
/// <summary>
/// 判断字符串是否能转换为一个Datetime日期,并返回转换成功后的日期
/// </summary>
/// <param name="value">要转换的日期字符串</param>
/// <param name="emptyValue">空日期的取值类型</param>
/// <param name="result">返回转换成功后的日期</param>
private static bool TryStringToDate(string value, EmptyValue emptyValue, ref DateTime result)
{
//定义一个临时日期
DateTime temp;
#region 如果日期字符串为空,则转成最大或最小的日期
if (string.IsNullOrEmpty(value))
{
//如果空日期的取值类型为MinDate,则转成最小日期,否则最大日期
if (emptyValue == EmptyValue.MinDate)
{
result = _minDate;
}
else
{
result = DateTime.MaxValue;
}
//返回true
return true;
}
#endregion
#region 将日期字符串转换为DateTime
if (DateTime.TryParse(value, out temp))
{
//如果转换成功,则返回true
result = temp;
return true;
}
#endregion
#region 如果日期字符串是自定义的值,则进行转换
//将日期字符串转成大写
string date = value.Trim().ToLower();
//转换成今天的日期
if (date == SmartDateString.SmartDateT || date == SmartDateString.SmartDateToday || date == ".")
{
result = DateTime.Now;
return true;
}
//转换成昨天的日期
if (date == SmartDateString.SmartDateY || date == SmartDateString.SmartDateYesterday || date == "-")
{
result = DateTime.Now.AddDays(-1);
return true;
}
//转换成明天的日期
if (date == SmartDateString.SmartDateTom || date == SmartDateString.SmartDateTomorrow || date == "+")
{
result = DateTime.Now.AddDays(1);
return true;
}
#endregion
//转换失败,返回false
return false;
}
示例12: TryParse
/// <summary>
/// Converts a string value into a SmartDate.
/// </summary>
/// <param name="value">String containing the date value.</param>
/// <param name="emptyValue">Indicates whether an empty date is the min or max date value.</param>
/// <param name="result">The resulting SmartDate value if the parse was successful.</param>
/// <returns>A value indicating if the parse was successful.</returns>
public static bool TryParse(string value, EmptyValue emptyValue, ref SmartDate result)
{
System.DateTime dateResult = DateTime.MinValue;
if (TryStringToDate(value, emptyValue, ref dateResult))
{
result = new SmartDate(dateResult, emptyValue);
return true;
}
else
{
return false;
}
}
示例13: TryStringToDate
private static bool TryStringToDate(string value, EmptyValue emptyValue, ref DateTime result)
{
// call custom parser if set...
if (_customParser != null)
{
var tmpValue = _customParser.Invoke(value);
// i f custom parser returned a value then parsing succeeded
if (tmpValue.HasValue)
{
result = tmpValue.Value;
return true;
}
}
DateTime tmp;
if (String.IsNullOrEmpty(value))
{
result = emptyValue == EmptyValue.MinDate ? DateTime.MinValue : DateTime.MaxValue;
return true;
}
if (DateTime.TryParse(value, out tmp))
{
result = tmp;
return true;
}
string ldate = value.Trim().ToLower();
if (ldate == Resources.SmartDateT ||
ldate == Resources.SmartDateToday ||
ldate == ".")
{
result = DateTime.Now;
return true;
}
if (ldate == Resources.SmartDateY ||
ldate == Resources.SmartDateYesterday ||
ldate == "-")
{
result = DateTime.Now.AddDays(-1);
return true;
}
if (ldate == Resources.SmartDateTom ||
ldate == Resources.SmartDateTomorrow ||
ldate == "+")
{
result = DateTime.Now.AddDays(1);
return true;
}
return false;
}
示例14:
void IMobileObject.SetState(SerializationInfo info)
{
_date = info.GetValue<DateTime>("SmartDate._date");
_defaultFormat = info.GetValue<string>("SmartDate._defaultFormat");
_emptyValue = (EmptyValue)System.Enum.Parse(typeof(EmptyValue), info.GetValue<string>("SmartDate._emptyValue"), true);
_format = info.GetValue<string>("SmartDate._format");
_initialized = info.GetValue<bool>("SmartDate._initialized");
}
示例15: DateToString
/// <summary>
/// Converts a date value into a text representation.
/// </summary>
/// <remarks>
/// Whether the date value is considered empty is determined by
/// the EmptyIsMin parameter value. If the date is empty, this
/// method returns an empty string. Otherwise it returns the date
/// value formatted based on the FormatString parameter.
/// </remarks>
/// <param name="value">The date value to convert.</param>
/// <param name="formatString">The format string used to format the date into text.</param>
/// <param name="emptyValue">Indicates whether an empty date is the min or max date value.</param>
/// <returns>Text representation of the date value.</returns>
public static string DateToString(
DateTime value, string formatString, EmptyValue emptyValue)
{
if (emptyValue == EmptyValue.MinDate)
{
if (value == DateTime.MinValue)
return string.Empty;
}
else
{
if (value == DateTime.MaxValue)
return string.Empty;
}
return string.Format("{0:" + formatString + "}", value);
}