Replace NotNullAttribute with thrown exceptions

This commit is contained in:
Pranav K 2015-09-16 22:06:25 -07:00
parent 0376550f2d
commit 33a0f7a0db
24 changed files with 451 additions and 110 deletions

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -29,9 +29,14 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// <typeparam name="TAttribute">The <see cref="Attribute"/> type.</typeparam> /// <typeparam name="TAttribute">The <see cref="Attribute"/> type.</typeparam>
/// <param name="symbol">The <see cref="ISymbol"/> to find attributes on.</param> /// <param name="symbol">The <see cref="ISymbol"/> to find attributes on.</param>
/// <returns></returns> /// <returns></returns>
public static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>([NotNull] ISymbol symbol) public static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>(ISymbol symbol)
where TAttribute : Attribute where TAttribute : Attribute
{ {
if (symbol == null)
{
throw new ArgumentNullException(nameof(symbol));
}
var attributes = symbol.GetAttributes(); var attributes = symbol.GetAttributes();
if (attributes.Length > 0) if (attributes.Length > 0)
{ {

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.Precompilation namespace Microsoft.AspNet.Razor.Runtime.Precompilation
{ {
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// Initializes a new instance of <see cref="CodeAnalysisSymbolBasedPropertyInfo"/>. /// Initializes a new instance of <see cref="CodeAnalysisSymbolBasedPropertyInfo"/>.
/// </summary> /// </summary>
/// <param name="propertySymbol">The <see cref="IPropertySymbol"/>.</param> /// <param name="propertySymbol">The <see cref="IPropertySymbol"/>.</param>
public CodeAnalysisSymbolBasedPropertyInfo([NotNull] IPropertySymbol propertySymbol) public CodeAnalysisSymbolBasedPropertyInfo(IPropertySymbol propertySymbol)
{ {
if (propertySymbol == null)
{
throw new ArgumentNullException(nameof(propertySymbol));
}
_propertySymbol = propertySymbol; _propertySymbol = propertySymbol;
PropertyType = new CodeAnalysisSymbolBasedTypeInfo(_propertySymbol.Type); PropertyType = new CodeAnalysisSymbolBasedTypeInfo(_propertySymbol.Type);
} }

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -9,7 +9,6 @@ using System.Reflection;
using System.Text; using System.Text;
using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.Precompilation namespace Microsoft.AspNet.Razor.Runtime.Precompilation
{ {
@ -35,8 +34,13 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// Initializes a new instance of <see cref="CodeAnalysisSymbolBasedTypeInfo"/>. /// Initializes a new instance of <see cref="CodeAnalysisSymbolBasedTypeInfo"/>.
/// </summary> /// </summary>
/// <param name="propertySymbol">The <see cref="IPropertySymbol"/>.</param> /// <param name="propertySymbol">The <see cref="IPropertySymbol"/>.</param>
public CodeAnalysisSymbolBasedTypeInfo([NotNull] ITypeSymbol type) public CodeAnalysisSymbolBasedTypeInfo(ITypeSymbol type)
{ {
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
_type = type; _type = type;
_underlyingType = UnwrapArrayType(type); _underlyingType = UnwrapArrayType(type);
} }
@ -174,10 +178,10 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
ITypeSymbol sourceTypeSymbol, ITypeSymbol sourceTypeSymbol,
System.Reflection.TypeInfo targetTypeInfo) System.Reflection.TypeInfo targetTypeInfo)
{ {
return string.Equals( return string.Equals(
targetTypeInfo.FullName, targetTypeInfo.FullName,
GetFullName(sourceTypeSymbol), GetFullName(sourceTypeSymbol),
StringComparison.Ordinal); StringComparison.Ordinal);
} }
/// <summary> /// <summary>
@ -185,8 +189,13 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// </summary> /// </summary>
/// <param name="symbol">The <see cref="ITypeSymbol" /> to generate the name for.</param> /// <param name="symbol">The <see cref="ITypeSymbol" /> to generate the name for.</param>
/// <returns>The assembly qualified name.</returns> /// <returns>The assembly qualified name.</returns>
public static string GetAssemblyQualifiedName([NotNull] ITypeSymbol symbol) public static string GetAssemblyQualifiedName(ITypeSymbol symbol)
{ {
if (symbol == null)
{
throw new ArgumentNullException(nameof(symbol));
}
var builder = new StringBuilder(); var builder = new StringBuilder();
GetAssemblyQualifiedName(builder, symbol); GetAssemblyQualifiedName(builder, symbol);

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.Precompilation namespace Microsoft.AspNet.Razor.Runtime.Precompilation
{ {
@ -24,14 +23,24 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// Initializes a new instance of <see cref="PrecompilationTagHelperTypeResolver"/>. /// Initializes a new instance of <see cref="PrecompilationTagHelperTypeResolver"/>.
/// </summary> /// </summary>
/// <param name="compilation">The <see cref="Compilation"/>.</param> /// <param name="compilation">The <see cref="Compilation"/>.</param>
public PrecompilationTagHelperTypeResolver([NotNull] Compilation compilation) public PrecompilationTagHelperTypeResolver(Compilation compilation)
{ {
if (compilation == null)
{
throw new ArgumentNullException(nameof(compilation));
}
_compilation = compilation; _compilation = compilation;
} }
/// <inheritdoc /> /// <inheritdoc />
protected override IEnumerable<ITypeInfo> GetTopLevelExportedTypes([NotNull] AssemblyName assemblyName) protected override IEnumerable<ITypeInfo> GetTopLevelExportedTypes(AssemblyName assemblyName)
{ {
if (assemblyName == null)
{
throw new ArgumentNullException(nameof(assemblyName));
}
lock (_assemblyLookupLock) lock (_assemblyLookupLock)
{ {
IEnumerable<ITypeInfo> result; IEnumerable<ITypeInfo> result;

View File

@ -9,10 +9,6 @@
"warningsAsErrors": true "warningsAsErrors": true
}, },
"dependencies": { "dependencies": {
"Microsoft.Framework.NotNullAttribute.Sources": {
"version": "1.0.0-*",
"type": "build"
},
"Microsoft.Framework.PropertyActivator.Sources": { "Microsoft.Framework.PropertyActivator.Sources": {
"version": "1.0.0-*", "version": "1.0.0-*",
"type": "build" "type": "build"

View File

@ -132,72 +132,132 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
public override TagHelperContent AppendFormat([NotNull] string format, object arg0) public override TagHelperContent AppendFormat(string format, object arg0)
{ {
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
Buffer.Append(string.Format(format, arg0)); Buffer.Append(string.Format(format, arg0));
return this; return this;
} }
/// <inheritdoc /> /// <inheritdoc />
public override TagHelperContent AppendFormat([NotNull] string format, object arg0, object arg1) public override TagHelperContent AppendFormat(string format, object arg0, object arg1)
{ {
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
Buffer.Append(string.Format(format, arg0, arg1)); Buffer.Append(string.Format(format, arg0, arg1));
return this; return this;
} }
/// <inheritdoc /> /// <inheritdoc />
public override TagHelperContent AppendFormat([NotNull] string format, object arg0, object arg1, object arg2) public override TagHelperContent AppendFormat(string format, object arg0, object arg1, object arg2)
{ {
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
Buffer.Append(string.Format(format, arg0, arg1, arg2)); Buffer.Append(string.Format(format, arg0, arg1, arg2));
return this; return this;
} }
/// <inheritdoc /> /// <inheritdoc />
public override TagHelperContent AppendFormat([NotNull] string format, params object[] args) public override TagHelperContent AppendFormat(string format, params object[] args)
{ {
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
Buffer.Append(string.Format(format, args)); Buffer.Append(string.Format(format, args));
return this; return this;
} }
/// <inheritdoc /> /// <inheritdoc />
public override TagHelperContent AppendFormat( public override TagHelperContent AppendFormat(
[NotNull] IFormatProvider provider, IFormatProvider provider,
[NotNull] string format, string format,
object arg0) object arg0)
{ {
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
Buffer.Append(string.Format(provider, format, arg0)); Buffer.Append(string.Format(provider, format, arg0));
return this; return this;
} }
/// <inheritdoc /> /// <inheritdoc />
public override TagHelperContent AppendFormat( public override TagHelperContent AppendFormat(
[NotNull] IFormatProvider provider, IFormatProvider provider,
[NotNull] string format, string format,
object arg0, object arg0,
object arg1) object arg1)
{ {
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
Buffer.Append(string.Format(provider, format, arg0, arg1)); Buffer.Append(string.Format(provider, format, arg0, arg1));
return this; return this;
} }
/// <inheritdoc /> /// <inheritdoc />
public override TagHelperContent AppendFormat( public override TagHelperContent AppendFormat(
[NotNull] IFormatProvider provider, IFormatProvider provider,
[NotNull] string format, string format,
object arg0, object arg0,
object arg1, object arg1,
object arg2) object arg2)
{ {
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
Buffer.Append(string.Format(provider, format, arg0, arg1, arg2)); Buffer.Append(string.Format(provider, format, arg0, arg1, arg2));
return this; return this;
} }
/// <inheritdoc /> /// <inheritdoc />
public override TagHelperContent AppendFormat( public override TagHelperContent AppendFormat(
[NotNull] IFormatProvider provider, IFormatProvider provider,
[NotNull] string format, string format,
params object[] args) params object[] args)
{ {
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
Buffer.Append(string.Format(provider, format, args)); Buffer.Append(string.Format(provider, format, args));
return this; return this;
} }
@ -232,8 +292,18 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
public override void WriteTo([NotNull] TextWriter writer, [NotNull] IHtmlEncoder encoder) public override void WriteTo(TextWriter writer, IHtmlEncoder encoder)
{ {
if (writer == null)
{
throw new ArgumentNullException(nameof(writer));
}
if (encoder == null)
{
throw new ArgumentNullException(nameof(encoder));
}
Buffer.WriteTo(writer, encoder); Buffer.WriteTo(writer, encoder);
} }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -18,8 +17,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <param name="outputElement"> /// <param name="outputElement">
/// The HTML element the <see cref="ITagHelper"/> may output. /// The HTML element the <see cref="ITagHelper"/> may output.
/// </param> /// </param>
public OutputElementHintAttribute([NotNull] string outputElement) public OutputElementHintAttribute(string outputElement)
{ {
if (outputElement == null)
{
throw new ArgumentNullException(nameof(outputElement));
}
OutputElement = outputElement; OutputElement = outputElement;
} }

View File

@ -32,8 +32,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <paramref name="attributes"/>. /// <paramref name="attributes"/>.
/// </summary> /// </summary>
/// <param name="attributes">The collection to wrap.</param> /// <param name="attributes">The collection to wrap.</param>
public ReadOnlyTagHelperAttributeList([NotNull] IEnumerable<TAttribute> attributes) public ReadOnlyTagHelperAttributeList(IEnumerable<TAttribute> attributes)
{ {
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
Attributes = new List<TAttribute>(attributes); Attributes = new List<TAttribute>(attributes);
} }
@ -64,10 +69,15 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// matching <paramref name="name"/>. /// matching <paramref name="name"/>.
/// </returns> /// </returns>
/// <remarks><paramref name="name"/> is compared case-insensitively.</remarks> /// <remarks><paramref name="name"/> is compared case-insensitively.</remarks>
public TAttribute this[[NotNull] string name] public TAttribute this[string name]
{ {
get get
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return Attributes.FirstOrDefault(attribute => NameEquals(name, attribute)); return Attributes.FirstOrDefault(attribute => NameEquals(name, attribute));
} }
} }
@ -93,8 +103,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks> /// <remarks>
/// <paramref name="item"/>s <see cref="IReadOnlyTagHelperAttribute.Name"/> is compared case-insensitively. /// <paramref name="item"/>s <see cref="IReadOnlyTagHelperAttribute.Name"/> is compared case-insensitively.
/// </remarks> /// </remarks>
public bool Contains([NotNull] TAttribute item) public bool Contains(TAttribute item)
{ {
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}
return Attributes.Contains(item); return Attributes.Contains(item);
} }
@ -109,8 +124,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <see cref="IReadOnlyTagHelperAttribute.Name"/> exists in the collection; otherwise, <c>false</c>. /// <see cref="IReadOnlyTagHelperAttribute.Name"/> exists in the collection; otherwise, <c>false</c>.
/// </returns> /// </returns>
/// <remarks><paramref name="name"/> is compared case-insensitively.</remarks> /// <remarks><paramref name="name"/> is compared case-insensitively.</remarks>
public bool ContainsName([NotNull] string name) public bool ContainsName(string name)
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return Attributes.Any(attribute => NameEquals(name, attribute)); return Attributes.Any(attribute => NameEquals(name, attribute));
} }
@ -124,8 +144,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks> /// <remarks>
/// <paramref name="item"/>s <see cref="IReadOnlyTagHelperAttribute.Name"/> is compared case-insensitively. /// <paramref name="item"/>s <see cref="IReadOnlyTagHelperAttribute.Name"/> is compared case-insensitively.
/// </remarks> /// </remarks>
public int IndexOf([NotNull] TAttribute item) public int IndexOf(TAttribute item)
{ {
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}
return Attributes.IndexOf(item); return Attributes.IndexOf(item);
} }
@ -141,8 +166,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <returns><c>true</c> if a <typeparamref name="TAttribute"/> with the same /// <returns><c>true</c> if a <typeparamref name="TAttribute"/> with the same
/// <see cref="IReadOnlyTagHelperAttribute.Name"/> exists in the collection; otherwise, <c>false</c>.</returns> /// <see cref="IReadOnlyTagHelperAttribute.Name"/> exists in the collection; otherwise, <c>false</c>.</returns>
/// <remarks><paramref name="name"/> is compared case-insensitively.</remarks> /// <remarks><paramref name="name"/> is compared case-insensitively.</remarks>
public bool TryGetAttribute([NotNull] string name, out TAttribute attribute) public bool TryGetAttribute(string name, out TAttribute attribute)
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
attribute = Attributes.FirstOrDefault(attr => NameEquals(name, attr)); attribute = Attributes.FirstOrDefault(attr => NameEquals(name, attr));
return attribute != null; return attribute != null;
@ -160,8 +190,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <returns><c>true</c> if at least one <typeparamref name="TAttribute"/> with the same /// <returns><c>true</c> if at least one <typeparamref name="TAttribute"/> with the same
/// <see cref="IReadOnlyTagHelperAttribute.Name"/> exists in the collection; otherwise, <c>false</c>.</returns> /// <see cref="IReadOnlyTagHelperAttribute.Name"/> exists in the collection; otherwise, <c>false</c>.</returns>
/// <remarks><paramref name="name"/> is compared case-insensitively.</remarks> /// <remarks><paramref name="name"/> is compared case-insensitively.</remarks>
public bool TryGetAttributes([NotNull] string name, out IEnumerable<TAttribute> attributes) public bool TryGetAttributes(string name, out IEnumerable<TAttribute> attributes)
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
attributes = Attributes.Where(attribute => NameEquals(name, attribute)); attributes = Attributes.Where(attribute => NameEquals(name, attribute));
return attributes.Any(); return attributes.Any();
@ -187,8 +222,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <param name="attribute">The attribute to compare against.</param> /// <param name="attribute">The attribute to compare against.</param>
/// <returns><c>true</c> if <paramref name="name"/> case-insensitively matches <paramref name="attribute"/>s /// <returns><c>true</c> if <paramref name="name"/> case-insensitively matches <paramref name="attribute"/>s
/// <see cref="TagHelperAttribute.Name"/>.</returns> /// <see cref="TagHelperAttribute.Name"/>.</returns>
protected static bool NameEquals(string name, [NotNull] TAttribute attribute) protected static bool NameEquals(string name, TAttribute attribute)
{ {
if (attribute == null)
{
throw new ArgumentNullException(nameof(attribute));
}
return string.Equals(name, attribute.Name, StringComparison.OrdinalIgnoreCase); return string.Equals(name, attribute.Name, StringComparison.OrdinalIgnoreCase);
} }
} }

View File

@ -1,11 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime namespace Microsoft.AspNet.Razor.Runtime
{ {
@ -18,8 +17,13 @@ namespace Microsoft.AspNet.Razor.Runtime
/// Initializes a new instance of <see cref="RuntimePropertyInfo"/>. /// Initializes a new instance of <see cref="RuntimePropertyInfo"/>.
/// </summary> /// </summary>
/// <param name="propertyInfo">The <see cref="PropertyInfo"/> instance to adapt.</param> /// <param name="propertyInfo">The <see cref="PropertyInfo"/> instance to adapt.</param>
public RuntimePropertyInfo([NotNull] PropertyInfo propertyInfo) public RuntimePropertyInfo(PropertyInfo propertyInfo)
{ {
if (propertyInfo == null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
Property = propertyInfo; Property = propertyInfo;
} }

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -27,8 +27,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// Initializes a new instance of <see cref="RuntimeTypeInfo"/> /// Initializes a new instance of <see cref="RuntimeTypeInfo"/>
/// </summary> /// </summary>
/// <param name="propertyInfo">The <see cref="System.Reflection.TypeInfo"/> instance to adapt.</param> /// <param name="propertyInfo">The <see cref="System.Reflection.TypeInfo"/> instance to adapt.</param>
public RuntimeTypeInfo([NotNull] TypeInfo typeInfo) public RuntimeTypeInfo(TypeInfo typeInfo)
{ {
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
TypeInfo = typeInfo; TypeInfo = typeInfo;
} }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -25,9 +24,14 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <paramref name="attribute"/>. /// <paramref name="attribute"/>.
/// </summary> /// </summary>
/// <param name="attribute">A <see cref="IReadOnlyTagHelperAttribute"/> whose values should be copied.</param> /// <param name="attribute">A <see cref="IReadOnlyTagHelperAttribute"/> whose values should be copied.</param>
public TagHelperAttribute([NotNull] IReadOnlyTagHelperAttribute attribute) public TagHelperAttribute(IReadOnlyTagHelperAttribute attribute)
: this (attribute?.Name, attribute?.Value) : this(attribute?.Name, attribute?.Value)
{ {
if (attribute == null)
{
throw new ArgumentNullException(nameof(attribute));
}
Minimized = attribute.Minimized; Minimized = attribute.Minimized;
} }

View File

@ -25,9 +25,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <paramref name="attributes"/>. /// <paramref name="attributes"/>.
/// </summary> /// </summary>
/// <param name="attributes">The collection to wrap.</param> /// <param name="attributes">The collection to wrap.</param>
public TagHelperAttributeList([NotNull] IEnumerable<TagHelperAttribute> attributes) public TagHelperAttributeList(IEnumerable<TagHelperAttribute> attributes)
: base(attributes) : base(attributes)
{ {
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
} }
/// <inheritdoc /> /// <inheritdoc />
@ -40,9 +44,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
return base[index]; return base[index];
} }
[param: NotNull]
set set
{ {
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
if (value.Name == null) if (value.Name == null)
{ {
throw new ArgumentException( throw new ArgumentException(
@ -83,15 +91,29 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// attributes["name"] = new TagHelperAttribute("name", "value"); /// attributes["name"] = new TagHelperAttribute("name", "value");
/// </code> /// </code>
/// </example> /// </example>
public new TagHelperAttribute this[[NotNull] string name] public new TagHelperAttribute this[string name]
{ {
get get
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return base[name]; return base[name];
} }
[param: NotNull]
set set
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
// Name will be null if user attempts to set the attribute via an implicit conversion: // Name will be null if user attempts to set the attribute via an implicit conversion:
// output.Attributes["someName"] = "someValue" // output.Attributes["someName"] = "someValue"
if (value.Name == null) if (value.Name == null)
@ -152,8 +174,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </summary> /// </summary>
/// <param name="name">The <see cref="TagHelperAttribute.Name"/> of the attribute to add.</param> /// <param name="name">The <see cref="TagHelperAttribute.Name"/> of the attribute to add.</param>
/// <param name="value">The <see cref="TagHelperAttribute.Value"/> of the attribute to add.</param> /// <param name="value">The <see cref="TagHelperAttribute.Value"/> of the attribute to add.</param>
public void Add([NotNull] string name, object value) public void Add(string name, object value)
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
Attributes.Add(new TagHelperAttribute(name, value)); Attributes.Add(new TagHelperAttribute(name, value));
} }
@ -161,8 +188,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks> /// <remarks>
/// <paramref name="attribute"/>'s <see cref="TagHelperAttribute.Name"/> must not be <c>null</c>. /// <paramref name="attribute"/>'s <see cref="TagHelperAttribute.Name"/> must not be <c>null</c>.
/// </remarks> /// </remarks>
public void Add([NotNull] TagHelperAttribute attribute) public void Add(TagHelperAttribute attribute)
{ {
if (attribute == null)
{
throw new ArgumentNullException(nameof(attribute));
}
if (attribute.Name == null) if (attribute.Name == null)
{ {
throw new ArgumentException( throw new ArgumentException(
@ -179,8 +211,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks> /// <remarks>
/// <paramref name="attribute"/>'s <see cref="TagHelperAttribute.Name"/> must not be <c>null</c>. /// <paramref name="attribute"/>'s <see cref="TagHelperAttribute.Name"/> must not be <c>null</c>.
/// </remarks> /// </remarks>
public void Insert(int index, [NotNull] TagHelperAttribute attribute) public void Insert(int index, TagHelperAttribute attribute)
{ {
if (attribute == null)
{
throw new ArgumentNullException(nameof(attribute));
}
if (attribute.Name == null) if (attribute.Name == null)
{ {
throw new ArgumentException( throw new ArgumentException(
@ -194,8 +231,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
public void CopyTo([NotNull] TagHelperAttribute[] array, int index) public void CopyTo(TagHelperAttribute[] array, int index)
{ {
if (array == null)
{
throw new ArgumentNullException(nameof(array));
}
Attributes.CopyTo(array, index); Attributes.CopyTo(array, index);
} }
@ -203,8 +245,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks> /// <remarks>
/// <paramref name="attribute"/>s <see cref="TagHelperAttribute.Name"/> is compared case-insensitively. /// <paramref name="attribute"/>s <see cref="TagHelperAttribute.Name"/> is compared case-insensitively.
/// </remarks> /// </remarks>
public bool Remove([NotNull] TagHelperAttribute attribute) public bool Remove(TagHelperAttribute attribute)
{ {
if (attribute == null)
{
throw new ArgumentNullException(nameof(attribute));
}
return Attributes.Remove(attribute); return Attributes.Remove(attribute);
} }
@ -225,8 +272,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <c>true</c> if at least 1 <see cref="TagHelperAttribute"/> was removed; otherwise, <c>false</c>. /// <c>true</c> if at least 1 <see cref="TagHelperAttribute"/> was removed; otherwise, <c>false</c>.
/// </returns> /// </returns>
/// <remarks><paramref name="name"/> is compared case-insensitively.</remarks> /// <remarks><paramref name="name"/> is compared case-insensitively.</remarks>
public bool RemoveAll([NotNull] string name) public bool RemoveAll(string name)
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return Attributes.RemoveAll(attribute => NameEquals(name, attribute)) > 0; return Attributes.RemoveAll(attribute => NameEquals(name, attribute)) > 0;
} }

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -26,11 +25,31 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <param name="getChildContentAsync">A delegate used to execute and retrieve the rendered child content /// <param name="getChildContentAsync">A delegate used to execute and retrieve the rendered child content
/// asynchronously.</param> /// asynchronously.</param>
public TagHelperContext( public TagHelperContext(
[NotNull] IEnumerable<IReadOnlyTagHelperAttribute> allAttributes, IEnumerable<IReadOnlyTagHelperAttribute> allAttributes,
[NotNull] IDictionary<object, object> items, IDictionary<object, object> items,
[NotNull] string uniqueId, string uniqueId,
[NotNull] Func<bool, Task<TagHelperContent>> getChildContentAsync) Func<bool, Task<TagHelperContent>> getChildContentAsync)
{ {
if (allAttributes == null)
{
throw new ArgumentNullException(nameof(allAttributes));
}
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
if (uniqueId == null)
{
throw new ArgumentNullException(nameof(uniqueId));
}
if (getChildContentAsync == null)
{
throw new ArgumentNullException(nameof(getChildContentAsync));
}
AllAttributes = new ReadOnlyTagHelperAttributeList<IReadOnlyTagHelperAttribute>( AllAttributes = new ReadOnlyTagHelperAttributeList<IReadOnlyTagHelperAttribute>(
allAttributes.Select(attribute => new TagHelperAttribute(attribute.Name, attribute.Value))); allAttributes.Select(attribute => new TagHelperAttribute(attribute.Name, attribute.Value)));
Items = items; Items = items;

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -54,10 +53,20 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </returns> /// </returns>
public static IEnumerable<TagHelperDescriptor> CreateDescriptors( public static IEnumerable<TagHelperDescriptor> CreateDescriptors(
string assemblyName, string assemblyName,
[NotNull] ITypeInfo typeInfo, ITypeInfo typeInfo,
bool designTime, bool designTime,
[NotNull] ErrorSink errorSink) ErrorSink errorSink)
{ {
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
if (ShouldSkipDescriptorCreation(designTime, typeInfo)) if (ShouldSkipDescriptorCreation(designTime, typeInfo))
{ {
return Enumerable.Empty<TagHelperDescriptor>(); return Enumerable.Empty<TagHelperDescriptor>();

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.AspNet.Razor.Parser; using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -52,8 +51,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
public IEnumerable<TagHelperDescriptor> Resolve([NotNull] TagHelperDescriptorResolutionContext context) public IEnumerable<TagHelperDescriptor> Resolve(TagHelperDescriptorResolutionContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var resolvedDescriptors = new HashSet<TagHelperDescriptor>(TagHelperDescriptorComparer.Default); var resolvedDescriptors = new HashSet<TagHelperDescriptor>(TagHelperDescriptorComparer.Default);
// tagHelperPrefix directives do not affect which TagHelperDescriptors are added or removed from the final // tagHelperPrefix directives do not affect which TagHelperDescriptors are added or removed from the final

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if !DNXCORE50 // Cannot accurately resolve the location of the documentation XML file in coreclr. #if !DNXCORE50 // Cannot accurately resolve the location of the documentation XML file in coreclr.
@ -9,7 +9,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Razor.TagHelpers; using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -27,8 +26,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </param> /// </param>
/// <returns>A <see cref="TagHelperDesignTimeDescriptor"/> that describes design time specific information /// <returns>A <see cref="TagHelperDesignTimeDescriptor"/> that describes design time specific information
/// for the given <paramref name="type"/>.</returns> /// for the given <paramref name="type"/>.</returns>
public static TagHelperDesignTimeDescriptor CreateDescriptor([NotNull] Type type) public static TagHelperDesignTimeDescriptor CreateDescriptor(Type type)
{ {
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
var id = XmlDocumentationProvider.GetId(type); var id = XmlDocumentationProvider.GetId(type);
var documentationDescriptor = CreateDocumentationDescriptor(type.Assembly, id); var documentationDescriptor = CreateDocumentationDescriptor(type.Assembly, id);
@ -62,8 +66,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <returns>A <see cref="TagHelperAttributeDesignTimeDescriptor"/> that describes design time specific /// <returns>A <see cref="TagHelperAttributeDesignTimeDescriptor"/> that describes design time specific
/// information for the given <paramref name="propertyInfo"/>.</returns> /// information for the given <paramref name="propertyInfo"/>.</returns>
public static TagHelperAttributeDesignTimeDescriptor CreateAttributeDescriptor( public static TagHelperAttributeDesignTimeDescriptor CreateAttributeDescriptor(
[NotNull] PropertyInfo propertyInfo) PropertyInfo propertyInfo)
{ {
if (propertyInfo == null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
var id = XmlDocumentationProvider.GetId(propertyInfo); var id = XmlDocumentationProvider.GetId(propertyInfo);
var declaringAssembly = propertyInfo.DeclaringType.Assembly; var declaringAssembly = propertyInfo.DeclaringType.Assembly;
var documentationDescriptor = CreateDocumentationDescriptor(declaringAssembly, id); var documentationDescriptor = CreateDocumentationDescriptor(declaringAssembly, id);

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -45,14 +44,44 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <param name="startTagHelperWritingScope">A delegate used to start a writing scope in a Razor page.</param> /// <param name="startTagHelperWritingScope">A delegate used to start a writing scope in a Razor page.</param>
/// <param name="endTagHelperWritingScope">A delegate used to end a writing scope in a Razor page.</param> /// <param name="endTagHelperWritingScope">A delegate used to end a writing scope in a Razor page.</param>
public TagHelperExecutionContext( public TagHelperExecutionContext(
[NotNull] string tagName, string tagName,
TagMode tagMode, TagMode tagMode,
[NotNull] IDictionary<object, object> items, IDictionary<object, object> items,
[NotNull] string uniqueId, string uniqueId,
[NotNull] Func<Task> executeChildContentAsync, Func<Task> executeChildContentAsync,
[NotNull] Action startTagHelperWritingScope, Action startTagHelperWritingScope,
[NotNull] Func<TagHelperContent> endTagHelperWritingScope) Func<TagHelperContent> endTagHelperWritingScope)
{ {
if (tagName == null)
{
throw new ArgumentNullException(nameof(tagName));
}
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
if (uniqueId == null)
{
throw new ArgumentNullException(nameof(uniqueId));
}
if (executeChildContentAsync == null)
{
throw new ArgumentNullException(nameof(executeChildContentAsync));
}
if (startTagHelperWritingScope == null)
{
throw new ArgumentNullException(nameof(startTagHelperWritingScope));
}
if (endTagHelperWritingScope == null)
{
throw new ArgumentNullException(nameof(endTagHelperWritingScope));
}
_tagHelpers = new List<ITagHelper>(); _tagHelpers = new List<ITagHelper>();
_executeChildContentAsync = executeChildContentAsync; _executeChildContentAsync = executeChildContentAsync;
_startTagHelperWritingScope = startTagHelperWritingScope; _startTagHelperWritingScope = startTagHelperWritingScope;
@ -127,8 +156,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// Tracks the given <paramref name="tagHelper"/>. /// Tracks the given <paramref name="tagHelper"/>.
/// </summary> /// </summary>
/// <param name="tagHelper">The tag helper to track.</param> /// <param name="tagHelper">The tag helper to track.</param>
public void Add([NotNull] ITagHelper tagHelper) public void Add(ITagHelper tagHelper)
{ {
if (tagHelper == null)
{
throw new ArgumentNullException(nameof(tagHelper));
}
_tagHelpers.Add(tagHelper); _tagHelpers.Add(tagHelper);
} }
@ -136,8 +170,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// Tracks the minimized HTML attribute in <see cref="AllAttributes"/> and <see cref="HTMLAttributes"/>. /// Tracks the minimized HTML attribute in <see cref="AllAttributes"/> and <see cref="HTMLAttributes"/>.
/// </summary> /// </summary>
/// <param name="name">The minimized HTML attribute name.</param> /// <param name="name">The minimized HTML attribute name.</param>
public void AddMinimizedHtmlAttribute([NotNull] string name) public void AddMinimizedHtmlAttribute(string name)
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
HTMLAttributes.Add( HTMLAttributes.Add(
new TagHelperAttribute new TagHelperAttribute
{ {
@ -157,8 +196,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </summary> /// </summary>
/// <param name="name">The HTML attribute name.</param> /// <param name="name">The HTML attribute name.</param>
/// <param name="value">The HTML attribute value.</param> /// <param name="value">The HTML attribute value.</param>
public void AddHtmlAttribute([NotNull] string name, object value) public void AddHtmlAttribute(string name, object value)
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
HTMLAttributes.Add(name, value); HTMLAttributes.Add(name, value);
AllAttributes.Add(name, value); AllAttributes.Add(name, value);
} }
@ -168,8 +212,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </summary> /// </summary>
/// <param name="name">The bound attribute name.</param> /// <param name="name">The bound attribute name.</param>
/// <param name="value">The attribute value.</param> /// <param name="value">The attribute value.</param>
public void AddTagHelperAttribute([NotNull] string name, object value) public void AddTagHelperAttribute(string name, object value)
{ {
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
AllAttributes.Add(name, value); AllAttributes.Add(name, value);
} }

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -23,8 +23,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <param name="attributes">The HTML attributes.</param> /// <param name="attributes">The HTML attributes.</param>
public TagHelperOutput( public TagHelperOutput(
string tagName, string tagName,
[NotNull] TagHelperAttributeList attributes) TagHelperAttributeList attributes)
{ {
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
TagName = tagName; TagName = tagName;
Attributes = new TagHelperAttributeList(attributes); Attributes = new TagHelperAttributeList(attributes);
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -19,8 +19,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </param> /// </param>
/// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the /// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the
/// <paramref name="executionContext"/>'s <see cref="ITagHelper"/>s.</returns> /// <paramref name="executionContext"/>'s <see cref="ITagHelper"/>s.</returns>
public async Task<TagHelperOutput> RunAsync([NotNull] TagHelperExecutionContext executionContext) public async Task<TagHelperOutput> RunAsync(TagHelperExecutionContext executionContext)
{ {
if (executionContext == null)
{
throw new ArgumentNullException(nameof(executionContext));
}
var tagHelperContext = new TagHelperContext( var tagHelperContext = new TagHelperContext(
executionContext.AllAttributes, executionContext.AllAttributes,
executionContext.Items, executionContext.Items,

View File

@ -34,13 +34,38 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <param name="endTagHelperWritingScope">A delegate used to end a writing scope in a Razor page.</param> /// <param name="endTagHelperWritingScope">A delegate used to end a writing scope in a Razor page.</param>
/// <returns>A <see cref="TagHelperExecutionContext"/> to use.</returns> /// <returns>A <see cref="TagHelperExecutionContext"/> to use.</returns>
public TagHelperExecutionContext Begin( public TagHelperExecutionContext Begin(
[NotNull] string tagName, string tagName,
TagMode tagMode, TagMode tagMode,
[NotNull] string uniqueId, string uniqueId,
[NotNull] Func<Task> executeChildContentAsync, Func<Task> executeChildContentAsync,
[NotNull] Action startTagHelperWritingScope, Action startTagHelperWritingScope,
[NotNull] Func<TagHelperContent> endTagHelperWritingScope) Func<TagHelperContent> endTagHelperWritingScope)
{ {
if (tagName == null)
{
throw new ArgumentNullException(nameof(tagName));
}
if (uniqueId == null)
{
throw new ArgumentNullException(nameof(uniqueId));
}
if (executeChildContentAsync == null)
{
throw new ArgumentNullException(nameof(executeChildContentAsync));
}
if (startTagHelperWritingScope == null)
{
throw new ArgumentNullException(nameof(startTagHelperWritingScope));
}
if (endTagHelperWritingScope == null)
{
throw new ArgumentNullException(nameof(endTagHelperWritingScope));
}
IDictionary<object, object> items; IDictionary<object, object> items;
// If we're not wrapped by another TagHelper, then there will not be a parentExecutionContext. // If we're not wrapped by another TagHelper, then there will not be a parentExecutionContext.

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{ {
@ -29,8 +28,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
public IEnumerable<ITypeInfo> Resolve( public IEnumerable<ITypeInfo> Resolve(
string name, string name,
SourceLocation documentLocation, SourceLocation documentLocation,
[NotNull] ErrorSink errorSink) ErrorSink errorSink)
{ {
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
{ {
var errorLength = name == null ? 1 : Math.Max(name.Length, 1); var errorLength = name == null ? 1 : Math.Max(name.Length, 1);
@ -71,8 +75,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <returns> /// <returns>
/// An <see cref="IEnumerable{ITypeInfo}"/> of types exported from the given <paramref name="assemblyName"/>. /// An <see cref="IEnumerable{ITypeInfo}"/> of types exported from the given <paramref name="assemblyName"/>.
/// </returns> /// </returns>
protected virtual IEnumerable<ITypeInfo> GetTopLevelExportedTypes([NotNull] AssemblyName assemblyName) protected virtual IEnumerable<ITypeInfo> GetTopLevelExportedTypes(AssemblyName assemblyName)
{ {
if (assemblyName == null)
{
throw new ArgumentNullException(nameof(assemblyName));
}
var exportedTypeInfos = GetExportedTypes(assemblyName); var exportedTypeInfos = GetExportedTypes(assemblyName);
return exportedTypeInfos return exportedTypeInfos

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if !DNXCORE50 #if !DNXCORE50
@ -8,7 +8,6 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime namespace Microsoft.AspNet.Razor.Runtime
{ {
@ -76,8 +75,13 @@ namespace Microsoft.AspNet.Razor.Runtime
/// </summary> /// </summary>
/// <param name="type">The <see cref="Type"/> to get the identifier for.</param> /// <param name="type">The <see cref="Type"/> to get the identifier for.</param>
/// <returns>The <see cref="string"/> identifier for the given <paramref name="type"/>.</returns> /// <returns>The <see cref="string"/> identifier for the given <paramref name="type"/>.</returns>
public static string GetId([NotNull] Type type) public static string GetId(Type type)
{ {
if (type == null)
{
throw new ArgumentNullException(nameof(type));
}
return $"T:{type.FullName}"; return $"T:{type.FullName}";
} }
@ -86,8 +90,13 @@ namespace Microsoft.AspNet.Razor.Runtime
/// </summary> /// </summary>
/// <param name="propertyInfo">The <see cref="PropertyInfo"/> to get the identifier for.</param> /// <param name="propertyInfo">The <see cref="PropertyInfo"/> to get the identifier for.</param>
/// <returns>The <see cref="string"/> identifier for the given <paramref name="propertyInfo"/>.</returns> /// <returns>The <see cref="string"/> identifier for the given <paramref name="propertyInfo"/>.</returns>
public static string GetId([NotNull] PropertyInfo propertyInfo) public static string GetId(PropertyInfo propertyInfo)
{ {
if (propertyInfo == null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
var declaringTypeInfo = propertyInfo.DeclaringType; var declaringTypeInfo = propertyInfo.DeclaringType;
return $"P:{declaringTypeInfo.FullName}.{propertyInfo.Name}"; return $"P:{declaringTypeInfo.FullName}.{propertyInfo.Name}";
} }

View File

@ -19,10 +19,6 @@
"Microsoft.Framework.CopyOnWriteDictionary.Sources": { "Microsoft.Framework.CopyOnWriteDictionary.Sources": {
"type": "build", "type": "build",
"version": "1.0.0-*" "version": "1.0.0-*"
},
"Microsoft.Framework.NotNullAttribute.Sources": {
"type": "build",
"version": "1.0.0-*"
} }
}, },
"frameworks": { "frameworks": {

View File

@ -58,7 +58,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
var executionContext = new TagHelperExecutionContext( var executionContext = new TagHelperExecutionContext(
"p", "p",
tagMode: TagMode.StartTagAndEndTag, tagMode: TagMode.StartTagAndEndTag,
items: null, items: new Dictionary<object, object>(),
uniqueId: string.Empty, uniqueId: string.Empty,
executeChildContentAsync: () => executeChildContentAsync: () =>
{ {
@ -91,7 +91,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
var executionContext = new TagHelperExecutionContext( var executionContext = new TagHelperExecutionContext(
"p", "p",
tagMode: TagMode.StartTagAndEndTag, tagMode: TagMode.StartTagAndEndTag,
items: null, items: new Dictionary<object, object>(),
uniqueId: string.Empty, uniqueId: string.Empty,
executeChildContentAsync: () => executeChildContentAsync: () =>
{ {
@ -120,7 +120,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
var executionContext = new TagHelperExecutionContext( var executionContext = new TagHelperExecutionContext(
"p", "p",
tagMode: TagMode.StartTagAndEndTag, tagMode: TagMode.StartTagAndEndTag,
items: null, items: new Dictionary<object, object>(),
uniqueId: string.Empty, uniqueId: string.Empty,
executeChildContentAsync: () => { return Task.FromResult(result: true); }, executeChildContentAsync: () => { return Task.FromResult(result: true); },
startTagHelperWritingScope: () => { }, startTagHelperWritingScope: () => { },
@ -145,7 +145,7 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
var executionContext = new TagHelperExecutionContext( var executionContext = new TagHelperExecutionContext(
"p", "p",
tagMode: TagMode.StartTagAndEndTag, tagMode: TagMode.StartTagAndEndTag,
items: null, items: new Dictionary<object, object>(),
uniqueId: string.Empty, uniqueId: string.Empty,
executeChildContentAsync: () => executeChildContentAsync: () =>
{ {