|
I sit corrected:
DataMemberAttribute Class[^]
.NET Framework
Supported in: 4, 3.5, 3.0
So, no, not .net 2.0 -- unless maybe you write your own, like you can with ExtensionAttribute...
And my code as it stands uses Extension Methods and HashSet, so I would need to remove those.
modified on Sunday, September 26, 2010 12:54 AM
|
|
|
|
|
The stuff that everybody else said is confusing, so I thought I'd make it simple if anybody else is curious.
The properties A, R, G, and B on the Color struct only have getters (i.e., they don't have setters). No setters, the serializer can't set them. And the underlying property that they are based upon, Value, is private (not to mention it only has a getter), which serialization skips.
The Size struct serializes/deserializes fine because the Width and Height properties are public and have setters.
Oh, and in case you are curious why the deserialization requires a public setter... it first creates an instance of the class by calling the default constructor, then it calls the setter on each public property. That, by the way, means that serialization doesn't work by default on classes without a default constructor (I've been annoyed by that a couple times).
I think you can inherit from (or as PIEBALD might say, implement) an interface or something that allows you to implement custom serialization, but I've never had to resort to that.
|
|
|
|
|
aspdotnetdev wrote: as PIEBALD might say, implement
Correct, you're learning, grasshopper.
Much of that is true, but the question remains of why MS chose to implement Color in such a way that it won't serialize/deserialize in some meaningful way.
As I demonstrated with my last experiment, the property that gets serialized/deserialized (colourstring) doesn't have to be public (because objects serialize/deserialize themselves). MS could implement Color with serialization as I did with my Colour class.
Edit:
Allow me to amend that. This being a (WCF) Web Service, the class that is generated for the proxy includes:
[System.Runtime.Serialization.DataMemberAttribute()]
public string colourstring
{
get
{
return this.colourstringField;
}
set
{
this.colourstringField = value;
}
}
So, although the property in the class I wrote is private, the property that gets deserialized is public.
Crap, that's no good... what genius came up with that idea?
|
|
|
|
|
Aah ha ha ha!
System.ConsoleColor is an enumeration, so it passes through just fine... if you like 16-color.
Or write your own enumeration with the colours you want... how many could there be?
|
|
|
|
|
Yes, that was my initial approach, just an enum for CP colors (mainly: Orange, DarkGreen, Platinum, Gold, Silver, Bronze), but then I wanted to get the actual color components so an app could somewhat mimic the site look, even when CP itself changes some of its style parameters.
As DateTimes did just fine, I got a big bad surprise by Color acting up. You know the rest.
|
|
|
|
|
I have now rewritten my Colour class (as a struct) and it seems to work properly.
Record.cs as it now stands:
namespace Junk.Types
{
[System.Runtime.Serialization.DataContractAttribute()]
public sealed partial class Record
{
[System.Runtime.Serialization.DataMemberAttribute()]
public System.Guid ID { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public string LastName { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public string FirstName { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public Junk.Types.Gender Gender { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public Junk.Types.Colour FavouriteColour { get ; set ; }
}
}
Colour.cs:
namespace Junk.Types
{
public partial struct Colour
{
public byte A ;
public byte R ;
public byte G ;
public byte B ;
}
}
ColourPlus.cs:
namespace Junk.Types
{
using PIEBALD.Lib.LibExt.ParseArgb ;
public partial struct Colour
{
public override string
ToString
(
)
{
return ( System.String.Format
(
"#{0:X2}{1:X2}{2:X2}{3:X2}"
,
this.A
,
this.R
,
this.G
,
this.B
) ) ;
}
public static Colour
Parse
(
string Argb
)
{
return ( Colour.FromArgb ( Argb.ParseArgb() ) ) ;
}
public int
ToArgb
(
)
{
return ( this.A << 24 | this.R << 16 | this.G << 8 | this.B ) ;
}
public static Colour
FromArgb
(
int Argb
)
{
Colour result = new Colour() ;
result.B = (byte) ( Argb & 0x0FF ) ;
Argb >>= 8 ;
result.G = (byte) ( Argb & 0x0FF ) ;
Argb >>= 8 ;
result.R = (byte) ( Argb & 0x0FF ) ;
Argb >>= 8 ;
result.A = (byte) ( Argb & 0x0FF ) ;
return ( result ) ;
}
public static implicit operator System.Drawing.Color
(
Colour Colour
)
{
return ( System.Drawing.Color.FromArgb ( Colour.ToArgb() ) ) ;
}
public static implicit operator Colour
(
System.Drawing.Color Color
)
{
return ( Colour.FromArgb ( Color.ToArgb() ) ) ;
}
}
}
(ParseArgb replaces ParseColor, it returns an int.)
I haven't inspected the SOAP messages (I don't know how), but I expect they contain the four byte values; something along the lines of:
<FavouriteColour><A>256</A><R>256</R><G>256</G><B>256</B></FavouriteColour>
|
|
|
|
|
I'll experiment with this later today.
BTW: are you with Procter&Gamble? your favorite color is "whiter than white" (that is, if your code recovers from overflow when parsing the example)
|
|
|
|
|
I prefer Belgian White.
|
|
|
|
|
beer, wine, or chocolate?
|
|
|
|
|
Only tried the beer so far.
|
|
|
|
|
|
sure.
I have been working on semantics of the service, almost done now.
I experimented with a client-side extra file, works OK with WSDL.
I tried svcutil, no luck yet. To be continued.
Today I'm busy otherwise. Tomorrow I'll do some compatibility tests (what happens when server spec evolves, client lags?). Then I'll decide what I'll put in the proposal.
Cheers.
|
|
|
|
|
I'm trying to write an addin that updates a build number in an rc file *before* the build happens. I have a version of this that works fine for VC++ 6, but when trying to make this work in VS 2008, I can't get the build to recalculate every time - it only does it every other time.
I'm reading in an RC file, modifing it, then writing it back out. This is occuring in the OnBuildProjConfigBegin event (I have also tried OnBuildBegin as well with the same results).
|
|
|
|
|
Jim Crafton wrote: I'm reading in an RC file, modifing it, then writing it back out.
I don't know much about this, but I thought I'd throw out an idea or two. Are you flusing/closing the file too? Maybe Visual Studio is performing a threaded build and sometimes one thread gets ahead of the other? Can you do something less complicated to show whether or not your code is getting run each time (e.g., write to a new text file)? Or perahps show a message box? If it is getting executed every time, perhaps the RC file is getting overwritten after you change it?
|
|
|
|
|
hey guys..i want to connect my program with access..To do that i created a database in Access 2007 and saved it as Access 2003 with mdb extension..and i moved it to my project's debug file and i tried to connect it with udl file under debug fiile also...mdb has a password...i dont make a password for the mdb the connection is successfull but when i make a password there it gives error like "the provider had an error while connecting " and something like that
so what is wrong here? and why i can connect to database when i dont have a password
|
|
|
|
|
That's a database question.
Did you specify that the password should be saved to the UDL file?
Did you look in the UDL file and confirm that it's there?
|
|
|
|
|
Dear Coders.
I have a form, with a text box to allow a user to type a question, and a scrollable edit box that instantly relays the question.
Then, I send the typed question to my object, and it produces a responce (a bit like the AI webbots on here)
I want a delay while waiting for the responce, so it is more realistic.
I am using Thread.Sleep(3000) to produce a 3 second pause.
Now, this works fine EXCEPT, while the program is pausing, the text that the user has entered does not appear in the chat box.
once the pause has finished, the text AND the responce end up in the chat box at the same time.
So, when a user types a question, I would like it to appear straight away in the chat box, and only the reponse should be delayed.
I have tried moving the sleep function into every different call I make to see if it that but it makes no difference.
I even tried to call invalidate() on my edit box to update the display BEFORE I call sleep(), but again, no help.
Can anyone shed some light on this please?
Thank you
Steve
|
|
|
|
|
You'll have to use a thread to do the waiting bit, because when your're using Thread.Sleep in an event handler
the GUI thread can't be used to do all the repainting stuff that is needed.
My advice is:
Start a thread that waits (WaitOne) on a WaitHandle (e.g. AutoResetEvent) to process a
Queue<string> obj (queue of strings). When a string is entered by the user it's put on the
queue and the WaitHandle is signaled. The thread will awaken take the first string on the queue
(after locking on it of course). After the thread released the lock on the queue it'll go to
sleep and after awaking from sleep write response into textbox (remember to use invoke when doing
stuff on the GUI from a thread different from the GUI thread). After writing to the textbox the
thread will do WaitOne.
Hope this helps!
|
|
|
|
|
ManfredRBihy wrote: Hope this helps! Smile
Nope, sorry, that went straight over my head.
I dont even know where to start with this, as I am not used to working with threads.
Is there not just a simple way for me to say Sleep() just before I call for the responce, so that the first string (from the user) goes straight to the chat box, then sleep is called, waits, then ouputs the responce?
If I try to do what you have told me I realy dont know where to start.
Thank you for your help though.
Steve
|
|
|
|
|
I'll try to explain it in more detail.
A forms application has a thread to handle all the events
that are happening when the user enters input or clicks
something with the mouse. When an event handler is attached
to a forms object and it does a Thread.Sleep(xxxx) events
can no longer be handled and the application seems to freeze
for time specified in the Thread.Sleep call.
One thing you might try if you're not yet comfortable with creating
your own Thread is using a timer on your form. When the text is entered
the timer is set and activated. In the event handler of the timer the text
will finally be written to the textbox. Since all this is happending on
the GUI thread you don't even have to worry about that invoke bit I mentioned
in my previous response.
Better?
|
|
|
|
|
ManfredRBihy wrote: Better? Wink
Yes, I am "slightly" more comfotable with timers, so I will give that ago for now.
I am awaighting my new book on c# from amazon so I can get into the learning process better, and hopefully reduce the need to ask so many questions on here.
thank you again
|
|
|
|
|
Aww it didnt work.
It paused but the same thing happned
Steve
|
|
|
|
|
Can you post some code?
That would really be helpful in helping you !
(Remember to use "code block" when posting the code bits.)
|
|
|
|
|
OK, here you go, but please bare in mind I am a learner.
Also, It sort of works now, but the text that is output last is added onto the new text, so I am going wrong somewhere.
This part is elisa (name of the AI reponder)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace AI
{
class elisa
{
private string input;
private string output;
private int NumberOfReplies = 0;
public string respond(string input)
{
output = ("");
this.input = input;
if (NumberOfReplies >= 1)
{
output = ("Please wait!");
}
else
output = ("Sorry am a bit buzy at the min. ");
NumberOfReplies += 1;
Thread.Sleep(4000);
return output;
}
}
}
And this is from my form, it has a text box to enter what you want to say, and an edit box that then shows that text, and shows the responce from elisa...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace AI
{
public partial class Form1 : Form
{
elisa _elisa = new elisa();
string userInput;
string elisaResponce;
string you = ("You: ");
string elisa = ("Elisa: ");
public Form1()
{
InitializeComponent();
status.Text = ("");
}
private void btnSend_Click(object sender, EventArgs e)
{
updateInput(textBoxInput.Text);
textBoxInput.Clear();
status.Text = ("Elisa is typing a message");
getResponceFromElisa();
}
private void updateInput(string input)
{
richTextBoxOutput.Text += you += input + ("\n");
}
private void getResponceFromElisa()
{
timer1.Start();
}
private void textBoxInput_TextChanged(object sender, EventArgs e)
{
if (textBoxInput.Text == (""))
{
status.Text = ("");
}
else
status.Text = ("You are typing a message...");
}
private void timer1_Tick(object sender, EventArgs e)
{
elisaResponce = _elisa.respond(userInput);
richTextBoxOutput.Text += elisa += elisaResponce;
timer1.Stop();
status.Text = ("");
}
}
}
Thank you for asking to have a look, I appreciate it
Steve
|
|
|
|
|
I'll have a look at your post when I'm home from work.
(And I'm getting ready to go just about now)
Bye for now
|
|
|
|
|