I’m not a fan of creating extension methods that assume a string of a specific kind of string, such as a url or file path.


The worst was last year’s:
public static T To<T>(this string json) => JsonConvert.DeserializeObject<T>(json, JsonSettings.SerializerDefaults);
Assumes a string is JSON!
public static string ToCurrency(this double value, string cultureName)
God help you if you’re using doubles or floats for currency.
You’re better off just using decimal, even if that’s still wrong you at least preserve that they’re actually decimal values.
The whole point of flag enums is that you don’t need a list :/ You pick values of 1, 2, 4, 8, 16, 32, … because the underlying bits don’t conflict.
PermissionEnum value = PermissionEnum.Create | PermissionEnum.View | PermissionEnum.Update |PermissionEnum.Delete
This is a perfectly valid variable given the values of each enum label
Yeah, no.
I consider this to be namespace pollution. Don’t put extension methods for specific purposes on general types. 🙁
On top of that, these don’t seem that useful even for specific purposes. How is new[] { PermissionEnum.Create, PermissionEnum.View, PermissionEnum.Update, PermissionEnum.Delete }.GetFlagSum<PermissionEnum>() even any better than PermissionEnum.Create | PermissionEnum.View | PermissionEnum.Update | PermissionEnum.Delete?
Please don’t do any of this..
I’m going to be honest these all suck.
I think probably the LoadFile one made me angriest.
I would use string builder in Repeat() method. Nice read.
That would mean it’s a semi-decent method instead of a disaster like the rest of them.
Also laughs in python even if I think str * int is goofy as hell.
This approach is very bad. Don’t do it.
What’s nice about having 100 unrelated (extension) methods on a type like System.String? This is against all modern programming principles… but also to common sense to be honest. It’s not even practical.
C# devs
null reference exceptions

source