Need `[NotNull]` for all `TextWriter parameters in `RazorPage`

- #2102
- `PositionTagged<string>` and `RenderAsyncDelegate` parameters too
- and a few `string` parameters dereferenced or used as `Dictionary` keys
This commit is contained in:
Doug Bunting 2015-03-10 23:26:41 -07:00
parent cc7b319cb7
commit e9f56055eb
1 changed files with 19 additions and 17 deletions

View File

@ -186,7 +186,7 @@ namespace Microsoft.AspNet.Mvc.Razor
/// All writes to the <see cref="Output"/> or <see cref="ViewContext.Writer"/> after calling this method will /// All writes to the <see cref="Output"/> or <see cref="ViewContext.Writer"/> after calling this method will
/// be buffered until <see cref="EndTagHelperWritingScope"/> is called. /// be buffered until <see cref="EndTagHelperWritingScope"/> is called.
/// </remarks> /// </remarks>
public void StartTagHelperWritingScope(TextWriter writer) public void StartTagHelperWritingScope([NotNull] TextWriter writer)
{ {
// If there isn't a base writer take the ViewContext.Writer // If there isn't a base writer take the ViewContext.Writer
if (_originalWriter == null) if (_originalWriter == null)
@ -264,7 +264,7 @@ namespace Microsoft.AspNet.Mvc.Razor
/// <param name="writer">The <see cref="TextWriter"/> to which the /// <param name="writer">The <see cref="TextWriter"/> to which the
/// <paramref name="copyableTextWriter"/> is written.</param> /// <paramref name="copyableTextWriter"/> is written.</param>
/// <param name="copyableTextWriter">Contains the data to be written.</param> /// <param name="copyableTextWriter">Contains the data to be written.</param>
public void WriteTo(TextWriter writer, ITextWriterCopyable copyableTextWriter) public void WriteTo([NotNull] TextWriter writer, ITextWriterCopyable copyableTextWriter)
{ {
if (copyableTextWriter != null) if (copyableTextWriter != null)
{ {
@ -292,7 +292,7 @@ namespace Microsoft.AspNet.Mvc.Razor
/// For all other types, the encoded result of <see cref="object.ToString"/> is written to the /// For all other types, the encoded result of <see cref="object.ToString"/> is written to the
/// <paramref name="writer"/>. /// <paramref name="writer"/>.
/// </remarks> /// </remarks>
public virtual void WriteTo(TextWriter writer, object value) public virtual void WriteTo([NotNull] TextWriter writer, object value)
{ {
if (value != null && value != HtmlString.Empty) if (value != null && value != HtmlString.Empty)
{ {
@ -334,7 +334,7 @@ namespace Microsoft.AspNet.Mvc.Razor
/// </summary> /// </summary>
/// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param> /// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param>
/// <param name="value">The <see cref="string"/> to write.</param> /// <param name="value">The <see cref="string"/> to write.</param>
public virtual void WriteTo(TextWriter writer, string value) public virtual void WriteTo([NotNull] TextWriter writer, string value)
{ {
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
{ {
@ -356,7 +356,7 @@ namespace Microsoft.AspNet.Mvc.Razor
/// </summary> /// </summary>
/// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param> /// <param name="writer">The <see cref="TextWriter"/> instance to write to.</param>
/// <param name="value">The <see cref="object"/> to write.</param> /// <param name="value">The <see cref="object"/> to write.</param>
public virtual void WriteLiteralTo(TextWriter writer, object value) public virtual void WriteLiteralTo([NotNull] TextWriter writer, object value)
{ {
if (value != null) if (value != null)
{ {
@ -368,7 +368,7 @@ namespace Microsoft.AspNet.Mvc.Razor
/// Writes the specified <paramref name="value"/> without HTML encoding to <see cref="Output"/>. /// Writes the specified <paramref name="value"/> without HTML encoding to <see cref="Output"/>.
/// </summary> /// </summary>
/// <param name="value">The <see cref="string"/> to write.</param> /// <param name="value">The <see cref="string"/> to write.</param>
public virtual void WriteLiteralTo(TextWriter writer, string value) public virtual void WriteLiteralTo([NotNull] TextWriter writer, string value)
{ {
if (!string.IsNullOrEmpty(value)) if (!string.IsNullOrEmpty(value))
{ {
@ -376,19 +376,21 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
} }
public virtual void WriteAttribute(string name, public virtual void WriteAttribute(
PositionTagged<string> prefix, string name,
PositionTagged<string> suffix, [NotNull] PositionTagged<string> prefix,
params AttributeValue[] values) [NotNull] PositionTagged<string> suffix,
params AttributeValue[] values)
{ {
WriteAttributeTo(Output, name, prefix, suffix, values); WriteAttributeTo(Output, name, prefix, suffix, values);
} }
public virtual void WriteAttributeTo(TextWriter writer, public virtual void WriteAttributeTo(
string name, [NotNull] TextWriter writer,
PositionTagged<string> prefix, string name,
PositionTagged<string> suffix, [NotNull] PositionTagged<string> prefix,
params AttributeValue[] values) [NotNull] PositionTagged<string> suffix,
params AttributeValue[] values)
{ {
var first = true; var first = true;
var wroteSomething = false; var wroteSomething = false;
@ -452,7 +454,7 @@ namespace Microsoft.AspNet.Mvc.Razor
var sourceLength = next.Position - attrVal.Value.Position; var sourceLength = next.Position - attrVal.Value.Position;
BeginContext(attrVal.Value.Position, sourceLength, isLiteral: attrVal.Literal); BeginContext(attrVal.Value.Position, sourceLength, isLiteral: attrVal.Literal);
// The extra branching here is to ensure that we call the Write*To(string) overload whe // The extra branching here is to ensure that we call the Write*To(string) overload where
// possible. // possible.
if (attrVal.Literal && stringValue != null) if (attrVal.Literal && stringValue != null)
{ {
@ -521,7 +523,7 @@ namespace Microsoft.AspNet.Mvc.Razor
/// </summary> /// </summary>
/// <param name="name">The name of the section to create.</param> /// <param name="name">The name of the section to create.</param>
/// <param name="section">The <see cref="RenderAsyncDelegate"/> to execute when rendering the section.</param> /// <param name="section">The <see cref="RenderAsyncDelegate"/> to execute when rendering the section.</param>
public void DefineSection(string name, RenderAsyncDelegate section) public void DefineSection([NotNull] string name, [NotNull] RenderAsyncDelegate section)
{ {
if (SectionWriters.ContainsKey(name)) if (SectionWriters.ContainsKey(name))
{ {