|
Hello everyone,
1.
Here is one of the field of my class. During deserialization, if the counter attribute is null, the deserialization could still be successful. Any ideas to make deserialization be smarter to treat counter as a non-null (must to have value) attribute?
2.
Any other ways to make deserialization be even smarter to treat counter as an integer other than string? (i.e. if in the XML file, counter attribute is assigned to non-numeric value, deserialization will fail.)
[XmlAttribute("counter")]
public string counter;
thanks in advance,
George
|
|
|
|
|
George_George wrote: Any other ways to make deserialization be even smarter to treat counter as an integer other than string?
Why not just make the counter field an integer in the first place?
|
|
|
|
|
Thanks Colin,
I have tried but still InvalidOperationException, the exception message is "There is an error in XML document (1, 14)."
Here is my code, any ideas?
using System;
using System.ComponentModel;
using System.IO;
using System.Xml.Serialization;
public class Bar
{
[XmlAttribute(DataType = "int", AttributeName = "counter")]
[System.ComponentModel.DefaultValueAttribute(0)]
public int counter;
}
static class Program
{
static void Main()
{
Bar a = Read(@"<Bar counter=10/>");
return;
}
static Bar Read(string xml)
{
Bar bar = (Bar)new XmlSerializer(typeof(Bar)).Deserialize(new StringReader(xml));
return bar;
}
}
regards,
George
|
|
|
|
|
iam not able to cut,copy,paste a usercontrol(picturebox) on a form.As such there is no buitin cut,copy,paste property for a picturebox.
i want code to add cut,copy,paste property for a picturebox control on the form design at runtime in vc#.net.
Please let me know how to add a property for the usercontrol . or let me know if u need any more details regarding this.
shabana
|
|
|
|
|
You will need to add a context menu for right click functionality, keyboard handlers using keydown or keypress for keyboard shortcut functionality and use the System.Windows.Clipboard or System.Windows.Forms.Clipboard class.
Additionaly you may need to override WndProc, PreProcessMessage and maybe ProcessMnemonic.
Some or all of these should solve your problem.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hey everyone,
I would like to break through 2 loops with just one rule.
Something like this:
for(;;)
{
for(;;)
{
}
}
|
|
|
|
|
Hi,
there are several ways of breaking out of several loops:
1. change the state such that all the continuation tests will fail, and break (one way of achieving this is by adding a boolean test to each and every continuation test)
2. create a method that contains nothing but the loops, and return where you want to break out;
3. throw an exception and catch it where you need to.
|
|
|
|
|
Yes I've thought of those options too, but I don't want to break with extra code, not even a boolean.
With 'break;' you will exit one loop. But isn't there something like break * 2;
|
|
|
|
|
Deresen wrote: But isn't there something like break * 2;
You will end up in goto .
|
|
|
|
|
Hi,
No. Although there are languages that support break <count> C# isn't one of them.
|
|
|
|
|
Luc Pattyn wrote: 3. throw an exception and catch it where you need to.
Exceptions to control program flow? Isn't that a crime?
Regards,
Rob Philpott.
|
|
|
|
|
Hi,
Rob Philpott wrote: Exceptions to control program flow? Isn't that a crime?
Not always. The OP didn't mention why nor how often he would break out of all loops.
Exceptions always operate on program flow, they exist to make life easier and code more reliable. Not making good use of available means would be a crime. Depending on circumstances, one has to make a good choice, that is why I gave three possibilities.
|
|
|
|
|
Rob Philpott wrote: Exceptions to control program flow? Isn't that a crime?
Nope, if the condition that breaks the loops is exceptional.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Agreed. But use otherwise deserves a slap!
Regards,
Rob Philpott.
|
|
|
|
|
4.use goto .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Absolutely. That is covered by "Not making good use of available means would be a crime".
|
|
|
|
|
Luc Pattyn wrote: Absolutely
I agree, in fact this is the perfect example of when a goto may be the most appropriate. It can be a useful statement - it's only because it can be (and has been) wildly misused that it's frowned upon.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I love the goto statement, so I will use it.
It let's me think of the good times programming microcontrollers in assembly!!!
|
|
|
|
|
You can use break for the second loop and a boolean variable to be used inside the condition for loop 1 and set this to true from loop 2.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
If you were using Java, I'd say "break OuterLoop;" (by adding the label "OuterLoop:" before the outer loop). But since you're in C#, you need to do this:
for ( ; ; )
{
for ( ; ; )
{
goto EndOfLoop;
}
}
EndOfLoop:
(You may also check the second example in this[^] MSDN reference page, although I wouldn't like to see it in actual code!)
|
|
|
|
|
I have been strugling with some issues regarding .NET Remoting mechanism.
Lets look at the 3 following simple lines -
httpChannel = new HttpChannel(props, null, new SoapServerFormatterSinkProvider());
ChannelServices.RegisterChannel(httpChannel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Colors),"Colors", WellKnown.SingleCall)
OK.
I. what does RegisterChannel() actualy does?
or better yet, My client succeeds calling the server object even if I delete the RegisterChannel row.
So, why is it important?
II. Is there a way to progammaticly close a channel.
I mean if I unregister a channel - I can still call from client my remote object on the server
only if I close the server application the channel is closed . But I want to close him from within the server app.
10x a whole lot.
|
|
|
|
|
|
Don't bump your posts, it's very rude!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I'm not claiming any knowledge of this as I've never used it but I've just read the docs on the RegisterChannel and Unregister channel.
It appears that you may only need to use these methods to add/remove additional http or tcp channels to the registered channels list. By default, there are ones named "http" and "tcp" which is probably what's being used by your app. The registered channels list requires unique names which is why these methods are there in case you need to have more than one of either type.
I may be way off here - as i said I've never used it - but the docs seem to imply this.
Alt Register Channel Page[^]
RegisterChannel[^]
UnregisterChannel[^]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Yes, I read those docs, and maybe I missed something.
Channels require a number, Port number that is, and not a name.
The client connect through the port number .
And it can do that even if I dont register the channel at the server.
Why do I need to register the channel then?
And most important how do I release the channel?
10x.
|
|
|
|