|
devvvy wrote:
var carTypes = (from type in types
where type.IsClass && type == typeof(Car)
select type);
That's not going to do what you want. You're trying to find all sub-classes of the Car type, but your query is looking for types which are exactly the Car type.
I suspect you want to use Type.IsAssignableFrom(Type)[^] :
var carTypes = (from type in types
where type.IsClass && !type.IsAbstract && type.IsAssignableFrom(typeof(Car))
select type);
JsonConvert provides a non-generic method[^] you can use to deserialize your data. To access the result, you need to use a covariant interface[^] combined with the base type. For example:
var listType = typeof(List<>).MakeGenericType(carType);
var cars = (IReadOnlyList<Car>)Newtonsoft.Json.JsonConvert.DeserializeObject(json, listType);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hello
in the middle of trying to refactor out a nightmare that I have inherited and there is no documentation. The source looked something similar to this
var outcome = MethodCall(param1, param2, param3) ? AnotherMethod(MethodCall(param1, param2, param3), Enum.Value) :
MethodCall(param2, param3, param4) ? AnotherMethod(MethodCall(param2, param3, param4), Enum.Value) :
MethodCall(param3, param4, param5) ? AnotherMethod(MethodCall(param3, param4, param5), Enum.Value)
I have refactored this down to a series of If else but now I am at the following stage which I want to refactor because of the following. Apart from refactoring this into a series of nested if statements so that I dont have to call the same method twice in an if statement I am stuck.
if(methodcall(param1, param2, param3))
{
outcome = AnotherMethod(MethodCall(param1, param2, param3), someintValue);
}
else if (methocall(param2, param3, param4))
{
outcome = AnotherMethod(MethodCall(param2, param3, param4), someintValue);
}
else if (Methodcall(param3, param4, param5))
{
outcome = AnotherMethod(MethodCall(param3, param4, param5), someintValue);
}
Any advice would be greatfully recieved.
Thanks
Simon
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
How about this:
if(MethodCall(p1,p2,p3)||(MethodCall(p2,p3,p4) || MethodCall(p3,p4,p5)){
outcome = AnotherMethodCall(true, someIntValue);
}
From your code, I understand that MethodCall is of bool return type and if any one of three calls is true , we call AnotherMethodCall with true and a number. So, here is how it can be broken down. If I could, I would refactor method one to take in more arguments so only one call will tell me if it returns true for various input sets.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[ ^]
|
|
|
|
|
I make no apologies:
if(methodcall(param1, param2, param3)) {
outcome = AnotherMethod(MethodCall(param1, param2, param3), someintValue);
return;
}
if (methocall(param2, param3, param4)) {
outcome = AnotherMethod(MethodCall(param2, param3, param4), someintValue);
return;
}
if (Methodcall(param3, param4, param5)) {
outcome = AnotherMethod(MethodCall(param3, param4, param5), someintValue);
return;
}
throw new exception( "Logic error" );
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi,
as others already noted, every second call to MethodCall(param1, param2, param3), I mean the ones after the question marks, is likely to return true, as you just have tested for true (that is what the question mark does). I say likely, it might be ugly code that creates or uses nasty side effects. If so, what follows needs some adjusting.
it seems all your params have the same type, and all your someIntValues have different values, so I would suggest you:
1. stuff all the params in an array "paramsArray"
2. stuff all the someIntValues in an array "someIntValuesArray"
3. modify your MethodCall() to accept paramsArray and return an integer, being the first index in the paramsArray for which the original MethodCall() did return true; this basically means surrounding existing code with a for loop, adjusting the params (now array elements); also return a special value if no match found, say -1.
4. then simply do
int index=MethodCall(paramsArray);
if (index>=0) outcome=AnotherMethod(true, someIntValuesArray[index]);
|
|
|
|
|
Hi,
i have a report with the below structure
<group 1="">
<group 1="" header="">
<group2 footer="">
i'm trying to export this report to excel with repeated headers and footers with N number of rows to print the report..
After setting the page break calculations and repeat header and footers, the report does not break with the exact N number of rows..
i have few merged rows inside the report and conditions to hide rows..
Appreciate if some one could help me to achieve this... its really urgent
thanks in advance
|
|
|
|
|
|
I've just checked and nobody here appears to have this on their ToDo list at all, much less near teh top.
Are you sure it's urgent? Even the cat isn't too fussed about it at the moment.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I've go no experience at all in scanning barcodes, so excuse my ignorance.
What's involved in scanning a barcode and getting back the product's image?
I can provide more detail on the projects idea if needed.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Most barcode scanners are of the "keyboard wedge" variety. Scan a code and it "types" the code into your application.
The thing is, since the scanner types the code, you have to have a way of recognizing that the code is being typed by the scanner. So, most scanners will also let you configure a prefix and postfix you can add to the code. If you setup your code to look at every keystroke at the form level (Key Preview) you can look for the prefix and if you see it, set the focus to a textbox that takes the code, and the look for the postfix to know that the code is done.
As for the image, you have to look up that barcode in your own database if you've got images for each item. If not, there's public databases that have this stuff, but don't count on a free one. How you access them is dependent on the API for the vendor you use.
|
|
|
|
|
The scanner is the simple bit - all it returns is a string effectively, which contains the Article Number. Converting that to a product needs a database.
There is a free one here: Open Product Data[^] which you can access via code, but I've not done it. This chap has: OurGroceries[^] and he's a really nice guy. Ask him politely and he may share his code with you (particularly if you aren't in competition with him!)
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks Griff.
Just found this:
POD - Product Open Data -
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Hi Guys.
I'm trying to learn C# at the moment. I did some years ago using .net and WinForms but revisiting the language it seems WPF is the way to go? It might be me, but WPF seems a great deal more fiddly. Solutions that were really quite simple in Winforms, appear to take longer to code in WPF!
Not to rant. I'm sure there are many hidden benefits to WPF if I just stick with it! but I'm currently tearing my hair out after about 4 hours of failed googling. I just wanted you to know where my head is at before I go into the specific problem. I'm sure I'm not the first to find myself staring at the WPF framework in total confusion.
So. I managed to build a form (Window lol) with 5 buttons. Each button successfully opens an instance of a child window. One of these windows called 'LogWindow' contains (yes you guessed it) a textbox that I'm using as a log. Another window, that 'does something' needs to output a text based result (success or fail) to the LogWindow textbox.
I though this would be as easy as saying LogWindow.Textbox1.Text += updateText + /r/n" or something like that, but no, apparently not in WPF land.
Can anyone point me in the direction of a simple example where this is done? I think my knowledge needs more of a refresh than I thought lmao!
My Code Parts:
private NetworkingWindow NetworkingWindow = new NetworkingWindow();
private ClientWindow ClientWindow = new ClientWindow();
private LogWindow LogWindow = new LogWindow();
foreach (Error NetErr in results.Errors)
{
LogWindow.LogTextBox.text += updateText + /r/n"
// I suspect that this is wrong and I'm contacting the control in a non WPF manner
}
Any help would be greatly appreciated. Fully working examples with comments would be fantastic as I tend to go grab a coffee and read through them to try and learn what I can that way.
Thanks All!
|
|
|
|
|
Member 14058802 wrote: it seems WPF is the way to go?
Um ... not sure about that: WPF Dead or Not?[^]
There doesn't seem to be much support of / for WPF at MS - UWP and Xamarin Forms appear to be getting all their attention.
And my personal impression is: nice idea, badly implemented in VS. The designer is a true PITA after the simplicity that is WinForms! Doing anything pretty much means manual editing of the XML.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks for the feedback Griff.
I'm 41 and so have plenty of experience of Microsoft technologies getting ummm... 'Microsofted'? I guess this is one of those times.
So, I'm already feeling like it might be a good idea to drop back to WinForms? or is there a better way that I've not even found yet?
I've only built about 6 windows in wpf and the c# can be tweaked back to fit Winforms, so it won't be a problem. I'd just like some help to get pointed in the right direction if that's ok!
Best Regards,
James
|
|
|
|
|
Wait and see what others say - I've been wrong before.
WPF just doesn't feel "finished" - the framework support is good, but the designer stuff feels like "version 0": thrown together to test the tech rather than written for release to devs.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Ok so, problem solved!
I'm going to thank Griff (Thanks Griff!)
After the last update, I decided to go for a walk with the dog and contemplate a possible move back to Forms. I'm not great with C# but I'm enjoying it. I reasoned that maybe I need to stick with Forms which are more familiar, so that I can stick to learning C# better and then maybe move to WPF later on.
I think maybe the fresh air awakened some brain cells as it dawned on me that this isn't a WPF problem, it's a C# problem... or rather a me forgetting the fundamentals of access modifiers problem. As soon as I realised, the dog just got a shorter walk then normal (sorry dog lol).
Sorry to waste your time Griff, but thanks for the chat.
As soon as I changed the logwindow instance to static, and called the LogUpdater method from the child Window it worked!
private static LogWindow LogWindow = new LogWindow();
public static void LogUpdater(string stringUpdate)
{
LogWindow.LogTextBox.Text += stringUpdate + "\r\n";
}
James Wyatt - Putting the fun back into fundamentals!
|
|
|
|
|
|
|
I'd really enjoy reading an article from you describing your experience with these newer tools. Is the "desktop bridge" usable without high-overhead ?
thanks, Bill
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I'm going to dispute OG assumption that WPF is dying or dead (I'm the dev who is still pissed at Silverlights demise so...) WPF has a steep learning curve especially from winforms. I found it well worth the effort as once you get moderately proficient production is fairly rapid.
Work through a few tutorials, get familiar with MVVM, I use the GalaSoft framework because it is really minimalist.
One additional benefit is that Xamarin forms seem to be based on the same xaml concepts.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Thanks Mycroft. I'll take a look. I'd not heard of Galasoft yet, but yes, MVVM references keep popping up during my travels.
|
|
|
|
|
Lots of options:
public string TheText { get; set; } = "Bound value";
private void UxOK_Click( object sender, RoutedEventArgs e ) {
Window log = new Window();
TextBlock tb = new TextBlock();
tb.FontSize = 24;
log.Content = tb;
tb.Text += "Good" + Environment.NewLine;
tb.Text += "Bye";
log.Show();
}
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Hi,
i have a report with the below structure
<group 1="">
<group 1="" header="">
<group2 footer="">
i'm trying to export this report to excel with repeated headers and footers with N number of rows to print the report..
After setting the page break calculations and repeat header and footers, the report does not break with the exact N number of rows..
i have few merged rows inside the report and conditions to hide rows..
Appreciate if some one could help me to achieve this... its really urgent
thanks in advance
|
|
|
|
|
This issue I have it for a while, almost 1 year or more. I tried diverse permutations but always got stuck at some point, when the whole idea will not work anymore. And I give up all the time on it.
I have a class with properties, fields and methods in it. I am thinking to add events to it, but im not that great at them yet. When i call this class into form1 I basically change some values inside class, and the "object" that represents it, will add value or change color or change position ,etc.
If i have a game let's say, when the character stays and I want him to look like it's breathing, this property should be inside the class? or outside, letting me choose when to breathe, how much, how long, how fast,etc. It's just an example. I had a lot of similar (and more complex) encounters with this subject and I simply freeze in the middle of it, not knowing how to manage it anymore.
Both ways are good! From outside or from inside class. But... sometime i need maneuverability, sometime is just in the way and i want it 'there' behind some close door(inside class I mean).
What your rules say about this thing? Should I change its values from inside the class? Or from outside?
Thank you.
------
thanks to OriginalGriff i relocated here the question.
q12
|
|
|
|
|