Archives
-
XmlSerializer - some (enum) field not getting serialized...?
Here's the scenario. I'm serializing a particular object, which contains other objects as properties. I have this particular enum type that won't get included in the serialized XML.
For illustration - I'll simplify the class (which is a property of the main class being serialized); it looks as follows:
public class Contact
{
public ContactRoleType ContactRole;
public string ContactID;
// ....and some more fields...
}
The ContactRoleType is a normal enum. All fields are serialized, except the enum field ContactRole. Strange thing is, when I rename the member field ContactRole, it does get serialized.
I have actually used Chris Sells' excellent tool XmlSerializerPreCompiler , and all the types can be serialized without any problem.
All comments and ideas are welcomed!
Thanks! -
Enum values as bit flags - using FlagsAttribute
The other day, I was using the RegexOptions enum when creating a Regular Expression, and I thought it would be useful to dedicate a blog entry to using enumeration values as flags.
The following is a poor example, but it should be illustrative enough.
Imagine we have a Client class, and one of the Client properties is ClientState. The ClientState enum can be defined as follows: -
WebRequest and SSL (The underlying connection was closed. Could not establish trust relationship with remote server.)
internal class AcceptAllCertificatePolicy : ICertificatePolicy
{
public AcceptAllCertificatePolicy()
{
} -
Random records from table
Hi all,
Great to be part of this blogging community. I will try to submit several posts each week and will make sure they contain snippets of code here and there.
Now, what would you do to select a random set of several records from a SQL Server database table?
A couple of months ago I came across the following simple, but yet very effective solution to do just that. For instance to get 10 random quotes from a Quotes table:
SELECT TOP 10 * FROM Quotes ORDER BY NEWID()
Personally I think it's pure gold.