@NickAlexeev Lazy execution/Deferred Execution, you get a sperate reference but it works on the original object every time you enumerate on it and filters it.
IF you are smart and don't just take strangers on the internet for their word, I suggest an exercise, create an IEnumerable, preferably just a list going from 1 to 10, put a filter on it, say Val>5, print the result, Add 11 to the original list and then enumerate the filtered object
[HttpGet] public ActionResult<IEnumerable<Cars>> Get() { var result = _repository.GetAll(); if(result == null) { var message = "Cars List not found"; return NotFound(message); } return Ok(_repository.GetAll()); }
Yes you can use the GetValues method:
var values = Enum.GetValues(typeof(Foos));
Or the typed version:
var values = Enum.GetValues(typeof(Foos)).Cast<Foos>();
I long ago added a helper function to my private library for just such an occasion:
public static class EnumUtil {
public s...
Just combine that with intcastings and ToStrings and other black magic and you are read.
If I have an enum, say UnitOfMeasurementEnum, I can't add an extension method called GetValuesAndNames and call UnitOfMeasurementEnum.GetValuesAndNames(), because that would be a static method on the enum type.
@Wietlol you can't automate "getting from one place in the labrynth to another", which would be the meta-equivalent of writing a program that can write any program you want
That's what I dislike about static imports. A lot of times, a method name makes sense in the context of the type it's defined in, it's part of its full name.
With static import, you lose that context.
So yeah, Cos or Abs are meaningful enough without the Math prefix. But Parse? Not so much.
Literally, I have a static class that I use to avoid people touching my screen with their hands. You know they leave fingerprints and stuff I dislike so I load up the static class and they get a nice zap when they try to reach for it.
@AppleCiderYummy Nothing wrong with static methods. But you'll have to consider how to fit it with OOP concepts. Static methods are methods on a type, not an instance.
They're often abused when you say "oh, I just want everyone to be able to get to this method", which usually indicates that the writer doesn't have clear understanding of OO or any other methodologies, and this leads to tightly coupled code, dependencies that shouldn't be dependnecies and many other proven, known problems.
@AppleCiderYummy It's pretty new. Not generic constraints themselves, but specifically the ability to constrain a generic type parameter to be an enum type.
yep, I suppose you really only get into trouble when you try to use a static method which has a state or you try to make non-static methods work like static methods
On a serious note, for me static classes were very comfortable to use, then I used them and soon enough suffered the consequences. It's the kind of thing I learned by doing and not by actually reading somewhere.
@Neil Damn right I didn't, I came in this direction, not from. I started with Java and PHP, moved to C# and JS/jQuery, then eventually landed in no-man's code here.
Just don't abuse it. There are moments where it's fine, others when it's not. Generally you don't judge it by "Should I use static names here?" but rather "Is it gonna hurt me to make this static in exchange for the time I'll save thinking an actual way to do it?"
using a lot of static methods is considered a code smell - meaning it isn't necessarily bad by itself, but that it's usually an indicator of actual problems.
Like components that are too tightly coupled, static singletons that can't be replaced easily, methods used by too many components that grow to fit too many use-cases, etc.
The singleton pattern is a fully paid up member of the GoF's patterns book, but it lately seems rather orphaned by the developer world. I still use quite a lot of singletons, especially for factory classes, and while you have to be a bit careful about multithreading issues (like any class actuall...
If I have a dependency injection framework which injects a service, there's no problem with that service being a singleton - in fact, many of my services are singletons. But as far as its consumer it concerned, there's no difference in usage between a singleton and a multi-instance service.
For things like your EnumExtensions.GetNamesAndValues, static methods are usually just fine. These are entirely technical methods that revolve around the nitty-gritty mechanics of the type system and framework. You won't really have much cause to replace and switch it around.
But if, for instance, you had MyDataRepository.GetItems() as a static method used anywhere that needed that, you would be setting yourself up for trouble.
The service lifetime is already determined upon registration right? Do you know any frameworks where this can be configured in the parameter injection? Perhaps, like an attribute added to the service as parameter itself.
@Neil isn't DI meant to actually make this transparent? If I'm not mistaken you can simply register a new type and it should automagically choose for you later.
@Neil Not arbitrary, usually. The last one to be registered is the current one, which makes sense, because it allows you to override previous registrations, for instance in a unit test project.
Also, depending on the DI platform, multiple registrations of the same interface can be retrieved at runtime - say, resolving IEnumerable<IPlugin> to get all plugins registered, not just the last one.
I'm kind of imagining a situation where multiple registration of the same interface would be problematic, like, there would be a missing signature with its parameter.
@Neil Right, so how does DI eliminate this problem exactly? AFAIK you load the dependency lazily and wait there until someone calls you to use it, then you pick the one you need and call the caller to inject it.
@HéctorÁlvarez You provide general rules on how to select an implementation, and whatever class needs it, it doesn't have to perform any logic in that regard
> since often, you won't use an object where it is created and that's kind of the point of inheritance many times DI kind of eliminates that problem entirely
@Neil Yeah I always wonder if it was this kind of teaching that lead people to think "People have rights --> The right to stab and shoot other people dead, thanks literature teachers"
for example: LoginScreen - Username field: Max 20 characters - Password field: Contains alphanumeric characters with a minimum of 8 characters and maximum of 100 - ...
I was in a literature class where we were obliged to read this 19th century "fluid consciousness" crap that was hard to digest in under a week, and in the test, they asked what the name of the dog was.. and that would have been mentioned like, what.. once in its entirety..
It wasn't a major plotpoint whatsoever, but apparently it was supposed to just test the fact that we actually read it.. I read it and I didn't know that answer
We occasionally used to have "reading comprehension" tests at school. I couldn't understand why we did them or what the point of them was, because it was like...the answer is literally written on this piece of paper you've given us, what is this testing
@TomW I think you seriously underestimate the number of people who simply will not read unless forced, and will not understand what is written if not pushed.
It would have shaken my faith in reason itself as a pre-teenage child to have known what I know now, from work, about the reading ability of apparently fairly intelligent professional adults
I had lots of question like that, my teachers had the false belief that in order to make sure someone knew 100% of the concepts you had to know the details by heart.
@mr5 I hated history in high-school. The memorization of dates and events. And then I somehow stumbled into studying history for my BA and discovered how fascinating it is when taught properly.
I particularly recall my first test about plants when I was a kid, we just learned about the parts of plants, something as simple as leaves, roots, etc. and the first question was "Latin name of the common rose" implying the little brown boxes with pointless information were more important than actually knowing plants breathe CO2 and spit O2 out.
@AvnerShahar-Kashtan I am following this political scientist, who is natively Filipino but graduated somewhere in Netherlands. His use of dates&events on his writing is very fascinating. I am learning a lot on our history because of that.
Ok so I was going through this docs.microsoft.com/en-us/dotnet/csharp/programming-guide/…, If I understand correctly streaming would start pushing results while running the query in the background, but non streaming will wait for the query to complete and then make the results available, how is Except() in both and how to use the different versions of them??
@CaptainObvious Module actually makes more sense, because static classes aren't really classes, they're usually used as logical groupings of static methods - or, you know, modules.