79470407

Date: 2025-02-26 16:27:31
Score: 2
Natty:
Report link

Lacking reputation to upvote Michael Wagner's elegant answer, I offer a slight improvement.

public class PropertyCastExtension<T>(T value) : MarkupExtension
{
  [ConstructorArgument("value")]
  public T Value { get; } = value;

  public override object ProvideValue(IServiceProvider serviceProvider) => Value!;
}

[MarkupExtensionReturnType(typeof(int))]
public class IntExtension(int value) : PropertyCastExtension<int>(value) { }

[MarkupExtensionReturnType(typeof(double))]
public class DoubleExtension(double value) : PropertyCastExtension<double>(value) { }
Reasons:
  • Blacklisted phrase (0.5): upvote
  • RegEx Blacklisted phrase (1.5): reputation
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Jack Skate