public override string ToString() { #if NET20 var year = ObjectExtensionMethods.ToXmlString(_date).Substring(0, 4); #else var year = _date.ToXmlString().Substring(0, 4); #endif switch (_date.Month) { case 1: case 2: case 3: return(year + " Q1"); case 4: case 5: case 6: return(year + " Q2"); case 7: case 8: case 9: return(year + " Q3"); default: return(year + " Q4"); } }
public override string ToString() { #if NET20 return(ObjectExtensionMethods.ToXmlString(_date).Substring(0, 7)); #else return(_date.ToXmlString().Substring(0, 7)); #endif }
public static IXPathNavigable XmlSerialize(this object value) #endif { if (null == value) { throw new ArgumentNullException("value"); } var result = new XmlDocument(); var buffer = new StringBuilder(); var exception = value as Exception; #if NET20 if (ObjectExtensionMethods.IsNotNull(exception)) #else if (exception.IsNotNull()) #endif { using (var stream = new MemoryStream()) { new SoapFormatter().Serialize(stream, value); stream.Seek(0, SeekOrigin.Begin); using (var reader = new StreamReader(stream)) { buffer.Append(reader.ReadToEnd()); } } } else { using (TextWriter writer = new EncodedStringWriter(buffer, CultureInfo.InvariantCulture, Encoding.UTF8)) { XmlSerializerNamespaces namespaces; var obj = value as IXmlSerializerNamespaces; if (null == obj) { namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); } else { namespaces = obj.XmlNamespaceDeclarations; } new XmlSerializer(value.GetType()).Serialize(writer, value, namespaces); } } result.LoadXml(buffer.ToString()); return(result); }
public override int GetHashCode() { return(Properties .Select(property => property.GetValue(this, null)) #if NET20 .Where(value => ObjectExtensionMethods.IsNotNull(value)) #else .Where(value => value.IsNotNull()) #endif .Aggregate(0, (x, value) => x ^ value.GetHashCode())); }
public override string ToString() { var buffer = new StringBuilder(); foreach (var value in Properties .Select(property => property.GetValue(this, null)) #if NET20 .Where(value => ObjectExtensionMethods.IsNotNull(value))) #else .Where(value => value.IsNotNull())) #endif { if (0 != buffer.Length) { buffer.Append(Environment.NewLine); } buffer.Append(value); } return(buffer.ToString()); }
public static string ToXmlString(this object value) #endif { if (null == value) { return(null); } var s = value as string; #if NET20 if (ObjectExtensionMethods.IsNotNull(s)) #else if (s.IsNotNull()) #endif { return(s); } if (value is bool) { return(XmlConvert.ToString((bool)value)); } if (value is DateTime) { return(XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.Utc)); } #if !NET20 if (value is DateTimeOffset) { return(XmlConvert.ToString((DateTimeOffset)value)); } #endif if (value is decimal) { return(XmlConvert.ToString((decimal)value)); } if (value is double) { return(XmlConvert.ToString((double)value)); } if (value is float) { return(XmlConvert.ToString((float)value)); } if (value is TimeSpan) { return(XmlConvert.ToString((TimeSpan)value)); } if (value is IConvertible) { return((string)Convert.ChangeType(value, typeof(string), CultureInfo.InvariantCulture)); } return(value.ToString()); }