|
Hi All,
Can anyone send some links on creating well organised/factored reuseable classes. I've been looking through google but haven't found much as of yet.
Thanks,
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
|
Isn't it just!
Thanks for this ... really good reading.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
experance really helps in this, and mark clifton a fellow cp'er has written some good articles on this.
You can only be young once. But you can always be immature.
- Dave Barry
|
|
|
|
|
Im trying to send a class full of variables to a DLL Method and then have that method do some calculations and then send the class back to the client. IS that possible? Im getting an error that the current argument cant be converted.
|
|
|
|
|
Yes this will work just fine, so long as the "class full of variables" is a class that's visible to both sides.
e.g. MyProgram - references MySharedDll
Creates new <code>ClassFullOfVariables</code>
Sends instance over to MyOtherDll
MySharedDll
Contains the type
<code> class ClassFullOfVariables { ... }</code>
MyOtherDll - referencesMySharedDll
Contains a method: <code>DoCalculations(ClassFullOfVariables input)</code>
|
|
|
|
|
Cozmo23 wrote: IS that possible?
Yes.
are you passing the object ? does dll file have the defination of that class?
can you put the code over here
Best Regards
-----------------
Abhijit Jana
"Success is Journey it's not a destination"
|
|
|
|
|
The class you're passing back and forth would have to be defined in another DLL, that your other DLL would then "use".
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
What I have done so far is included the Class "PumpTest" (Class full of variables) in both the client and the DLL and attempted to use the code
"pTest = Calc.TableIIcalc(pTest); " to pass the PumpTest pTest to the DLL.
My DLL looke like this
public PumpTest TableIIcalc(PumpTest pTest)
{
calculations
return pTest;
}
I planned on making the PumpTest class its own DLL, would that solve the problem?
|
|
|
|
|
What makes you think this will not work?
You can only be young once. But you can always be immature.
- Dave Barry
|
|
|
|
|
Well I get two errors with the "pTest = Calc.TableIIcalc(pTest);" line of code
The first is a invalid arguments error, the second is Argument '1', cannont convert from 'Namespace.PumpTest' to 'Namespace2.PumpTest' they aren t actually called namespace but I cant post too much info about the program on the web. Namespace is the name of the client and namespace two is the name of the DLL.
|
|
|
|
|
Hello,
I'm stuck with the following issue:
let's say there is a DateTime 'timepoint', wich is passed in my method. I need to check now, whether timepoint's DayOfWeek is between 'fromDayOfWeek' and 'toDayOfWeek'.
that's what I've done so far:
protected override bool checkTimepoint(DateTime timepoint, DayOfWeek from, DayOfWeek to)
{
bool retValue;
retValue = timepoint.DayOfWeek >= from && timepoint.DayOfWeek <= to;
return retValue;
}
This will work for ranges like Monday-Friday, Thursday-Wednesday, Wednesday-Wednesday, but it will fail for something like Saturday-Sunday, since Sunday (0) is lower than Saturday(6).
Any idea on how to logically implement this issue?
Thanks in advance.
|
|
|
|
|
We solved a similar problem by using a mapping from DayOfWeek to integer that returned 7 instead of 0 for Sunday.
This way your code would work, too.
Not very nice but it works.
For .net the week start on Sunday
-^-^-^-^-^-^-^-
no risk no funk
|
|
|
|
|
This will fix the problem for Saturday-Sunday, but it will not solve for Saturday-Tuesday.
|
|
|
|
|
why not:
protected override bool checkTimepoint(DateTime timepoint, DayOfWeek from, DayOfWeek to)
{
return timepoint.DayOfWeek >= from && timepoint.DayOfWeek <= to;
}
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
because this doesn't work.
testcase:
timepoint = new DateTime(2008,5,4);//sunday, 0
from = DayOfWeek.Friday; // 5
to = DayOfWeek.Tuesday; // 2
return 0 >= 5 && 0 <= 2;
return value is 'false', but sunday is between friday and tuesday!
|
|
|
|
|
You can use the CultureInfo class to set the first day of the week.
using System.Threading;
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
So, set the first day of the week to whatever day you want, and then do your comparison.
protected override bool checkTimepoint(DateTime timepoint, DayOfWeek from, DayOfWeek to)
{
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek = from;
bool inRange = timepoint.DayOfWeek >= from && timepoint.DayOfWeek <= to;
Thread.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
return inRange;
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Friday, May 2, 2008 1:26 PM
|
|
|
|
|
Huh, interesting.
I wonder how it performs in a loop.
|
|
|
|
|
If performance is an issue (in a loop), you could always wait until the loop is done and reset to the proper 1st day at that point, thus saving n calls to do it in that checkpoint function.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Just thought I'd let you know I was completely wrong.
I posted a new response to the OP with the correct solution.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
What? Say it ain't so! 
|
|
|
|
|
return ( true ) ;
Every timepoint falls between some DayOfWeek X and some DayOfWeek Y.
buchstaben wrote: Thursday-Wednesday
Did you mean that?
If you want Sunday to sort higher than Saturday, then you can simply add seven to it, but you'll need to store the values as integers rather than as the provided enum values.
int x = (int) timepoint.DayOfWeek ;
int y = (int) from ;
int z = (int) to ;
x += x==0 ? 7 : 0 ;
y += y==0 ? 7 : 0 ;
z += z==0 ? 7 : 0 ;
return ( x >= y && x <= z ) ;
but that's rather ugly.
|
|
|
|
|
You can set the first day of the week to be thursday, and then the comparison would work.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Ignore my first post. This is the best way (notice no bizarre culture crap going on):
DayOfWeek from = DayOfWeek.Thursday;
DayOfWeek to = DayOfWeek.Tuesday;
DayOfWeek currentDay = DayOfWeek.Wednesday;
bool inRange = (currentDay >= from || currentDay <= to);
Notice that I'm using OR instead of AND . If you make currentDay Wednesday, inRange will be false. If you make it any other day, it will be true.
It's kind of pointless to do a Sunday-Saturday (or similar) comparison because any date will fall into the range. BTW, the comparison above also works for from=Saturday and to=Sunday.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I was just reviewing a method I wrote a few months back where I was checking to see if a value (integer) is between two others. I decided I needed more than a true/false, there are (currently) four result values:
[System.FlagsAttribute()]
public enum CheckRangeResult
{
WithinStrictRange = 0
,
Low = 1
,
High = 2
,
WithinLooseRange = 3
}
Basically; given Min, Max, and Test we expect Min to be less than Max; and Test will be Lower than Min (1), Higher than Max (2), or WithinStrictRange (0).
But, when Min is greater than Max and Test is between Min and Max, both tests are true, yielding WithinLooseRange (3).
In the case presented here, when Min is greater than Max and Test is not between the values, that should translate to "true", but that's not currently supported.
I think I need to add value 4 to indicate that Min is greater than Max, then WithinLooseRange would have value 7. I'll think about it over the weekend.
|
|
|
|