Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
LongSack
Jan 17, 2003

Funking Giblet posted:

Figure out a different way to Populate your observable, and maybe, try not using an EF entity, but a DTO of some sort.

I’ve finally come to an understanding as to why you recommended this. Since the contexts are disposed, my data bindings are throwing a shitton of exceptions now. The only fix is to load my observable with classes with a bunch of added .Include() which loads way more memory than needs to be loaded.

So by adding DT objects as an added layer of abstraction, I can avoid attempts to hit the database with a disposed context. I think I will replace my character selection combo box of ObservableCollection<Character> with a List<int> or ObservableCollection<int> of character ids and when SelectedCharacterId changes, load up a new Character DTO from the new id.

I think.

I don’t think this added abstraction is needed for every entity, but on those with navigation properties, it’ll probably save me some headache.

Of course, abandoning EF and going back to my ADO data access layer classes would do the same. There is a lot of counter-intuitive stuff happening in EF, like getting an exception about not being able to create a relationship to an entity in deleted state when deleting. Why is it trying to create anything when I am deleting an item? I’m trying to learn, but man this kind of stuff is making it frustrating.

Adbot
ADBOT LOVES YOU

Akujiki
Nov 25, 2013


Hello everyone! I'm not entirely sure that this is the right place to post this but it's the closest I could find, so here goes.

I'm working on an interview presentation and for part of it I want to create a powerpoint slide that does a rudimentary text check for proper MLA or APA (haven't decided yet) citation in a string. Essentially, you would type in a sentence and then click a button and it would point to the problem area and explain what is incorrect, or alternatively to give an affirmative message if everything is in line.

I don't know about coding, so I'm hoping the fine goons here can point me in the direction of either sources that I can use to puzzle this out, or if not, possibly in the direction of something that I might be able to reverse-engineer into what I want.

Any help would be greatly appreciated!

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
For want of a proper Windows thread, I'll ask here: how would you write a UI for a Windows desktop application? My coworker wants to use Windows Forms but hasn't it been obsolete for a long time? Not that I know much about UI development on Windows...

Roid666
Jul 18, 2010

hackbunny posted:

For want of a proper Windows thread, I'll ask here: how would you write a UI for a Windows desktop application? My coworker wants to use Windows Forms but hasn't it been obsolete for a long time? Not that I know much about UI development on Windows...

Windows forms isn't going anywhere, but if I were learning from scratch WPF is weapon of choice now.

EssOEss
Oct 23, 2006
128-bit approved
What sort of app and who is the target audience in terms of users? WinForms is perfect for quick-and-dirty technical GUIs. WPF is the most powerful option but not very loved by Microsoft. UWP is the "modern mobile UI kit" that gets all the attention these days.

30 TO 50 FERAL HOG
Mar 2, 2005



yeah i just started building my first large app in WPF and its super annoying if youre used to winforms but once you get the hang of it things start to come together really nicely

bindings and XAML reduce the amount of UI code by absolutely obscene amounts. there's a lot of annoying boilerplate code though

what im struggling with now is figuring out how the hell to get my ViewModel to do something and then report the status of that action. from what i can tell the "offical MVVM" way is to have the View subscribe to an Interaction Service in the ViewModel and then issue a command to the ViewModel. the ViewModel executes the command and then pushes a message to the Interaction Service which the View receives and then performs an action

this is ludicrous if you want an "OK" button that saves some data and pops up an error message if something doesnt work

30 TO 50 FERAL HOG fucked around with this message at 16:06 on Jan 17, 2018

Mr Shiny Pants
Nov 12, 2012

NEED MORE MILK posted:

yeah i just started building my first large app in WPF and its super annoying if youre used to winforms but once you get the hang of it things start to come together really nicely

bindings and XAML reduce the amount of UI code by absolutely obscene amounts. there's a lot of annoying boilerplate code though

what im struggling with now is figuring out how the hell to get my ViewModel to do something and then report the status of that action. from what i can tell the "offical MVVM" way is to have the View subscribe to an Interaction Service in the ViewModel and then issue a command to the ViewModel. the ViewModel executes the command and then pushes a message to the Interaction Service which the View receives and then performs an action

this is ludicrous if you want an "OK" button that saves some data and pops up an error message if something doesnt work

You create a status label that is two way binded to your outcome. So in your GUI you have something like a status field and you save the outcome to the field its binded to in your viewmodel and the Gui will show the outcome if it is necessary.

At least, that is what I would do. :)

30 TO 50 FERAL HOG
Mar 2, 2005



Mr Shiny Pants posted:

You create a status label that is two way binded to your outcome. So in your GUI you have something like a status field and you save the outcome to the field its binded to in your viewmodel and the Gui will show the outcome if it is necessary.

At least, that is what I would do. :)

This is a dialog though, so when I hit "OK" I want to set DialogResult = true to close the dialog if the command is successful and pop up a MessageBox if it fails

Mr Shiny Pants
Nov 12, 2012

NEED MORE MILK posted:

This is a dialog though, so when I hit "OK" I want to set DialogResult = true to close the dialog if the command is successful and pop up a MessageBox if it fails

Ah, well that is a bit different, what I've seen is that you "fake" a dialog. You create a new XAML form that acts as a dialog and have a viewmodel that hides behind this form in which you update the state of the operation.

Dialogs in WPF are pain in the rear end, I think it wasn't even possible to have them in the older versions, but I could be misremembering.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Roid666 posted:

Windows forms isn't going anywhere, but if I were learning from scratch WPF is weapon of choice now.

"Not going anywhere" in the sense that they won't get any significant updates, or in the sense that they won't be dropped any soon?

EssOEss posted:

What sort of app and who is the target audience in terms of users?

General users - it's a communication application (voice chat & text messaging)

EssOEss posted:

WPF is the most powerful option but not very loved by Microsoft. UWP is the "modern mobile UI kit" that gets all the attention these days.

I was afraid you'd say that! I'd rather go with a desktop application unless there are very, very good reasons not to. Microsoft mobile platforms are not on our radar right now and they don't look like they'll ever be

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



hackbunny posted:

"Not going anywhere" in the sense that they won't get any significant updates, or in the sense that they won't be dropped any soon?

Both

quote:

I was afraid you'd say that! I'd rather go with a desktop application unless there are very, very good reasons not to. Microsoft mobile platforms are not on our radar right now and they don't look like they'll ever be

It's technically ~mobile-friendly~ and a requirement to use the app store IIRC. You know how most of the apps that come with Windows 10 look? That's probably what they're using.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

Munkeymon posted:

It's technically ~mobile-friendly~ and a requirement to use the app store IIRC.

For our customers, the app not being on the store might be a plus. Only thing that might be desirable to us about UWP is sandboxing, but (with effort) you can sandbox desktop apps in the same way, as Chrome famously does

Munkeymon posted:

You know how most of the apps that come with Windows 10 look? That's probably what they're using.

Yeah, let's just say I... don't love those. Is the single window UI a hard requirement or just convention?

Ciaphas
Nov 20, 2005

> BEWARE, COWARD :ovr:


Is there a way in C# to require that a string parameter (or hell numeric ones too) to a function be filled via a literal rather than a variable or other expression that requires evaluation?
C# code:
var result = Foo("id1"); // ok
string id = "id1"; var result = Foo(id); // not ok
It's an awkward edge case I'm running into involving walking CSharpSyntaxTrees from user scripts.

LongSack
Jan 17, 2003

Ciaphas posted:

Is there a way in C# to require that a string parameter (or hell numeric ones too) to a function be filled via a literal rather than a variable or other expression that requires evaluation?
C# code:
var result = Foo("id1"); // ok
string id = "id1"; var result = Foo(id); // not ok
It's an awkward edge case I'm running into involving walking CSharpSyntaxTrees from user scripts.

If there is, it would be some deeply weird poo poo involving reflection, but even then I am dubious, because typeof(“foo”) and typeof(string) are almost certainly the same.

Funking Giblet
Jun 28, 2004

Jiglightful!

LongSack posted:

If there is, it would be some deeply weird poo poo involving reflection, but even then I am dubious, because typeof(“foo”) and typeof(string) are almost certainly the same.

Wonder what nameof does in this scenario :D

kitten emergency
Jan 13, 2008

get meow this wack-ass crystal prison

hackbunny posted:

For want of a proper Windows thread, I'll ask here: how would you write a UI for a Windows desktop application? My coworker wants to use Windows Forms but hasn't it been obsolete for a long time? Not that I know much about UI development on Windows...

electron

:mrgw:

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



hackbunny posted:

Is the single window UI a hard requirement or just convention?

Looks like multiple windows are supported in UWP https://docs.microsoft.com/en-us/windows/uwp/design/layout/show-multiple-views

WPF is being neglected/in maintenance mode in favor of UWP because they figured out too late that it's to hard or impossible to offload things WPF does to a mobile GPU because of the way it's structured under the hood, IIRC. WPF, like Forms, won't go away because that would break thousands of internal applications that Microsoft's primary customers depend on.

Also worth noting that WPF and Forms can mingle! An application based on either can host controls from the other. Probably not a great idea to do that too much, but it's not a totally binary choice. Dunno if UWP will do that, too, but I'd be a kinda surprised if it did.

IME, WPF makes it easier to make a consistently good-looking UI, but slightly more annoying/convoluted to wire up the behavior that controls the UI. However, the wiring tends to be testable where Forms control code is much less so.

chippy
Aug 16, 2006

OK I DON'T GET IT

Is Electron really bad or something (or was this a serious recommendation)? I assume it was pretty good, mainly because there are some decent apps built on it. I saw an interesting blog article about creating an app that was basically a self-hosted WebAPI app using .NET Core, with an Electron UI.

chippy fucked around with this message at 16:26 on Jan 18, 2018

Dietrich
Sep 11, 2001

chippy posted:

Is Electron really bad or something (or was this a serious recommendation)? I assume it was pretty good, mainly because there are some decent apps built on it. I saw an interesting blog article about creating an app that was basically a self-hosted WebAPI app using .NET Core, with an Electron UI.

Electron's fine, I just wish it did a better job of handling stupid OS poo poo like app icons, keyboard shorcuts and menus to OS conventions without having to write a bunch of stuff. If you're mainly targeting windows and don't care if your app feels a little wonky under mac-os or linux then it's not bat at all.

This is all assuming that you have lots of experience working in web development, of course.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
Another question: correct me if I'm wrong, but .NET still doesn't have a standard way to specify/suggest that a return value or argument can't be null, right? There's Nullable to make value types nullable, but nothing to make reference types non-nullable? [and what's taking them so long?]


Noted


Noted. Sentence: hanged by the neck until dead

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Munkeymon posted:

WPF is being neglected/in maintenance mode in favor of UWP because they figured out too late that it's to hard or impossible to offload things WPF does to a mobile GPU because of the way it's structured under the hood, IIRC. WPF, like Forms, won't go away because that would break thousands of internal applications that Microsoft's primary customers depend on.

IIRC, WinRT's existence has less to do with WPF not having mobile GPU support, but more to do with the really dumb internal politics at the time.

WPF is not being neglected, nor is it "in maintenance mode". It's still a major, supported framework for building applications on Windows and new features are being added to it. Hell, even WinForms is getting new features in Windows 10, such as better high DPI support out of the box.

It's not just because of legacy reasons WinForms is still around. If you're making a simple program (Like CRUD, or whatever), and just need to wire something up quickly, WinForms is great for that. WPF and UWP have a bit of a learning curve to it that makes it less ideal for those use cases (even if, in the end, it would probably result in a more sustainable application if you need to do any maintenance on it).

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

hackbunny posted:

Another question: correct me if I'm wrong, but .NET still doesn't have a standard way to specify/suggest that a return value or argument can't be null, right? There's Nullable to make value types nullable, but nothing to make reference types non-nullable? [and what's taking them so long?]


It's coming:
https://blogs.msdn.microsoft.com/dotnet/2017/11/15/nullable-reference-types-in-csharp/

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Drastic Actions posted:

WPF is not being neglected, nor is it "in maintenance mode". It's still a major, supported framework for building applications on Windows and new features are being added to it. Hell, even WinForms is getting new features in Windows 10, such as better high DPI support out of the box.

When I google WPF and find a page full of articles wondering if it's dead, it's being neglected. High DPI support isn't a new feature as far as I'm concerned as a dev/user but rather keeping it in step with Windows.

biznatchio
Mar 31, 2001


Buglord
WinForms and WPF are dead ends. Don't let the fact they're still getting bug fixes fool you -- only getting bug fixes is the definition of being in "maintenance mode". All the dev love is behind the UWP platform now.

And to be honest, UWP isn't as god awful as it used to be. But even in the presence of roadmaps that only lead straight over a cliff I'd still say that, when it comes to making desktop apps for Windows, WinForms and WPF are still your best options.

biznatchio fucked around with this message at 22:05 on Jan 18, 2018

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
UWP is not for desktop apps, is it? It's for sandboxed store apps, right? That's the main thing stopping me

e: ... MFC then? :v:


That's what I found, too. It's not very promising that it seems to be a C# thing only

hackbunny fucked around with this message at 23:04 on Jan 18, 2018

beuges
Jul 4, 2005
fluffy bunny butterfly broomstick

hackbunny posted:

UWP is not for desktop apps, is it? It's for sandboxed store apps, right? That's the main thing stopping me

e: ... MFC then? :v:


That's what I found, too. It's not very promising that it seems to be a C# thing only

UWP apps can run on the desktop, they're not limited to phones only, but they're meant to be distributed via the store, not as standalone software. If your users are not likely to want to use the store, that's going to be a big factor. edit: also, UWP apps will limit you to running on Win10.


Non-nullable objects in C#8 is entirely a set of compiler rules - it doesn't affect the generated IL at all. So it's not a feature of .net itself, it's just the C# compiler getting cleverer/stricter. I guess the same rules could be built into the VB.net compiler as well, although I'm not sure why anyone would want to start a new .net project in VB in the first place.

beuges fucked around with this message at 23:21 on Jan 18, 2018

mystes
May 31, 2006

beuges posted:

Non-nullable objects in C#8 is entirely a set of compiler rules - it doesn't affect the generated IL at all. So it's not a feature of .net itself, it's just the C# compiler getting cleverer/stricter.
Doesn't there have to be some sort of change to the output if it's supposed to be able to detect nullable annotations in libraries?

LongSack
Jan 17, 2003

Funking Giblet posted:

Wonder what nameof does in this scenario :D

Just a guess, but if you have
C# code:
public void Foo(string bar)
{
    var n = nameof(bar);
}
That n would be set to “bar”. Dunno, I’ve never come across a need to use nameof, so I don’t really know how it works. :shrug:

Although, now I’m curious what nameof(“string”) or nameof((object)”string”) would return ...

raminasi
Jan 25, 2005

a last drink with no ice

beuges posted:

UWP apps can run on the desktop, they're not limited to phones only, but they're meant to be distributed via the store, not as standalone software. If your users are not likely to want to use the store, that's going to be a big factor. edit: also, UWP apps will limit you to running on Win10.

Aren't UWP apps stuck inside a sandbox? Like they can't (for example) touch the greater filesystem?

Night Shade
Jan 13, 2013

Old School

LongSack posted:

Although, now I’m curious what nameof(“string”) or nameof((object)”string”) would return ...

CS8081, apparently.

downout
Jul 6, 2009

Night Shade posted:

CS8081, apparently.



Well that is one solution if performance isn't a huge concern - to a nameof check and catch the exception.

Night Shade
Jan 13, 2013

Old School
That's a compiler error, not an exception. nameof(thing) is replaced with a string constant by the compiler. It's got some smarts in there about taking the last identifier in a dotted path of identifiers, so nameof(System.Object.ToString) gets replaced with "ToString", but it doesn't work on literals or anything that needs to be evaluated at runtime.

It also doesn't work how you may think for generic type parameters - nameof(TKey) is always "TKey", not typeof(TKey).Name. It basically exists to give refactoring tools something they can guarantee needs to be updated instead of guessing that "MyFunction" and void MyFunction() are the same thing.

downout
Jul 6, 2009

Night Shade posted:

That's a compiler error, not an exception. nameof(thing) is replaced with a string constant by the compiler. It's got some smarts in there about taking the last identifier in a dotted path of identifiers, so nameof(System.Object.ToString) gets replaced with "ToString", but it doesn't work on literals or anything that needs to be evaluated at runtime.

It also doesn't work how you may think for generic type parameters - nameof(TKey) is always "TKey", not typeof(TKey).Name. It basically exists to give refactoring tools something they can guarantee needs to be updated instead of guessing that "MyFunction" and void MyFunction() are the same thing.

I was just realizing that. Everything else I tested suggested that for "string"' and var str = "string", the literal and variable are treated identically by the compiler.

roflsaurus
Jun 5, 2004

GAOooooooh!! RAOR!!!
What's the best way to do non-trivial validation on domain model entities in ASP.Net MVC Core MVVM? MVC has great auto-validation for ViewModels, but not if your domain models aren't going through the model binding process

I have set up view models which can be validated from the DataAnnotations. But then with domain models I want to do some further checking - e.g.

  • check if a record already exists with that unique key and show a friendly error
  • check if an IP Address range is valid syntax
  • if property X is set, then property Y must be set

At the moment I'm doing it in the controller and it doesn't feel right. It seems EF Core have washed their hands of validation entirely (doesn't even check for duplicate PKs - just throws an SQL Exception)

I can use FluentValidation or some other kind of library, but it seems this still relies on the controller performing the validation (instead of validating on DbContext.Save). This won't work if I don't trust the UI layer. Ideally i'd call DbContext.Save, which would then call a custom Validate() function on my domain object. It could then return a list of DbValidationErrors or similar which I can bubble up to a UI / API. Am I missing something?

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

beuges posted:

UWP apps can run on the desktop, they're not limited to phones only, but they're meant to be distributed via the store, not as standalone software. If your users are not likely to want to use the store, that's going to be a big factor. edit: also, UWP apps will limit you to running on Win10.

By "desktop app" I mean classic Windows apps, using the terminology used to describe them in the Windows UI

beuges posted:

Non-nullable objects in C#8 is entirely a set of compiler rules - it doesn't affect the generated IL at all. So it's not a feature of .net itself, it's just the C# compiler getting cleverer/stricter. I guess the same rules could be built into the VB.net compiler as well, although I'm not sure why anyone would want to start a new .net project in VB in the first place.

What he said:

mystes posted:

Doesn't there have to be some sort of change to the output if it's supposed to be able to detect nullable annotations in libraries?

For example, Java has no official nullable/non-nullable attribute either, but there are many unofficial ones, like android.support.annotation.NonNull, recognized and honored by other JVM languages with non-null-by-default semantics (like Kotlin)

raminasi posted:

Aren't UWP apps stuck inside a sandbox? Like they can't (for example) touch the greater filesystem?

It would actually be preferrable to sandbox our app... but I'm afraid of the impact it would have on our third party dependencies. UWP also bans certain Win32 functions, right?

TheBlackVegetable
Oct 29, 2006

hackbunny posted:

Another question: correct me if I'm wrong, but .NET still doesn't have a standard way to specify/suggest that a return value or argument can't be null, right? There's Nullable to make value types nullable, but nothing to make reference types non-nullable? [and what's taking them so long?]

.NET does, it's called F#.

But yeah, C# will copy that eventually too.

Also, WPF might be dead, but it still works fine for Windows apps (and it's far better than winforms)

TheBlackVegetable fucked around with this message at 12:11 on Jan 19, 2018

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

TheBlackVegetable posted:

.NET does, it's called F#.

It's the existence of F# that made me hope there was a standard or standard-ish set of attributes I could annotate stuff with. But, no. At least, nothing language-agnostic

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



roflsaurus posted:

What's the best way to do non-trivial validation on domain model entities in ASP.Net MVC Core MVVM? MVC has great auto-validation for ViewModels, but not if your domain models aren't going through the model binding process

I have set up view models which can be validated from the DataAnnotations. But then with domain models I want to do some further checking - e.g.

  • check if a record already exists with that unique key and show a friendly error
  • check if an IP Address range is valid syntax
  • if property X is set, then property Y must be set

At the moment I'm doing it in the controller and it doesn't feel right. It seems EF Core have washed their hands of validation entirely (doesn't even check for duplicate PKs - just throws an SQL Exception)

I can use FluentValidation or some other kind of library, but it seems this still relies on the controller performing the validation (instead of validating on DbContext.Save). This won't work if I don't trust the UI layer. Ideally i'd call DbContext.Save, which would then call a custom Validate() function on my domain object. It could then return a list of DbValidationErrors or similar which I can bubble up to a UI / API. Am I missing something?

I'm confused: why can't you trust your controllers?

Anyway, you could make your own DbContext that overrides the base Save method with one that calls Validate, I guess.

hackbunny posted:

It's the existence of F# that made me hope there was a standard or standard-ish set of attributes I could annotate stuff with. But, no. At least, nothing language-agnostic

I didn't know you could do stuff like that with annotations in Java but .Net would probably do it with a wrapper type. int? is just sugar for Nullable<int>, for example.

https://fsharpforfunandprofit.com/posts/fsharp-decompiled/ is an interesting look at how F# types look translted into C#

B-Nasty
May 25, 2005

nameof is particularly useful for ArgumentNullExceptions where you don't have to worry about your function parameter names deviating from the magic strings. e.g.

code:

private void MyFunc(string fizzBuzz){
    if(fizzBuzz == null)
        throw new ArgumentNullException(nameof(fizzBuzz), "Nulls not allowed, you dummy");
}

That way, when someone changes fizzBuzz to fizzBuzzBazz, the compiler freaks out instead of that exception always being confusing. That and property change events are about the only practical uses I've had.

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



B-Nasty posted:

nameof is particularly useful for ArgumentNullExceptions where you don't have to worry about your function parameter names deviating from the magic strings. e.g.

code:

private void MyFunc(string fizzBuzz){
    if(fizzBuzz == null)
        throw new ArgumentNullException(nameof(fizzBuzz), "Nulls not allowed, you dummy");
}

That way, when someone changes fizzBuzz to fizzBuzzBazz, the compiler freaks out instead of that exception always being confusing. That and property change events are about the only practical uses I've had.

I thought it was originally added to make observables less annoying to maintain.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply