|
Here is the VB.NET version I had laying around (should be fairly simple to convert to C#):
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
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
|
|
|
|
|
One reason for that of course could be that the source of the other XML does not use C# serialization for creation.
|
|
|
|
|
Hi world
i have to draw 2D forms (ellipse, lines, arcs...)in WPF using code.
i don't know from where i should start xD ..........
do you have an idea O_o !!! if yes tell me pleaaaaze, cause i have to finish my application this month.
thanks.
|
|
|
|
|
|
thank you that's very interesting.
|
|
|
|
|
And if you run into snags, there's a WPF message board[^] here
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
Iam using C#. WinForms 2010. In C# coding time while I press Ctrl+F then I can able to see
Find Window.
Similarly I have DataGridView and its DataSource is MyTable1. When the user presses Ctrl+F then I would like to locate on Particular Row,Column in DGV's DataSource column.
Is it possible? Or any other way for search...
Thanks For The Ideas.
|
|
|
|
|
|
Thanks
|
|
|
|
|
I made a custom UserControl and in it i put a Listbox.
In Form1, in the properties of the UserControl I want to see the [Items] property of the Listbox that is inside UserControl.
How to do that?
thanks.
|
|
|
|
|
Create the property yourself, and delegate the get/set methods to the property on the listbox.
Regards,
Rob Philpott.
|
|
|
|
|
If I was knowing how to make it, i did not cry for help.
give me an example please.
|
|
|
|
|
Ok something like (in your user control):
public ListBox.Collection Items
{
get { return listbox1.Items; }
set { listbox1.Items = value; }
}
... (edit) although you probably don't want the setter thinking about it..
Regards,
Rob Philpott.
|
|
|
|
|
ListBox.Collection does not exist!
I found this but with a little problem:
public ListBox.ObjectCollection Items
{
get { return listBox1.Items; }
set { listBox1.Items = value; }
}
|
|
|
|
|
yeah, I edited the original - you can't set it, so just forget the second line and you should be there.
Regards,
Rob Philpott.
|
|
|
|
|
I figure it out and it works:
public ListBox.ObjectCollection Items
{
get { return listBox1.Items; }
}
But when i open Items property from the Property panel, a window appear (Object Collection Editor) and it let me add and remove items but with no capability of editing those items... how to solve that?
I observe that when i open Items property for the actual listBox1 another window appear (String Collection Editor).
How to add the (String...) instead of (Object...)?
The ListBox have only these classes available: ___(and no String Collection)
modified on Tuesday, June 21, 2011 8:59 AM
|
|
|
|
|
Set an Editor attribute
[Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
(lifted from here[^])
|
|
|
|
|
in Form1 I wrote this and is working all right:
(BUT...I want to be able to add items not only programmatic, but from properties panel too.)
private void Form1_Load(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(path + "\\Sessions.txt");
RichTextBox rtb = new RichTextBox();
rtb.Text = sr.ReadToEnd();
for (int i = 0; i < rtb.Lines.Length-1; i++)
{
session1.listBox1.Items.Add(rtb.Lines[i]);
}
sr.Close();
}
|
|
|
|
|
you don't need the richttextbox, you should be able to iterate through the lines of the StreamReader (ReadLine method)
V.
|
|
|
|
|
"you don't need the richtextbox""
And how do I take the lines from file (here:[for (int i = 0; i < rtb.Lines.Length-1; i++)]?
|
|
|
|
|
Just take a look at the documentation of StreamReader ; there should be a ReadLine() method.
Well, here's the link : StreamReader.ReadLine()
|
|
|
|
|
thx (with the while will do nice |)
But my first problem still is in debate
|
|
|
|
|
Sorry, I don't know how to customize the collection editor for your needs. This should be possible as there are some attributes that you can add to your USerControl that will let you customize their behavior.
Here's another link that could help you get the point
Hope this points you in the right direction.
|
|
|
|
|
Hi ,
I am using Visual Studio Professional edition.There is no Fxcop integration in that.Is there any third party tools/addons that can be used to run Fxcop ?
With regards
|
|
|
|
|
You could always try google: It lead me straight to MSDN: Visual Studio Integration of FxCop[^]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|