public GenericWrapper(object wrapped) { if (wrapped == null) { throw new ArgumentNullException("wrapped"); } m_wrapped = wrapped; m_type = m_wrapped.GetType(); m_formats = WrappedValueFormats.Object; }
public GenericWrapper(object wrapped, Type type) { if (wrapped == null) { throw new ArgumentNullException("wrapped"); } if (type == null) { throw new ArgumentNullException("type"); } m_wrapped = wrapped; m_type = type; m_formats = WrappedValueFormats.Object; }
/// <summary> /// Update the object and string values from the XML value. The caller needs to pass in a delegate to /// a method that can perform the conversion from XML. /// </summary> public void UpdateFromXml(XmlToObject xmlToObject) { if ((AvailableFormats & WrappedValueFormats.Xml) != WrappedValueFormats.Xml) { throw new InvalidOperationException("Unable to update the GenericWrapper object and string values," + " because it does not have the XML value."); } if (m_wrapped == null) { throw new InvalidOperationException("Unable to update the GenericWrapper object and string values," + " because it does not have an existing object value (needed to get the type)."); } // Reset existing object and string values. m_wrapped = null; m_string = null; m_formats = WrappedValueFormats.Xml; if (xmlToObject != null) { try { m_wrapped = xmlToObject(m_type, m_xml); m_formats |= WrappedValueFormats.Object; } catch (System.Exception) { } } if (m_wrapped != null) { try { m_string = m_wrapped.ToString(); m_formats |= WrappedValueFormats.String; } catch (System.Exception) { } } }
public GenericWrapper(object wrapped, string xmlValue, Type type) { if (type == null) { throw new ArgumentNullException("type"); } m_wrapped = wrapped; m_xml = xmlValue; m_type = type; m_formats = WrappedValueFormats.None; if (wrapped != null) { m_formats |= WrappedValueFormats.Object; } if (m_xml != null) { m_formats |= WrappedValueFormats.Xml; } }
public GenericWrapper(object wrapped, string xmlValue, string stringValue, Type type) { if (type == null) { throw new ArgumentNullException("type"); } m_wrapped = wrapped; m_xml = xmlValue; m_string = stringValue; m_type = type; m_formats = WrappedValueFormats.String; // String format is "available", even if the string value is null. if (wrapped != null) { m_formats |= WrappedValueFormats.Object; } if (m_xml != null) { m_formats |= WrappedValueFormats.Xml; } }
/// <summary> /// Update the XML and string values from the object value. The caller needs to pass in a delegate to /// a method that can perform the conversion to XML. /// </summary> public void UpdateFromObject(ObjectToXml objectToXml) { if ((AvailableFormats & WrappedValueFormats.Object) != WrappedValueFormats.Object) { throw new InvalidOperationException("Unable to update the GenericWrapper XML and string values," + " because it does not have the actual object value."); } // Clear existing XML and string values. m_xml = null; m_string = null; m_formats = WrappedValueFormats.Object; // Try to read them from the object. if (objectToXml != null) { try { m_xml = objectToXml(m_wrapped); m_formats |= WrappedValueFormats.Xml; } catch (System.Exception) { } } try { m_string = m_wrapped.ToString(); m_formats |= WrappedValueFormats.String; } catch (System.Exception) { } }