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.
using System;
@ -29,9 +29,14 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// <typeparam name="TAttribute">The <see cref="Attribute"/> type.</typeparam>
/// <param name="symbol">The <see cref="ISymbol"/> to find attributes on.</param>
/// <returns></returns>
public static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>([NotNull] ISymbol symbol)
public static IEnumerable<TAttribute> GetCustomAttributes<TAttribute>(ISymbol symbol)
where TAttribute : Attribute
{
if (symbol == null)
{
throw new ArgumentNullException(nameof(symbol));
}
var attributes = symbol.GetAttributes();
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.
using System;
@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.CodeAnalysis;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.Precompilation
{
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// Initializes a new instance of <see cref="CodeAnalysisSymbolBasedPropertyInfo"/>.
/// </summary>
/// <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;
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.
using System;
@ -9,7 +9,6 @@ using System.Reflection;
using System.Text;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.CodeAnalysis;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.Precompilation
{
@ -35,8 +34,13 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// Initializes a new instance of <see cref="CodeAnalysisSymbolBasedTypeInfo"/>.
/// </summary>
/// <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;
_underlyingType = UnwrapArrayType(type);
}
@ -174,10 +178,10 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
ITypeSymbol sourceTypeSymbol,
System.Reflection.TypeInfo targetTypeInfo)
{
return string.Equals(
targetTypeInfo.FullName,
GetFullName(sourceTypeSymbol),
StringComparison.Ordinal);
return string.Equals(
targetTypeInfo.FullName,
GetFullName(sourceTypeSymbol),
StringComparison.Ordinal);
}
/// <summary>
@ -185,8 +189,13 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// </summary>
/// <param name="symbol">The <see cref="ITypeSymbol" /> to generate the name for.</param>
/// <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();
GetAssemblyQualifiedName(builder, symbol);

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.CodeAnalysis;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.Precompilation
{
@ -24,14 +23,24 @@ namespace Microsoft.AspNet.Razor.Runtime.Precompilation
/// Initializes a new instance of <see cref="PrecompilationTagHelperTypeResolver"/>.
/// </summary>
/// <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;
}
/// <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)
{
IEnumerable<ITypeInfo> result;

View File

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

View File

@ -132,72 +132,132 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
}
/// <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));
return this;
}
/// <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));
return this;
}
/// <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));
return this;
}
/// <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));
return this;
}
/// <inheritdoc />
public override TagHelperContent AppendFormat(
[NotNull] IFormatProvider provider,
[NotNull] string format,
IFormatProvider provider,
string format,
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));
return this;
}
/// <inheritdoc />
public override TagHelperContent AppendFormat(
[NotNull] IFormatProvider provider,
[NotNull] string format,
IFormatProvider provider,
string format,
object arg0,
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));
return this;
}
/// <inheritdoc />
public override TagHelperContent AppendFormat(
[NotNull] IFormatProvider provider,
[NotNull] string format,
IFormatProvider provider,
string format,
object arg0,
object arg1,
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));
return this;
}
/// <inheritdoc />
public override TagHelperContent AppendFormat(
[NotNull] IFormatProvider provider,
[NotNull] string format,
IFormatProvider provider,
string format,
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));
return this;
}
@ -232,8 +292,18 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
}
/// <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);
}

View File

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

View File

@ -32,8 +32,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <paramref name="attributes"/>.
/// </summary>
/// <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);
}
@ -64,10 +69,15 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// matching <paramref name="name"/>.
/// </returns>
/// <remarks><paramref name="name"/> is compared case-insensitively.</remarks>
public TAttribute this[[NotNull] string name]
public TAttribute this[string name]
{
get
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return Attributes.FirstOrDefault(attribute => NameEquals(name, attribute));
}
}
@ -93,8 +103,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks>
/// <paramref name="item"/>s <see cref="IReadOnlyTagHelperAttribute.Name"/> is compared case-insensitively.
/// </remarks>
public bool Contains([NotNull] TAttribute item)
public bool Contains(TAttribute item)
{
if (item == null)
{
throw new ArgumentNullException(nameof(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>.
/// </returns>
/// <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));
}
@ -124,8 +144,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks>
/// <paramref name="item"/>s <see cref="IReadOnlyTagHelperAttribute.Name"/> is compared case-insensitively.
/// </remarks>
public int IndexOf([NotNull] TAttribute item)
public int IndexOf(TAttribute item)
{
if (item == null)
{
throw new ArgumentNullException(nameof(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
/// <see cref="IReadOnlyTagHelperAttribute.Name"/> exists in the collection; otherwise, <c>false</c>.</returns>
/// <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));
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
/// <see cref="IReadOnlyTagHelperAttribute.Name"/> exists in the collection; otherwise, <c>false</c>.</returns>
/// <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));
return attributes.Any();
@ -187,8 +222,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <param name="attribute">The attribute to compare against.</param>
/// <returns><c>true</c> if <paramref name="name"/> case-insensitively matches <paramref name="attribute"/>s
/// <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);
}
}

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.
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime
{
@ -18,8 +17,13 @@ namespace Microsoft.AspNet.Razor.Runtime
/// Initializes a new instance of <see cref="RuntimePropertyInfo"/>.
/// </summary>
/// <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;
}

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.
using System;
@ -27,8 +27,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// Initializes a new instance of <see cref="RuntimeTypeInfo"/>
/// </summary>
/// <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;
}

View File

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

View File

@ -25,9 +25,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <paramref name="attributes"/>.
/// </summary>
/// <param name="attributes">The collection to wrap.</param>
public TagHelperAttributeList([NotNull] IEnumerable<TagHelperAttribute> attributes)
public TagHelperAttributeList(IEnumerable<TagHelperAttribute> attributes)
: base(attributes)
{
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
}
/// <inheritdoc />
@ -40,9 +44,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
return base[index];
}
[param: NotNull]
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
if (value.Name == null)
{
throw new ArgumentException(
@ -83,15 +91,29 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// attributes["name"] = new TagHelperAttribute("name", "value");
/// </code>
/// </example>
public new TagHelperAttribute this[[NotNull] string name]
public new TagHelperAttribute this[string name]
{
get
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
return base[name];
}
[param: NotNull]
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:
// output.Attributes["someName"] = "someValue"
if (value.Name == null)
@ -152,8 +174,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </summary>
/// <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>
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));
}
@ -161,8 +188,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks>
/// <paramref name="attribute"/>'s <see cref="TagHelperAttribute.Name"/> must not be <c>null</c>.
/// </remarks>
public void Add([NotNull] TagHelperAttribute attribute)
public void Add(TagHelperAttribute attribute)
{
if (attribute == null)
{
throw new ArgumentNullException(nameof(attribute));
}
if (attribute.Name == null)
{
throw new ArgumentException(
@ -179,8 +211,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks>
/// <paramref name="attribute"/>'s <see cref="TagHelperAttribute.Name"/> must not be <c>null</c>.
/// </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)
{
throw new ArgumentException(
@ -194,8 +231,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
}
/// <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);
}
@ -203,8 +245,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <remarks>
/// <paramref name="attribute"/>s <see cref="TagHelperAttribute.Name"/> is compared case-insensitively.
/// </remarks>
public bool Remove([NotNull] TagHelperAttribute attribute)
public bool Remove(TagHelperAttribute attribute)
{
if (attribute == null)
{
throw new ArgumentNullException(nameof(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>.
/// </returns>
/// <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;
}

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
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
/// asynchronously.</param>
public TagHelperContext(
[NotNull] IEnumerable<IReadOnlyTagHelperAttribute> allAttributes,
[NotNull] IDictionary<object, object> items,
[NotNull] string uniqueId,
[NotNull] Func<bool, Task<TagHelperContent>> getChildContentAsync)
IEnumerable<IReadOnlyTagHelperAttribute> allAttributes,
IDictionary<object, object> items,
string uniqueId,
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.Select(attribute => new TagHelperAttribute(attribute.Name, attribute.Value)));
Items = items;

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
@ -54,10 +53,20 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </returns>
public static IEnumerable<TagHelperDescriptor> CreateDescriptors(
string assemblyName,
[NotNull] ITypeInfo typeInfo,
ITypeInfo typeInfo,
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))
{
return Enumerable.Empty<TagHelperDescriptor>();

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.AspNet.Razor.Parser;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
@ -52,8 +51,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
}
/// <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);
// 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.
#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.Reflection;
using Microsoft.AspNet.Razor.TagHelpers;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
@ -27,8 +26,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </param>
/// <returns>A <see cref="TagHelperDesignTimeDescriptor"/> that describes design time specific information
/// 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 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
/// information for the given <paramref name="propertyInfo"/>.</returns>
public static TagHelperAttributeDesignTimeDescriptor CreateAttributeDescriptor(
[NotNull] PropertyInfo propertyInfo)
PropertyInfo propertyInfo)
{
if (propertyInfo == null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
var id = XmlDocumentationProvider.GetId(propertyInfo);
var declaringAssembly = propertyInfo.DeclaringType.Assembly;
var documentationDescriptor = CreateDocumentationDescriptor(declaringAssembly, id);

View File

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

View File

@ -1,7 +1,7 @@
// 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.
using Microsoft.Framework.Internal;
using System;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
@ -23,8 +23,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <param name="attributes">The HTML attributes.</param>
public TagHelperOutput(
string tagName,
[NotNull] TagHelperAttributeList attributes)
TagHelperAttributeList attributes)
{
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
TagName = tagName;
Attributes = new TagHelperAttributeList(attributes);
}

View File

@ -1,9 +1,9 @@
// 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.
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
@ -19,8 +19,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// </param>
/// <returns>Resulting <see cref="TagHelperOutput"/> from processing all of the
/// <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(
executionContext.AllAttributes,
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>
/// <returns>A <see cref="TagHelperExecutionContext"/> to use.</returns>
public TagHelperExecutionContext Begin(
[NotNull] string tagName,
string tagName,
TagMode tagMode,
[NotNull] string uniqueId,
[NotNull] Func<Task> executeChildContentAsync,
[NotNull] Action startTagHelperWritingScope,
[NotNull] Func<TagHelperContent> endTagHelperWritingScope)
string uniqueId,
Func<Task> executeChildContentAsync,
Action startTagHelperWritingScope,
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;
// 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.Linq;
using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
{
@ -29,8 +28,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
public IEnumerable<ITypeInfo> Resolve(
string name,
SourceLocation documentLocation,
[NotNull] ErrorSink errorSink)
ErrorSink errorSink)
{
if (errorSink == null)
{
throw new ArgumentNullException(nameof(errorSink));
}
if (string.IsNullOrEmpty(name))
{
var errorLength = name == null ? 1 : Math.Max(name.Length, 1);
@ -71,8 +75,13 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <returns>
/// An <see cref="IEnumerable{ITypeInfo}"/> of types exported from the given <paramref name="assemblyName"/>.
/// </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);
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.
#if !DNXCORE50
@ -8,7 +8,6 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Xml.Linq;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Razor.Runtime
{
@ -76,8 +75,13 @@ namespace Microsoft.AspNet.Razor.Runtime
/// </summary>
/// <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>
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}";
}
@ -86,8 +90,13 @@ namespace Microsoft.AspNet.Razor.Runtime
/// </summary>
/// <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>
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;
return $"P:{declaringTypeInfo.FullName}.{propertyInfo.Name}";
}

View File

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

View File

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