Skip to content

Instantly share code, notes, and snippets.

@emoacht
Created June 5, 2022 14:01
Show Gist options
  • Save emoacht/ac77ee791f8324015d74c3a4a83320d3 to your computer and use it in GitHub Desktop.
Save emoacht/ac77ee791f8324015d74c3a4a83320d3 to your computer and use it in GitHub Desktop.
MarkupExtension to construct an array
[MarkupExtensionReturnType(typeof(object[]))]
public class ArrayConstructorExtension : MarkupExtension
{
private readonly object[] _elements;
public ArrayConstructorExtension(object a) => _elements = new[] { a };
public ArrayConstructorExtension(object a, object b) => _elements = new[] { a, b };
public ArrayConstructorExtension(object a, object b, object c) => _elements = new[] { a, b, c };
public ArrayConstructorExtension(object a, object b, object c, object d) => _elements = new[] { a, b, c, d };
public ArrayConstructorExtension(object a, object b, object c, object d, object e) => _elements = new[] { a, b, c, d, e };
public override object ProvideValue(IServiceProvider serviceProvider)
{
return _elements;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment