提交 78c63b43 编写于 作者: A Andrew Casey

Add input validation

上级 111d3d52
...@@ -240,7 +240,7 @@ private string FormatGenericTypeName(TypeInfo typeInfo, Options options) ...@@ -240,7 +240,7 @@ private string FormatGenericTypeName(TypeInfo typeInfo, Options options)
if (options.ShowNamespaces) if (options.ShowNamespaces)
{ {
var @namespace = nestedTypes.Last().Namespace; var @namespace = nestedTypes.Last().Namespace;
if (@namespace.Length > 0) if (@namespace != null)
{ {
builder.Append(@namespace + "."); builder.Append(@namespace + ".");
} }
......
...@@ -23,7 +23,7 @@ public enum MemberDisplayFormat ...@@ -23,7 +23,7 @@ public enum MemberDisplayFormat
Hidden, Hidden,
} }
internal static partial class EnumBounds internal static partial class MemberDisplayFormatExtensions
{ {
internal static bool IsValid(this MemberDisplayFormat value) internal static bool IsValid(this MemberDisplayFormat value)
{ {
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.Scripting.Hosting
{
public enum NumberRadix : byte
{
Decimal = 10,
Hexadecimal = 16,
}
internal static class NumberRadixExtensions
{
internal static bool IsValid(this NumberRadix radix)
{
switch(radix)
{
case NumberRadix.Decimal:
case NumberRadix.Hexadecimal:
return true;
default:
return false;
}
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.CodeAnalysis.Scripting.Hosting namespace Microsoft.CodeAnalysis.Scripting.Hosting
{ {
public class PrintOptions public class PrintOptions
{ {
public NumberRadix NumberRadix { get; set; } = NumberRadix.Decimal; private NumberRadix _numberRadix = NumberRadix.Decimal;
public MemberDisplayFormat MemberDisplayFormat { get; set; } private MemberDisplayFormat _memberDisplayFormat;
public bool EscapeNonPrintableCharacters { get; set; } private bool _escapeNonPrintableCharacters;
public int MaximumOutputLength { get; set; } = 1024; private int _maximumOutputLength = 1024;
}
public enum NumberRadix : byte public NumberRadix NumberRadix
{ {
Decimal = 10, get
Hexadecimal = 16, {
} return _numberRadix;
}
internal static class NumberRadixExtensions set
{ {
internal static bool IsValid(this NumberRadix radix) if (!value.IsValid())
{
throw new ArgumentOutOfRangeException(nameof(value));
}
_numberRadix = value;
}
}
public MemberDisplayFormat MemberDisplayFormat
{
get
{
return _memberDisplayFormat;
}
set
{
if (!value.IsValid())
{
throw new ArgumentOutOfRangeException(nameof(value));
}
_memberDisplayFormat = value;
}
}
public bool EscapeNonPrintableCharacters
{ {
switch(radix) get
{ {
case NumberRadix.Decimal: return _escapeNonPrintableCharacters;
case NumberRadix.Hexadecimal: }
return true;
default: set
return false; {
_escapeNonPrintableCharacters = value;
}
}
public int MaximumOutputLength
{
get
{
return _maximumOutputLength;
}
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value));
}
_maximumOutputLength = value;
} }
} }
} }
......
...@@ -84,6 +84,7 @@ ...@@ -84,6 +84,7 @@
<Compile Include="Hosting\ObjectFormatter\CommonTypeNameFormatter.Options.cs" /> <Compile Include="Hosting\ObjectFormatter\CommonTypeNameFormatter.Options.cs" />
<Compile Include="Hosting\ObjectFormatter\CommonTypeNameFormatter.cs" /> <Compile Include="Hosting\ObjectFormatter\CommonTypeNameFormatter.cs" />
<Compile Include="Hosting\CommonStackTraceRewriter.cs" /> <Compile Include="Hosting\CommonStackTraceRewriter.cs" />
<Compile Include="Hosting\ObjectFormatter\NumberRadix.cs" />
<Compile Include="Hosting\StackFrame.cs" /> <Compile Include="Hosting\StackFrame.cs" />
<Compile Include="Hosting\StackTraceRewriter.cs" /> <Compile Include="Hosting\StackTraceRewriter.cs" />
<Compile Include="Hosting\PrintOptions.cs" /> <Compile Include="Hosting\PrintOptions.cs" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册