blokyk
blokyk
CC#
Created by blokyk on 8/27/2023 in #help
✅ Disable IDE0046 (use conditional return) when throw is involved
Hello, I was wondering if there is any way to disable "Use conditional return" when half of the expression is a throw expression? I'm not too well-versed when it comes to fine-grained .editorconfig stuff... Example code:
if (arg > 5) // IDE0046: Use conditional return
throw new Exception("some long message");

return DoSomeStuff(arg);

// Code fix suggestion:
return arg > 5 ? throw new Exception(...) : DoSomeStuff(arg);
if (arg > 5) // IDE0046: Use conditional return
throw new Exception("some long message");

return DoSomeStuff(arg);

// Code fix suggestion:
return arg > 5 ? throw new Exception(...) : DoSomeStuff(arg);
5 replies
CC#
Created by blokyk on 8/10/2023 in #help
✅ Override (abstract) getter-only property with a setter
Hello! I was wondering if there is anyway to add a setter to an overridden getter-only property? Currently, I've tried the following:
public class Base {
public abstract int Count { get; }
}

public class Derived : Base {
// #1
public override int Count { get; set; } // CS0546: Cannot override because no 'set' accessor

// #2
// CS0106: The 'override' modifier is not valid for this item
// CS0538: 'Base' in explicit implementation is not an interface
override Base.Count => Count;
public new int Count { get; set; }
}
public class Base {
public abstract int Count { get; }
}

public class Derived : Base {
// #1
public override int Count { get; set; } // CS0546: Cannot override because no 'set' accessor

// #2
// CS0106: The 'override' modifier is not valid for this item
// CS0538: 'Base' in explicit implementation is not an interface
override Base.Count => Count;
public new int Count { get; set; }
}
I'd prefer avoiding a constructor, since the rest of my hierarchy uses required properties, and Derived is actually sub-classed elsewhere, so adding a constructor would make things a bit clunky...
13 replies
CC#
Created by blokyk on 2/3/2023 in #help
❔ Using net7 documentation while targeting netstandard2.0
This might be a bit of a dumb question, but is there anyway to make omnisharp/roslyn's tooltips use the xml docs from a newer version of .NET (like .NET 7) while targeting netstandard2.0? What about nullability annotations (although I'm pretty sure that one is impossible without dangerously messing with ref assemblies) ?
14 replies
CC#
Created by blokyk on 8/19/2022 in #help
Excluding record member from default equality comparison
When declaring a record, it seems that every instance field/property, no matter its accessibility, is included in the default equality implementation. Is there any way to exclude a specific member from it without having to manually write the implementation ? Sharplab link : https://sharplab.io/#v2:D4AQDABCCMB0CSB5A3AWAFAgMwQE4FMBjAe1wBMIAlACgEsA7AFwloBoppIBnASggG8MEYRAAOuWgDcAho3wQAYrQA2+ePQBmxCBrToAvkA=
1 replies