Fix #1355 Make extension nodes check for their extensions

This commit is contained in:
Ryan Nowak 2017-06-06 13:54:54 -07:00
parent e05c697c58
commit 17800b6055
7 changed files with 101 additions and 0 deletions

View File

@ -38,7 +38,18 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions
throw new ArgumentNullException(nameof(target)); throw new ArgumentNullException(nameof(target));
} }
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var extension = target.GetExtension<IInjectDirectiveTargetExtension>(); var extension = target.GetExtension<IInjectDirectiveTargetExtension>();
if (extension == null)
{
context.ReportMissingExtension<IInjectDirectiveTargetExtension>();
return;
}
extension.WriteInjectProperty(context, this); extension.WriteInjectProperty(context, this);
} }
} }

View File

@ -28,6 +28,16 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)
{ {
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var extension = target.GetExtension<ITemplateTargetExtension>(); var extension = target.GetExtension<ITemplateTargetExtension>();
if (extension == null) if (extension == null)
{ {

View File

@ -29,7 +29,23 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)
{ {
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var extension = target.GetExtension<IPreallocatedAttributeTargetExtension>(); var extension = target.GetExtension<IPreallocatedAttributeTargetExtension>();
if (extension == null)
{
context.ReportMissingExtension<IPreallocatedAttributeTargetExtension>();
return;
}
extension.WriteAddPreallocatedTagHelperHtmlAttribute(context, this); extension.WriteAddPreallocatedTagHelperHtmlAttribute(context, this);
} }
} }

View File

@ -36,7 +36,23 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)
{ {
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var extension = target.GetExtension<IPreallocatedAttributeTargetExtension>(); var extension = target.GetExtension<IPreallocatedAttributeTargetExtension>();
if (extension == null)
{
context.ReportMissingExtension<IPreallocatedAttributeTargetExtension>();
return;
}
extension.WriteDeclarePreallocatedTagHelperAttribute(context, this); extension.WriteDeclarePreallocatedTagHelperAttribute(context, this);
} }
} }

View File

@ -36,7 +36,23 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)
{ {
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var extension = target.GetExtension<IPreallocatedAttributeTargetExtension>(); var extension = target.GetExtension<IPreallocatedAttributeTargetExtension>();
if (extension == null)
{
context.ReportMissingExtension<IPreallocatedAttributeTargetExtension>();
return;
}
extension.WriteDeclarePreallocatedTagHelperHtmlAttribute(context, this); extension.WriteDeclarePreallocatedTagHelperHtmlAttribute(context, this);
} }
} }

View File

@ -27,7 +27,23 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)
{ {
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var extension = target.GetExtension<IDesignTimeDirectiveTargetExtension>(); var extension = target.GetExtension<IDesignTimeDirectiveTargetExtension>();
if (extension == null)
{
context.ReportMissingExtension<IDesignTimeDirectiveTargetExtension>();
return;
}
extension.WriteDesignTimeDirective(context, this); extension.WriteDesignTimeDirective(context, this);
} }
} }

View File

@ -42,7 +42,23 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public override void WriteNode(CodeTarget target, CSharpRenderingContext context) public override void WriteNode(CodeTarget target, CSharpRenderingContext context)
{ {
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var extension = target.GetExtension<IPreallocatedAttributeTargetExtension>(); var extension = target.GetExtension<IPreallocatedAttributeTargetExtension>();
if (extension == null)
{
context.ReportMissingExtension<IPreallocatedAttributeTargetExtension>();
return;
}
extension.WriteSetPreallocatedTagHelperProperty(context, this); extension.WriteSetPreallocatedTagHelperProperty(context, this);
} }
} }