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

Add input validation

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