diff --git a/src/Scripting/Core/Hosting/ObjectFormatter/CommonTypeNameFormatter.cs b/src/Scripting/Core/Hosting/ObjectFormatter/CommonTypeNameFormatter.cs index c9e592a0bdc60862d7cf1ed654a0b7e886d62ccf..173d7ef15b109f81a130f6c286b997a027ab6942 100644 --- a/src/Scripting/Core/Hosting/ObjectFormatter/CommonTypeNameFormatter.cs +++ b/src/Scripting/Core/Hosting/ObjectFormatter/CommonTypeNameFormatter.cs @@ -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 + "."); } diff --git a/src/Scripting/Core/Hosting/ObjectFormatter/MemberDisplayFormat.cs b/src/Scripting/Core/Hosting/ObjectFormatter/MemberDisplayFormat.cs index 8932824671fab8ba165d4ad57048ec27d0e6bd89..8aff8cbf0e8e78e02982d405b85e8fb5c2560133 100644 --- a/src/Scripting/Core/Hosting/ObjectFormatter/MemberDisplayFormat.cs +++ b/src/Scripting/Core/Hosting/ObjectFormatter/MemberDisplayFormat.cs @@ -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) { diff --git a/src/Scripting/Core/Hosting/ObjectFormatter/NumberRadix.cs b/src/Scripting/Core/Hosting/ObjectFormatter/NumberRadix.cs new file mode 100644 index 0000000000000000000000000000000000000000..4bb09340a0cb41196a65395760ea3572d961b0b5 --- /dev/null +++ b/src/Scripting/Core/Hosting/ObjectFormatter/NumberRadix.cs @@ -0,0 +1,25 @@ +// 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 diff --git a/src/Scripting/Core/Hosting/PrintOptions.cs b/src/Scripting/Core/Hosting/PrintOptions.cs index 13cbc17c36481dd539d0bd3ce0d74fb02675670e..8138e84c81df97d2b3caa6ac8406fd771f7c79c5 100644 --- a/src/Scripting/Core/Hosting/PrintOptions.cs +++ b/src/Scripting/Core/Hosting/PrintOptions.cs @@ -1,32 +1,80 @@ // 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; } } } diff --git a/src/Scripting/Core/Scripting.csproj b/src/Scripting/Core/Scripting.csproj index a0445c3d5c4e7b57db84b1a6c0493294af7e8271..23cd54a321fd17078bad9afb45b6a18163168aef 100644 --- a/src/Scripting/Core/Scripting.csproj +++ b/src/Scripting/Core/Scripting.csproj @@ -84,6 +84,7 @@ +