Click here to Skip to main content
15,917,953 members
Home / Discussions / C#
   

C#

 
AnswerRe: Serialize Class To Xml & Store In Sql Pin
Not Active21-Jun-11 16:30
mentorNot Active21-Jun-11 16:30 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Kevin Marois21-Jun-11 17:41
professionalKevin Marois21-Jun-11 17:41 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Mycroft Holmes21-Jun-11 18:54
professionalMycroft Holmes21-Jun-11 18:54 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Kevin Marois22-Jun-11 3:51
professionalKevin Marois22-Jun-11 3:51 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
BobJanova22-Jun-11 4:15
BobJanova22-Jun-11 4:15 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Kevin Marois22-Jun-11 5:10
professionalKevin Marois22-Jun-11 5:10 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
Mark Salsbery22-Jun-11 8:26
Mark Salsbery22-Jun-11 8:26 
GeneralRe: Serialize Class To Xml & Store In Sql Pin
AspDotNetDev22-Jun-11 8:44
protectorAspDotNetDev22-Jun-11 8:44 
Here is the VB.NET version I had laying around (should be fairly simple to convert to C#):
VB.NET
''' <summary>
''' Converts an item to an XML string.
''' </summary>
''' <typeparam name="T">The type of object to convert.</typeparam>
''' <param name="item">The item to convert.</param>
''' <returns>The string containing the XML representation of the object.</returns>
Public Shared Function ToXml(Of T)(ByVal item As T) As String
	If item Is Nothing Then
		Return String.Empty
	End If
	Dim serializer As New XmlSerializer(GetType(T), String.Empty)
	Dim stream As New MemoryStream
	Dim settings As New XmlWriterSettings
	settings = New XmlWriterSettings
	settings.OmitXmlDeclaration = True
	settings.Indent = True
	Dim writer As XmlWriter = XmlWriter.Create(stream, settings)
	Dim ns As New XmlSerializerNamespaces
	ns.Add(String.Empty, String.Empty)
	serializer.Serialize(writer, item, ns)
	stream.Position = 0
	Dim xml As String = New StreamReader(stream).ReadToEnd
	writer.Close()
	stream.Close()
	Return xml
End Function

''' <summary>
''' Converts an XML string to an object.
''' </summary>
''' <typeparam name="T">The type of object to get.</typeparam>
''' <param name="xml">The string containing the XML representation of the object.</param>
''' <returns>The object represented by the XML string.</returns>
Public Shared Function FromXml(Of T)(ByVal xml As String) As T
	If String.IsNullOrEmpty(xml) Then
		Return CType(Nothing, T)
	End If
	Dim serializer As New XmlSerializer(GetType(T))
	Dim reader As New StringReader(xml)
	Dim xmlReader As New XmlTextReader(reader)
	Dim item As T = DirectCast(serializer.Deserialize(xmlReader), T)
	reader.Close()
	Return item
End Function


AnswerRe: Serialize Class To Xml & Store In Sql Pin
jschell22-Jun-11 9:21
jschell22-Jun-11 9:21 
Suggestiondraw 2D in WPF using code Pin
moums21-Jun-11 10:01
moums21-Jun-11 10:01 
GeneralRe: draw 2D in WPF using code Pin
Shahriar Iqbal Chowdhury/Galib21-Jun-11 10:27
professionalShahriar Iqbal Chowdhury/Galib21-Jun-11 10:27 
GeneralRe: draw 2D in WPF using code Pin
moums21-Jun-11 10:36
moums21-Jun-11 10:36 
GeneralRe: draw 2D in WPF using code Pin
Mark Salsbery21-Jun-11 10:36
Mark Salsbery21-Jun-11 10:36 
QuestionHow to Implement Search - System to DataGridView() ? Pin
Paramu197321-Jun-11 2:18
Paramu197321-Jun-11 2:18 
AnswerRe: How to Implement Search - System to DataGridView() ? Pin
Shahriar Iqbal Chowdhury/Galib21-Jun-11 10:33
professionalShahriar Iqbal Chowdhury/Galib21-Jun-11 10:33 
GeneralRe: How to Implement Search - System to DataGridView() ? Pin
Paramu197322-Jun-11 3:19
Paramu197322-Jun-11 3:19 
QuestionHow to see the [Items] property of the Listbox that is inside UserControl Pin
_Q12_21-Jun-11 2:00
_Q12_21-Jun-11 2:00 
AnswerRe: How to see the [Items] property of the Listbox that is inside UserControl Pin
Rob Philpott21-Jun-11 2:19
Rob Philpott21-Jun-11 2:19 
GeneralRe: How to see the [Items] property of the Listbox that is inside UserControl Pin
_Q12_21-Jun-11 2:22
_Q12_21-Jun-11 2:22 
GeneralRe: How to see the [Items] property of the Listbox that is inside UserControl Pin
Rob Philpott21-Jun-11 2:27
Rob Philpott21-Jun-11 2:27 
GeneralRe: How to see the [Items] property of the Listbox that is inside UserControl Pin
_Q12_21-Jun-11 2:34
_Q12_21-Jun-11 2:34 
GeneralRe: How to see the [Items] property of the Listbox that is inside UserControl Pin
Rob Philpott21-Jun-11 2:42
Rob Philpott21-Jun-11 2:42 
GeneralRe: How to see the [Items] property of the Listbox that is inside UserControl [modified] Pin
_Q12_21-Jun-11 2:53
_Q12_21-Jun-11 2:53 
GeneralRe: How to see the [Items] property of the Listbox that is inside UserControl Pin
BobJanova21-Jun-11 23:44
BobJanova21-Jun-11 23:44 
GeneralRe: How to see the [Items] property of the Listbox that is inside UserControl Pin
_Q12_21-Jun-11 3:06
_Q12_21-Jun-11 3:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.