Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Add copy constructor for IReadonlyTagHelperAttribute => TagHelperAttribute #492

@NTaylorMullen

Description

@NTaylorMullen

Today in a TagHelpers Process method you're unable to copy values from TagHelperContext.AllAttributes => TagHelperOutput effectively. Aka this results in an error:

public override void Process(TagHelperContext context, TagHelperOutput output)
{
    output.Attributes.Insert(0, context.AllAttributes[0]);
}

Because context.AllAttributes[0] is an IReadonlyTagHelperAttribute and output.Attributes.Insert only takes TagHelperAttributes (as expected). To make this work you need to re-create the TagHelperAttribute via`

var existingAttribute = context.AllAttributes[0];
var copiedAttribute = new TagHelperAttribute
{
    Name = existingAttribute.Name,
    Value = existingAttribute.Value,
    Minimized = existingAttribute.Minimized
};

It'd be nice to make this slightly easier by providing a semi-copy ctor for TagHelperAttribute so it can take in an IReadonlyTagHelperAttribute and construct itself accordingly. Would let us do:

var existingAttribute = context.AllAttributes[0];
var copiedAttribute = new TagHelperAttribute(existingAttribute);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions