|
Works for me....
[Serializable(), XmlRoot("Products")]
public class ProductList : System.Collections.Generic.List<Product>
{
public ProductList()
{
}
public void Load()
{
this.Add(new Product("111"));
this.Add(new Product("222"));
this.Add(new Product("333"));
}
}
public class Product
{
public string Name;
public string Test;
public Product()
{
}
public Product(string val)
{
Name = val;
Test = "Default " + val;
}
}
I do this in the test app:
ProductList p = new ProductList();
p.Load();
..and then serialize and get this....
<?xml version="1.0" encoding="utf-8"?>
<Products xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Product>
<Name>111</Name>
<Test>Default 111</Test>
</Product>
<Product>
<Name>222</Name>
<Test>Default 222</Test>
</Product>
<Product>
<Name>333</Name>
<Test>Default 333</Test>
</Product>
</Products>
Erik Westermann - wWorkflow.net - BizTalk Consulting Services
SOA * ESB * BPI * SaaS ... forget the alphabet soup - get the main course with our consulting services!
wWorkflow.net or +1 416-809-1453
|
|
|
|
|
IM working on a small C# program to backup My Access database automatically and woould like to add a few bells and whistles. Id like to be able to open the selected database from the program in exclusive and non-exclusive mode. Ive read the articl on SMSDN about Access automation as well as others but still have a problem.
using Access = Microsoft.Office.Interop.Access;
.......
private void btnOpenCurrDB_Click(object sender, EventArgs e)
{
Access.Application oAccess = new Access.ApplicationClass();
if (cbExclMode.Checked == true)
{
oAccess.OpenCurrentDatabase(@"C:\FTTH.mdb", true,null);
}
else
{
oAccess.OpenCurrentDatabase(@"C:\FTTH.mdb", false,null);
}
}
When I run the program, and click on the OpenCurrDB button I get 'InvalidCastException was unhandled'
Unable to cast COM object of type 'Microsoft.Office.Interop.Access.ApplicationClass' to interface type 'Microsoft.Office.Interop.Access._ApplicationClass'. The exception cmoes in either of the two oAccess.OpenCurrentDatabase lines depending on whether or not I have the exclusive checkbox checked.
Im a novice programmer, the rest of my program works fine, I just cant seem to get my hand on this part.
|
|
|
|
|
Problem solved. My machine is x64. I went into the project tab and changed the target CPU to x86. Works like a champ now.
|
|
|
|
|
how can i move the location of gorupbox in winform...
i want to change the locatoin of groupbox...
mean first time when form loads, its location is change and after some time its location should be changed.
--------------------------------------------------------------------------------
hghghgh
|
|
|
|
|
groupBox1.Location
Eslam Afifi
|
|
|
|
|
this.groupBox1.Location = new Point(100, 150);
maifs
|
|
|
|
|
how can i change i item's order in listbox in winForm( i have VS2005)..
i want that when i add some text in listbox then it should be appear from bottom to top
maifs
|
|
|
|
|
Implement IComparable on your object, and set Sorted = true .
|
|
|
|
|
Hi,
could anyone help me and tell me how i could change the following code so that the resulting xml would have nillable="true" on the field elements so that null values are represented with xsi:nil="true" in the xml?
SqlConnection MSSqlConn = new SqlConnection();
SqlCommand MSSCommand = new SqlCommand();
SqlDataAdapter MSdataAdapter = new SqlDataAdapter();
DataTable MyDT = new DataTable("TestQuery");
MSSqlConn.ConnectionString = str_con;
MSSCommand.Connection = MSSqlConn;
MSSCommand.CommandText = "select * from order_header where order_header.order_date = '09/13/2008'";
MSdataAdapter.SelectCommand = MSSCommand;
MSdataAdapter.Fill(MyDT);
MyDT.WriteXml("c:\\testquery.xml", XmlWriteMode.WriteSchema);
|
|
|
|
|
Hi there,
I'm new to C# and .NET and just wandering if there is anything clever that I could download (library, etc.) or maybe is part of the standard C# library that could help this:
In an import scenario (of tousands of articles) I have a column in the database that contains links. This is a very messy database (from a CMS) and some of the links are www.somelink.com (the good ones), etc. some are actualy with the html tag <a href="http://somelink.com">www.somelink.com</a>
I was wandering if there is a regular expression anywhere that would help me to filter out the Web link?
In the worst case scenario I'll have to write it myself - not a huge worry but would prefere to resuse of course.
Any help much appreciated.
Kind regards,
Pav
|
|
|
|
|
<a.+?href>]*>(?<text>.+?)
should about do it
I just wrote that for you, should get you three named match groups: "HREF", "Domain", "Text".
My test data was:
asd
asd
asd
asd
asd
all matched correctly.
--
Real programmers don't comment their code. It was hard to write, it should be hard to understand.
|
|
|
|
|
|
Try Expresso, its a very handy tool if your going to be doing regular expressions. It also contains a small library of reg. expressions for common problems.
Here[^]
Mike
|
|
|
|
|
I admit to ignorance and some laziness. There.
Never having written a Linq expression, (or in this case, is it a simple lambda expression?) I'm humbly asking for an example, as I'd like to start learning this feature.
Here's the code. It should be obvious what I'm trying to do.
bool bad=false;
foreach (char c in failure.ToCharArray())
{
if (!Char.IsDigit(c) && !Char.IsWhiteSpace(c))
{
bad = true;
break;
}
}
Thanks!
Marc
|
|
|
|
|
Well I don't know how to write the LINQ but I would have posted the question in the LINQ forum. What a Nub
led mike
|
|
|
|
|
led mike wrote: Well I don't know how to write the LINQ but I would have posted the question in the LINQ forum. What a Nub
We have a Linq forum? Oh! You're right. What a Nub I am!
Marc
|
|
|
|
|
You cant do that in Linq (because of the break statement) But you can do something with same effect.
<font color="Blue">string</font> failure <font color="DarkBlue">=</font> <font color="Maroon">"fob"</font><font color="DarkBlue">;</font>
<font color="Blue">bool</font> bad <font color="DarkBlue">=</font> <font color="DarkBlue">(</font><font color="Blue">from</font> c <font color="Blue">in</font> failure
<font color="Blue">where</font> <font color="DarkBlue">!</font><font color="DarkBlue">(</font><font color="Blue">char</font><font color="DarkBlue">.</font>IsWhiteSpace<font color="DarkBlue">(</font>c<font color="DarkBlue">)</font> <font color="DarkBlue">||</font> <font color="Blue">char</font><font color="DarkBlue">.</font>IsDigit<font color="DarkBlue">(</font>c<font color="DarkBlue">)</font><font color="DarkBlue">)</font>
<font color="Blue">select</font> c<font color="DarkBlue">)</font><font color="DarkBlue">.</font>Count<font color="DarkBlue">(</font><font color="DarkBlue">)</font> <font color="DarkBlue">></font> <font color="Red">0</font><font color="DarkBlue">;</font>
[update] fixed the query [update]
modified on Friday, September 12, 2008 11:44 AM
|
|
|
|
|
I was wondering about that, because of the break statement.
So. That's, umm, disappointing. I certainly don't want to process a million character string if the first char in the string is 'A'.
Marc
|
|
|
|
|
See my reply to myself
|
|
|
|
|
Actually, you could still use the Linq functions, but not a query pre se. The Contains Any function takes a predicate.
bad = failure.Any(c => !(char.IsWhiteSpace(c) || char.IsDigit(c)));
[update] fixed the missing ! part [update]
modified on Friday, September 12, 2008 11:41 AM
|
|
|
|
|
leppie wrote: Any function takes a predicate.
Coolness! That's what I was looking for.
Thank you!
Marc
|
|
|
|
|
leppie wrote: bad = failure.Any(c => char.IsWhiteSpace(c) || char.IsDigit(c));
Except, wouldn't the logic be:
bool bad = failure.Any(c => (!char.IsWhiteSpace(c) && !char.IsDigit(c)));
Marc
|
|
|
|
|
Yeah I forgot the ! part in front of the condition. It is fixed now.
|
|
|
|
|
From your original post I assume you want to do some sort of processing on the valid lines so i think you can use the Where method.
foreach (var line in allLines.Where(s => s.Any(c => !(char.IsWhiteSpace(c) || char.IsDigit(c)))))
{ }
You might find the Select method useful, something like
allLines.Where(s => s.Any(c => !(char.IsWhiteSpace(c) || char.IsDigit(c)))).Select(s => s.Length);
Eslam Afifi
modified on Friday, September 12, 2008 1:04 PM
|
|
|
|
|
Marc Clifton wrote: So. That's, umm, disappointing. I certainly don't want to process a million character string if the first char in the string is 'A'.
Technically it would be possible for the Count function to break early, if it could infer the resulting comparison, thus resulting in an Any function as per the other example.
[update] I did a test, it does not appear to do it for a string enumerable, I do however believe that SQL will be optimized if running the same query over a database source. [update]
|
|
|
|