<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Comments on snippet: 'Global System Object extensions for easier conditionals (VB.net example)'</title>
    <description>Snipplr comments feed</description>
    <link>https://snipplr.com/</link>
    <lastBuildDate>Fri, 03 Apr 2026 18:33:28 +0000</lastBuildDate>
    <item>
      <title>rpresser said on 17/Nov/2011</title>
      <link>https://snipplr.com/view/59759/global-system-object-extensions-for-easier-conditionals-vbnet-example</link>
      <description>&lt;p&gt;This is wrong. Extension methods are possible and easy in VB.NET. Here is my favorite:&#13;
&#13;
    Imports System.Runtime.CompilerServices&#13;
    Imports System.Xml.Serialization&#13;
&#13;
    Module ToFromXml&#13;
&#13;
         _&#13;
        Public Function ToXml(Of T)(ByVal x As T) As String&#13;
            Dim ser As New XmlSerializer(GetType(T))&#13;
            Using sw As New IO.StringWriter&#13;
                Using xtw As New System.Xml.XmlTextWriter(sw)&#13;
                    xtw.Indentation = False&#13;
                    ser.Serialize(xtw, x)&#13;
                    Return sw.ToString()&#13;
                End Using&#13;
            End Using&#13;
        End Function&#13;
&#13;
         _&#13;
        Public Function ReadFromXml(Of T)(ByRef x As T, ByVal xml As String) As T&#13;
            Dim ser As New XmlSerializer(GetType(T))&#13;
            Using sr As New IO.StringReader(xml)&#13;
                x = CType(ser.Deserialize(sr), T)&#13;
                Return x&#13;
            End Using&#13;
        End Function&#13;
&#13;
    End Module&lt;/p&gt;</description>
      <pubDate>Thu, 17 Nov 2011 17:23:55 UTC</pubDate>
      <guid>https://snipplr.com/view/59759/global-system-object-extensions-for-easier-conditionals-vbnet-example</guid>
    </item>
    <item>
      <title>rpresser said on 17/Nov/2011</title>
      <link>https://snipplr.com/view/59759/global-system-object-extensions-for-easier-conditionals-vbnet-example</link>
      <description>&lt;p&gt;Trying again:&#13;
&#13;
&#13;
    Imports System.Runtime.CompilerServices&#13;
    Imports System.Xml.Serialization&#13;
&#13;
    Module ToFromXml&#13;
&#13;
        `` _&#13;
        Public Function ToXml(Of T)(ByVal x As T) As String&#13;
            Dim ser As New XmlSerializer(GetType(T))&#13;
            Using sw As New IO.StringWriter&#13;
                Using xtw As New System.Xml.XmlTextWriter(sw)&#13;
                    xtw.Indentation = False&#13;
                    ser.Serialize(xtw, x)&#13;
                    Return sw.ToString()&#13;
                End Using&#13;
            End Using&#13;
        End Function&#13;
&#13;
        `` _&#13;
        Public Function ReadFromXml(Of T)(ByRef x As T, ByVal xml As String) As T&#13;
            Dim ser As New XmlSerializer(GetType(T))&#13;
            Using sr As New IO.StringReader(xml)&#13;
                x = CType(ser.Deserialize(sr), T)&#13;
                Return x&#13;
            End Using&#13;
        End Function&#13;
&#13;
    End Module&#13;
&#13;
Usage:&#13;
&#13;
    Module test&#13;
          Sub test&#13;
               Dim x As New YourClass&#13;
              Dim xml As String = x.ToXML()&#13;
              Dim y as New YourClass&#13;
              y.ReadFromXml(xml)&#13;
         End Sub&#13;
    End Module&lt;/p&gt;</description>
      <pubDate>Thu, 17 Nov 2011 17:26:02 UTC</pubDate>
      <guid>https://snipplr.com/view/59759/global-system-object-extensions-for-easier-conditionals-vbnet-example</guid>
    </item>
    <item>
      <title>rpresser said on 17/Nov/2011</title>
      <link>https://snipplr.com/view/59759/global-system-object-extensions-for-easier-conditionals-vbnet-example</link>
      <description>&lt;p&gt;I don't know why the [Extension()] isn't showing. It is a code attribute applied to the Function on the line above.&lt;/p&gt;</description>
      <pubDate>Thu, 17 Nov 2011 17:26:44 UTC</pubDate>
      <guid>https://snipplr.com/view/59759/global-system-object-extensions-for-easier-conditionals-vbnet-example</guid>
    </item>
    <item>
      <title>charllykorpa8698 said on 23/Feb/2023</title>
      <link>https://snipplr.com/view/59759/global-system-object-extensions-for-easier-conditionals-vbnet-example</link>
      <description>&lt;p&gt;This is an interesting example of how to use global system object extensions to make conditionals easier to work with in VB.net. These extensions can provide an easier way to program, so it is beneficial to understand how to use them. For more information, take a look at the C# example provided, &lt;a href="https://realengagementrings.com"&gt;diamond rings&lt;/a&gt; which can offer additional insight into this concept.&lt;/p&gt;</description>
      <pubDate>Thu, 23 Feb 2023 06:55:49 UTC</pubDate>
      <guid>https://snipplr.com/view/59759/global-system-object-extensions-for-easier-conditionals-vbnet-example</guid>
    </item>
  </channel>
</rss>
