|
I have a hierarchy of classes, all of which implement this interface:
public class IRuleObject
{
int Sequence { get; set; }
}
Here's the top level class:
[Serializable]
[XmlRoot("Group")]
public class RuleGroup : IRuleObject
{
[XmlAttribute("ID")]
public int GroupID { get; set; }
[XmlAttribute("Sequence")]
public int Sequence { get; set; }
[XmlAttribute("Name")]
public string GroupName { get; set; }
[XmlAttribute("Active")]
public bool Active { get; set; }
[XmlElement("Rules")]
public List<Rule> Rules { get; set; }
}
You can see where it implements the interface.
When I attempt to serialize I get
Type 'RulesEngine.IRuleObject' in Assembly 'RulesEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
If I remove the interface, all works well. How do I set this up so i can use the interface & still serialize the
classes?
Everything makes sense in someone's mind
|
|
|
|
|
I'm just curious as I'm not sure this is the problem or if this will work, but did you try adding the Serializable keyword to the interface?
|
|
|
|
|
LOL - I figured that out right after I posted.
I didn't think that you could mark an interface as serializable.
Everything makes sense in someone's mind
|
|
|
|
|
it always takes me several iterations to get Serialization to not throw errors...and then a few more iterations to actually get it to output it the way I'm expecting it to.
It's helpful, but it can sure be a pain...especially with nested classes, inherited classes, and apparently interfaces as well.
|
|
|
|
|
Agreed.
Actually I first tried to base all my classes of an abstract, but that's nearly impossible with serialization, so
I decided that an interface would work.
In either case, you're right. It's a PITA to set up but very useful. On top of all this, I'm base64 encoding
the file after it's serialized. Makes it a bit tough to open it & look at it.
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: Makes it a bit tough to open it & look at it.
If you prefer the data isn't human readable, I recommend you use binary serialization. It's also a lot faster (which may not be an issue for you, but you kill two birds with one stone).
/ravi
|
|
|
|
|
Hi guys,
Last week, I rolled an app out to production and wouldn't you know, today someone comes to tell me "We're not going to be able to use Port 20 for FTP. Production Management has a separate data port for us." Reasoning is irrelevant for this discussion, but that left me trying to surgically modify my Upload code to allow for a different port to be specified. It ended up being easy, but the way it works kind of left me scratching my head.
For anyone that needs to replicate this, all you have to do is specify your port number after the host name. Really easy. ...But, the thing that puzzled me is that this worked while I had the UsePassive property of my ftpWebRequest set to true (I tested before I had gone in and checked the request's properties)
Since I had specified for the ftpwebrequest to sent a PASV command to the server, why was I able to dictate to the server which port number it was going to be receiving data on?
RFC 959 Section 3.2 states that the client may specify an arbitrary port via a PORT command, but I did not issue a PORT command...I issued a PASV command. For this to work, there must be something else going on under the covers of FtpWebRequest.
Can anyone shed light onto why I was able to specify a port while in Passive mode?
"I need build Skynet. Plz send code"
|
|
|
|
|
Hi all,
I am a beginner in C# and .Net
I have been reading the Wrox Visual C# 2008 book, and I don't understand and see the use of Iterators.
This might sound a bit dumb but I need to ask because I don't understand at all.
I had a look at MSDN but I am still feeling unhappy!
So here is what I have understood so far:
- foreach loop implements IEnumerable Interface
- You implement IEnumerable for a class member and IEnumerator for a class
- With yield keyword, you don't need to implement the members IEnumerable (Current, MoveNext(),...)
Is it correct?
And what is the use of Iterators? What is the difference with the foreach loop?
Could someone give me some insight please?
Bon_chan
|
|
|
|
|
bon_chan wrote: Is it correct?
No, all of that is wrong. I'll try to keep it simple, which may make it slightly incorrect. Here you go:
Enumerator, iterator and enumerable are pretty much the same. They offer an abstracted way to enumerate items in a collection, which means getting access to them, one after the other, in sequence.
foreach(someType varName in someCollection) does not implement IEnumerator nor IEnumerable; it requires someCollection to implement IEnumerable, as it will use an enumerator on someCollection and loop its way through it; you could do that yourself, based on a for loop and an explicit call to someCollection.GetEnumerator().
yield is a keyword that got introduced later; it helps in enumerating virtual collections, i.e. collections that do not really exist as a set of elements all available concurrently. You should not worry about it at all, until you fully understand everything else about enumerators.
Summary: it is all about enumerating; you don't really need it; it can come in handy; it can be virtualized. Take it one step at a time.
PS: Wrox books have good reputation; you should study some more. And experiment a bit too.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
bon_chan wrote: - foreach loop implements IEnumerable Interface
Foreach is just an instruction. It does not implement anything.
bon_chan wrote: You implement IEnumerable for a class member and IEnumerator for a class
No. See here.
bon_chan wrote: With yield keyword, you don't need to implement the members IEnumerable (Current, MoveNext(),...)
Yield is just a keyword. It has nothing to do with whether you need to implement some IEnumerable methods or not.
My signature "sucks" today
|
|
|
|
|
OK Thanks for your answers.
I understand a bit better, but yet I am still missing some parts.
Let's say we have a class called MyClass
So if we want to use foreach instruction, My Class must implement IEnumerable.
And then because IEnumerable contains GetEnumerator() signature, we have to implement that method in MyClass.
And because GetEnumerator() returns an IEnumerator, we need to implement IEnumerator interface as well (Reset(), MoveNext(), Current()). Is that correct?
But why does my Wrox book say:
Here is an extract of my wrox book:
<<
- To iterate over a class, use a method called GetEnumerator() with a return type of IEnumerator.
- To iterate over a class member, such as a method, use IEnumerable.
>>
I am confused
And why does the following code works without implementing IEnumerable???
<br />
using System;<br />
using System.Collections;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
<br />
namespace Ch11Ex03<br />
{<br />
public class Primes<br />
{<br />
private long min;<br />
private long max;<br />
<br />
public Primes(): this(2, 100)<br />
{<br />
}<br />
<br />
public Primes(long minimum, long maximum)<br />
{<br />
if (min < 2)<br />
{<br />
min = 2;<br />
}<br />
else<br />
{<br />
min = minimum;<br />
}<br />
max = maximum;<br />
}<br />
<br />
public IEnumerator GetEnumerator()<br />
{<br />
for (long possiblePrime = min; possiblePrime <= max; possiblePrime++)<br />
{<br />
bool isPrime = true;<br />
for (long possibleFactor = 2; possibleFactor <=<br />
(long)Math.Floor(Math.Sqrt(possiblePrime)); possibleFactor++)<br />
{<br />
long remainderAfterDivision = possiblePrime % possibleFactor;<br />
if (remainderAfterDivision == 0)<br />
{<br />
isPrime = false;<br />
break;<br />
}<br />
}<br />
if (isPrime)<br />
{<br />
yield return possiblePrime;<br />
}<br />
}<br />
}<br />
}<br />
}
<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
Primes primesFrom2To1000 = new Primes(2, 1000);<br />
foreach (long i in primesFrom2To1000)<br />
{<br />
Console.Write("{0} ", i);<br />
}<br />
Console.ReadKey();<br />
}<br />
}<br />
|
|
|
|
|
I have a simple 2d map (similar to classic sonic look) however I am not sure how to make my character walk up the map as it is not flat land (has slanted flooring).
I have though of per pixel detection but this sounds sloppy and expensive just for the flooring.
I have also though of polygon based collision however I only know how to find the slope of the two points but cant figure out how to change the sprites y position so that it can moove up the slope. The only way i can get it to work is by having many polygons plotting each point to make up the slope but its not very fun this way.
I read but did not find it helpful as the sprite just moves to the next way points y axis !
|
|
|
|
|
Are you working with XNA? There are some pretty good sprite tutorials that can help you out with this. The RPG tutorial that was posted at xnatutorial.com a few years ago did a pretty good job of assisting with making partial tile movements (would allow your character to move to its destination tile in framerate based increments so that he would go through a sprite based walk cycle) Let me see if I can find the link for you...or maybe someone else will beat me to it.
[Edit: I had the wrong tutorial site in mind. XNATutorial was not it, and I can't remember the exact location of it at the moment. If I recall it, I'll try and post the location. But, until then, you might want to check here[^]
[Edit: I remembered the location of the original tutorial I was thinking of, but this is gonna be a bummer. It was at www.ziggyware.com and Ziggy hasn't had the site up in over a year. He had some trouble with hackers and finally just shut the thing down. Hopefully that other tutorial list will give you the information you need]
"I need build Skynet. Plz send code"
modified on Monday, May 24, 2010 3:01 PM
|
|
|
|
|
Hmmm....another thought...without a tutorial. Have you thought of rotating your character based upon the slope of the "terrain" and set it's bottom left corner to snap to the top left corner of the ground? (Assuming that your Sonic runs on top of the ground, of course )
...That would put your character at the correct x location, ground his "back" point correctly and then the rotation of the character based upon the terrain slope should produce an effect that would keep him in contact with the ground as if he were running on a flat surface (Assuming your math is correct)
"I need build Skynet. Plz send code"
|
|
|
|
|
To follow up, the method that I posted earlier will work if your terrain is a constant slope, but you'll have to do something special for areas where the slope changes (i.e. the tile that transitions from 'flat' to 'hilly') That could be done by keeping a Stack of the 3 tiles that your character is interacting with.
Let's create a section of terrain, listing the slopes in left to right sequence
float[] terrain = new float[10];
terrain[0] = 0.0;
terrain[1] = 0.0;
terrain[2] = 0.0;
terrain[3] = 0.5;
terrain[4] = 0.5;
terrain[5] = 0.5;
terrain[6] = 0.0;
terrain[7] = -0.5;
terrain[8] = -0.5;
terrain[9] = 0.0;
So, if you can visualize this, it would be a section of flat ground, followed by a hill that has a slope of 1/2 that rises for 3 tiles, flattens off for 1 tile and then descends at 1/2 for 2 tiles.
You could want to maintain a "frame" of reference via a stack with the 3 tiles that are being interacted with. There is the tile that you are standing on, the tile behind you, and the tile in front of you. Pressing the -> arrow would move him forward. Pressing the <- arrow would obviously perform the reverse. Let's deal only with "forward" movement for this example.
Whenever your player tells Sonic to "move forward" the rotation that you apply to him will be contingent upon "Current Tile Slope" AND "Next Tile Slope"
...that way, if your player decides to stop him while one foot is still on the "Current Tile" but the lead foot is on "Next Tile" you will still maintain believable contact with the ground. Once Sonic's trailing foot is completely upon "Next Tile", your stack should shift to the next tile so that the "frame" refers to the next tuple of slopes.
So, to walk through this scenario (this is a barebones algorithm. There are more moving parts to it that are contingent upon your game specifics)
(Calling your player "Sonic" for brevity)
Note that I am saying "debounced" step to indicate that your player is not holding the forward movement button down. Your game loop needs to process ONE forward command...to explain the base case. "Holding down the button" will just loop the ONE forward command until the button is released, obviously.
setup)Let's say Sonic is standing on square 3. Your frame would contain {0, 0, 0.5}
KeyValuePair<int, float>[] frame = new KeyValuePair<int, float>[3];
frame[0] = new KeyValuePair<2, terrain[2]>();
frame[1] = new KeyValuePair<3, terrain[3]>();
frame[2] = new KeyValuePair<4, terrain[4]>();
1)Player issues a debounced step forward. (Issue one step forward) Sonic would advance one step in your walk cycle animation.
2)Check width of Sonic with width of tile, compare Sonic's trailing point + step offset to width of tile.
3)If ((Sonic's trailing foot position + Sonic's width) > tile width) his lead foot has moved to the next tile. You need to use "This Tile"s slope for trailing foot and "Next Tile"s slope for leading foot to determine the rotation that needs to be applied.
float rotateZ = CalculateRotation(frame[1], frame[2]);
Sonic.Rotate(rotateZ);
4)If (Sonic's trailing foot position > (tile width + Sonic's width)) then the trailing foot has moved away from "This square" Cycle your frame to track a new square as "This Tile"
OffsetFrame(1);
Sonic.Rotate(CalculateRotation(frame[1], frame[2]));
public void OffsetFrame(int offset)
{
frame[0] = new KeyValuePair<((int)frame[0].Key + 1), terrain[(int)frame[0].Key +1]>();
frame[0] = new KeyValuePair<((int)frame[1].Key + 1), terrain[(int)frame[1].Key +1]>();
frame[0] = new KeyValuePair<((int)frame[2].Key + 1), terrain[(int)frame[2].Key +1]>();
}
5)Loop 1-4
So, again for simplicity's sake, let's say that each debounced forward step moves your character from square to square "a la Frogger style". Your frame would look as such, starting with "This Tile" referencing square 3.
Frame: {0, 0, 0.5}
[Step forward]
Frame: {0, 0.5, 0.5}
[Step forward]
Frame: {0.5, 0.5, 0.5}
[Step forward]
Frame: {0.5, 0.5, 0}
[Step forward]
Frame: {0.5, 0, -0.5}
Get the idea? You're dealing with a sprite based walkcycle and multiple pitch terrain collision, so there are more details that are specific to your game but that should get you started in a direction that will at least get you moving. The "Frogger" example is to illustrate what I mean to do when Sonic's trailing foot moves onto a new square, but you won't be moving square by square. You'll be moving a partial square for each forward command to indicate a single step. Hope it's clear where the two examples above meet together to provide you with smooth, animated sprite movement.
"I need build Skynet. Plz send code"
modified on Wednesday, May 26, 2010 11:05 AM
|
|
|
|
|
Thank you for you help I understand this concept better !
|
|
|
|
|
|
I think your code is getting confused by SelectionChanged events that indicate something got deselected. When you click an unselected item, you are likely to get two events: one indicating nothing is selected (which you may want to ignore, but it needs code to do that), then one indicating the new selection.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
That would make sense if these were standard controls. But they are custom controls based on System.Windows.Forms.UserControl -- not inherited from any actual list control like a ListBox. My SelectionChanged() event is a very tightly-coded event that only fires when a value is assigned.
|
|
|
|
|
please do not remove a question, it is against the forum guidelines and considered rude. If your problem is solved or no longer relevant to you, leave it as is, but add a marker (such as "solved") to the subject line. If you found the solution yourself, do not hesitate to publish it in the thread, so others can also benefit from it.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I apologize. If it's against forum guidelines, then why is a delete option even available?
I removed the question because the more I dug the more confused I got. I decided that I really don't know what the heck is going on and need to do a lot more digging.
I thought it would be more courteous to remove the thread altogether than to have people waste their time reading it only to get to the point where I say "never mind, I don't know what I'm talking about".
|
|
|
|
|
well, the remove widget removes a question completely if it has no replies; there is no harm in that.
and it replaces the question by "question removed" when there are replies; it really shouldn't be available under those conditions.
Removing the head of a thread leaves a sloppy thread; leaving it there may still result in new replies, maybe containing a link to the perfect article dealing with the subject.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Since there was no "remove" widget available, I was hoping that "delete" on the thread root would accomplish the same thing. Seems like the forum codebase itself could use a little tightening
|
|
|
|
|
While in VS2005 and working with a crystal report, I have encountered two problems I believe are related. First problem is that all my crystal report menu items are doubled and sometimes quadrupled. Meaning that if I have a report opened for editing, and press the Crystal Reports menu item, all the submenu items are in there 4 times. The same thing happens if I right-click on an item on the report.
The second ithing I noticed is that when I do an build on my application setup, I get 190 warning errors, indicating that I have duplicate objects in the target location, for instance, (Warning 1 Two or more objects have the same target location ('[toolbar]\removeallfield_over.gif') )
I think this have something to do with the fact that I first install the .net crystal addon, then later install the full blown 11.5 CR and then the R2 update.
My application runs fine, with no errors, however, I would like the resolve the minor inconviences. Any ideas out there?
Ken
|
|
|
|
|
Hi
I have a server app which handles multiple Ethernet camera. The server sends a video streams to a client application which is then displayed on screen. The problem is that I am recieving corrupt frames quite regularly at the client end. An example of a frame is below,
[][Corrupt frame]
I am using TCP to send the images. Anyone got any ideas of what could be causing this?
Thanx
|
|
|
|
|