Everyone wanna see more toolkit video's? I do. James you curly haired code angel keep it up, this is something I am really interested as a newby dev. ❤
Hey, James! Thank you so much for these videos talking about features of dotNet Community Toolkit that I've never think about it. It's so helpful!!! Please, keep going! Thank you!
I'm having flashbacks to 'Code Contracts', where you could replace simple null argument checks with syntactical nightmare spaghetti nonsense and call yourself a hero. The bonus is if you did not have code contracts installed and unwittingly tried to compile the app without it, you got bizarre exceptions that were practically impossible to figure out. (Shiver) This seems a lot better. I look forward to trying it out!
I appreciate all the nice tools that the CommunityToolkit comes with and I certainly will check this one out as well. However, the helper methods of Guard seem a lot like syntactic sugar, because I could have my own set of static helper methods doing exactly that.
I love those gaurd method but my problem is that sometime we don't need to throw error but just return from function without working there. so maybe there is some setting like Guard.ThrowExceptionOrReturn =true or false and it respond accordingly.
This is an interesting approach, and does save some code, but I am surprised the toolkit does not use method attributes or method parameter attributes, like web api uses to validate parameters.
This library is a proof that direction in which developers are heading is completely wrong. Not sure whos fault is that but MS had Code Contracts for exactly this thing (and more). Why we fallback to checking things at runtime instead of compile time is beyond my understanding. At lest for nulls, if you use C# 8.0 or above don't use these guards, use C# language.
Code contracts was a good idea in principle. A major problem was that it usef IL rewrite though, which completely broke edit-and-continue, and would have broken hot reload had that existed at the time. I tried using it once, but once I started using it in one place, I had to use it for all the code that used the class I implemented it in first, then all classes and methods that used it and so on. It became a mess. It was before I had started to use source control, so cleaning it up was a pain. It would be cool if they brought some of it back, since the possibilities it brought seemed nice. Such as static source verification etc.
@@phizc actually I agree on code contracts, I used it a bit, to test, but it didn't turn well, as code contracts were mostly slow, static checker was too slow. But, referring to code contracts is to show that there is a way, code contracts were more like a proof-of-concept, but it was clear that heading towards compile-time check instead of runtime check is way to go, but somehow this philosophy didn't prevail at least not in that level what cc were aiming. Hopefully new compilers will introduce new features (like non-null reference types we have now).
Everyone wanna see more toolkit video's? I do. James you curly haired code angel keep it up, this is something I am really interested as a newby dev. ❤
Hey, James! Thank you so much for these videos talking about features of dotNet Community Toolkit that I've never think about it. It's so helpful!!! Please, keep going! Thank you!
I'm having flashbacks to 'Code Contracts', where you could replace simple null argument checks with syntactical nightmare spaghetti nonsense and call yourself a hero. The bonus is if you did not have code contracts installed and unwittingly tried to compile the app without it, you got bizarre exceptions that were practically impossible to figure out. (Shiver)
This seems a lot better. I look forward to trying it out!
That looks good! In the past I've used the GuardClasses package by Ardalis, but I'll definitely going to check this one out as well.
This is the reason why I am looking your videos....very helpful ☺️
I appreciate all the nice tools that the CommunityToolkit comes with and I certainly will check this one out as well. However, the helper methods of Guard seem a lot like syntactic sugar, because I could have my own set of static helper methods doing exactly that.
love the community toolkit stuff keep them rolling!
Great video. I’d like to see how to suppress or use custom message with these methods
I've been wanting to find an alternative to the Ensure.That library, thanks so much for this. I can't see a way to define a custom message though
Thank you James
Thank You. The exception messages from Guard are limited to English?
Great stuff thanks buddy!!!!
I love those gaurd method but my problem is that sometime we don't need to throw error but just return from function without working there. so maybe there is some setting like Guard.ThrowExceptionOrReturn =true or false and it respond accordingly.
So well said, thx!
I had proposed something similar. Take a look at github.com/CommunityToolkit/dotnet/issues/144
This is an interesting approach, and does save some code, but I am surprised the toolkit does not use method attributes or method parameter attributes, like web api uses to validate parameters.
That will require to intercept the method calls and require to use reflection. DynamicProxy can be used to implement it.
Maybe now that source generators are a thing, we will start to see more of that
I think we can use this package in Blazor or other types of applications right?
Any .NET app!
Just amazing!
This library is a proof that direction in which developers are heading is completely wrong. Not sure whos fault is that but MS had Code Contracts for exactly this thing (and more). Why we fallback to checking things at runtime instead of compile time is beyond my understanding. At lest for nulls, if you use C# 8.0 or above don't use these guards, use C# language.
Code contracts was a good idea in principle. A major problem was that it usef IL rewrite though, which completely broke edit-and-continue, and would have broken hot reload had that existed at the time.
I tried using it once, but once I started using it in one place, I had to use it for all the code that used the class I implemented it in first, then all classes and methods that used it and so on. It became a mess. It was before I had started to use source control, so cleaning it up was a pain.
It would be cool if they brought some of it back, since the possibilities it brought seemed nice. Such as static source verification etc.
@@phizc actually I agree on code contracts, I used it a bit, to test, but it didn't turn well, as code contracts were mostly slow, static checker was too slow. But, referring to code contracts is to show that there is a way, code contracts were more like a proof-of-concept, but it was clear that heading towards compile-time check instead of runtime check is way to go, but somehow this philosophy didn't prevail at least not in that level what cc were aiming. Hopefully new compilers will introduce new features (like non-null reference types we have now).