Esempio n. 1
0
        public string FormatTypeName(Type type, ObjectFormattingOptions options)
        {
            string result = GetPrimitiveTypeName(GetPrimitiveSpecialType(type));

            if (result != null)
            {
                return(result);
            }

            result = FormatGeneratedTypeName(type);
            if (result != null)
            {
                return(result);
            }

            if (type.IsArray)
            {
                return(FormatArrayTypeName(type, arrayOpt: null, options: options));
            }

            var typeInfo = type.GetTypeInfo();

            if (typeInfo.IsGenericType)
            {
                return(FormatGenericTypeName(typeInfo, options));
            }

            if (typeInfo.DeclaringType != null)
            {
                return(typeInfo.Name.Replace('+', '.'));
            }

            return(typeInfo.Name);
        }
Esempio n. 2
0
 public Service()
 {
     // TODO (tomat): we should share the copied files with the host
     _metadataFileProvider = new MetadataShadowCopyProvider();
     _assemblyLoader = new InteractiveAssemblyLoader(_metadataFileProvider);
     _sourceSearchPaths = DefaultSourceSearchPaths;
     _formattingOptions = new ObjectFormattingOptions(
         memberFormat: MemberDisplayFormat.Inline,
         quoteStrings: true,
         useHexadecimalNumbers: false,
         maxOutputLength: 200,
         memberIndentation: "  ");
 }
Esempio n. 3
0
            public Builder(int lengthLimit, ObjectFormattingOptions options, bool insertEllipsis)
            {
                Debug.Assert(lengthLimit <= options.MaxOutputLength);

                int lineLengthLimit = options.MaxLineLength;

                if (insertEllipsis)
                {
                    lengthLimit     = Math.Max(0, lengthLimit - options.Ellipsis.Length - 1);
                    lineLengthLimit = Math.Max(0, lineLengthLimit - options.Ellipsis.Length - 1);
                }

                _lengthLimit     = lengthLimit;
                _lineLengthLimit = lineLengthLimit;
                _currentLimit    = Math.Min(lineLengthLimit, lengthLimit);
                _insertEllipsis  = insertEllipsis;

                _options = options;
                _sb      = new StringBuilder();
            }
Esempio n. 4
0
        private string FormatGenericTypeName(TypeInfo typeInfo, ObjectFormattingOptions options)
        {
            var pooledBuilder = PooledStringBuilder.GetInstance();
            var builder       = pooledBuilder.Builder;

            // consolidated generic arguments (includes arguments of all declaring types):
            Type[] genericArguments = typeInfo.GenericTypeArguments;

            if (typeInfo.DeclaringType != null)
            {
                var nestedTypes = ArrayBuilder <TypeInfo> .GetInstance();

                do
                {
                    nestedTypes.Add(typeInfo);
                    typeInfo = typeInfo.DeclaringType?.GetTypeInfo();
                }while (typeInfo != null);

                int typeArgumentIndex = 0;
                for (int i = nestedTypes.Count - 1; i >= 0; i--)
                {
                    AppendTypeInstantiation(builder, nestedTypes[i], genericArguments, ref typeArgumentIndex, options);
                    if (i > 0)
                    {
                        builder.Append('.');
                    }
                }

                nestedTypes.Free();
            }
            else
            {
                int typeArgumentIndex = 0;
                AppendTypeInstantiation(builder, typeInfo, genericArguments, ref typeArgumentIndex, options);
            }

            return(pooledBuilder.ToStringAndFree());
        }
Esempio n. 5
0
            public Builder(int lengthLimit, ObjectFormattingOptions options, bool insertEllipsis)
            {
                Debug.Assert(lengthLimit <= options.MaxOutputLength);

                int lineLengthLimit = options.MaxLineLength;
                if (insertEllipsis)
                {
                    lengthLimit = Math.Max(0, lengthLimit - options.Ellipsis.Length - 1);
                    lineLengthLimit = Math.Max(0, lineLengthLimit - options.Ellipsis.Length - 1);
                }

                _lengthLimit = lengthLimit;
                _lineLengthLimit = lineLengthLimit;
                _currentLimit = Math.Min(lineLengthLimit, lengthLimit);
                _insertEllipsis = insertEllipsis;

                _options = options;
                _sb = new StringBuilder();
            }
Esempio n. 6
0
 public string FormatObject(object obj, ObjectFormattingOptions options = null)
 {
     return new Formatter(this, options).FormatObject(obj);
 }
Esempio n. 7
0
            public Service()
            {
                // TODO (tomat): we should share the copied files with the host
                _metadataFileProvider = new MetadataShadowCopyProvider(
                    Path.Combine(Path.GetTempPath(), "InteractiveHostShadow"),
                    noShadowCopyDirectories: s_systemNoShadowCopyDirectories);

                _options = ScriptOptions.Default.WithSearchPaths(DefaultReferenceSearchPaths);

                _assemblyLoader = new InteractiveAssemblyLoader(_metadataFileProvider);
                _sourceSearchPaths = DefaultSourceSearchPaths;
                _formattingOptions = new ObjectFormattingOptions(
                    memberFormat: MemberDisplayFormat.Inline,
                    quoteStrings: true,
                    useHexadecimalNumbers: false,
                    maxOutputLength: 200,
                    memberIndentation: "  ");

                // We want to be sure to delete the shadow-copied files when the process goes away. Frankly
                // there's nothing we can do if the process is forcefully quit or goes down in a completely
                // uncontrolled manner (like a stack overflow). When the process goes down in a controlled
                // manned, we should generally expect this event to be called.
                AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
            }
Esempio n. 8
0
 // TODO (tomat): testing only
 public void SetTestObjectFormattingOptions()
 {
     _formattingOptions = new ObjectFormattingOptions(
         memberFormat: MemberDisplayFormat.Inline,
         quoteStrings: true,
         useHexadecimalNumbers: false,
         maxOutputLength: int.MaxValue,
         memberIndentation: "  ");
 }
 public Formatter(ObjectFormatter language, ObjectFormattingOptions options)
 {
     _options = options ?? ObjectFormattingOptions.Default;
     _language = language;
 }
 public Formatter(ObjectFormatter language, ObjectFormattingOptions options)
 {
     _options  = options ?? ObjectFormattingOptions.Default;
     _language = language;
 }
Esempio n. 11
0
        private string FormatGenericTypeName(TypeInfo typeInfo, ObjectFormattingOptions options)
        {
            var pooledBuilder = PooledStringBuilder.GetInstance();
            var builder = pooledBuilder.Builder;

            // consolidated generic arguments (includes arguments of all declaring types):
            Type[] genericArguments = typeInfo.GenericTypeArguments;

            if (typeInfo.DeclaringType != null)
            {
                var nestedTypes = ArrayBuilder<TypeInfo>.GetInstance();
                do
                {
                    nestedTypes.Add(typeInfo);
                    typeInfo = typeInfo.DeclaringType?.GetTypeInfo();
                }
                while (typeInfo != null);

                int typeArgumentIndex = 0;
                for (int i = nestedTypes.Count - 1; i >= 0; i--)
                {
                    AppendTypeInstantiation(builder, nestedTypes[i], genericArguments, ref typeArgumentIndex, options);
                    if (i > 0)
                    {
                        builder.Append('.');
                    }
                }

                nestedTypes.Free();
            }
            else
            {
                int typeArgumentIndex = 0;
                AppendTypeInstantiation(builder, typeInfo, genericArguments, ref typeArgumentIndex, options);
            }

            return pooledBuilder.ToStringAndFree();
        }
Esempio n. 12
0
 /// <summary>
 /// Formats an array type name (vector or multidimensional).
 /// </summary>
 public abstract string FormatArrayTypeName(Type arrayType, Array arrayOpt, ObjectFormattingOptions options);
Esempio n. 13
0
 public string FormatObject(object obj, ObjectFormattingOptions options = null)
 {
     return(new Formatter(this, options).FormatObject(obj));
 }
Esempio n. 14
0
 // TODO (tomat): Use DebuggerDisplay.Type if specified?
 public abstract string FormatTypeName(Type type, ObjectFormattingOptions options);
Esempio n. 15
0
 /// <summary>
 /// Formats an array type name (vector or multidimensional).
 /// </summary>
 public abstract string FormatArrayTypeName(Type arrayType, Array arrayOpt, ObjectFormattingOptions options);
Esempio n. 16
0
        public string FormatTypeName(Type type, ObjectFormattingOptions options)
        {
            string result = GetPrimitiveTypeName(GetPrimitiveSpecialType(type));
            if (result != null)
            {
                return result;
            }

            result = FormatGeneratedTypeName(type);
            if (result != null)
            {
                return result;
            }

            if (type.IsArray)
            {
                return FormatArrayTypeName(type, arrayOpt: null, options: options);
            }

            var typeInfo = type.GetTypeInfo();
            if (typeInfo.IsGenericType)
            {
                return FormatGenericTypeName(typeInfo, options);
            }

            if (typeInfo.DeclaringType != null)
            {
                return typeInfo.Name.Replace('+', '.');
            }

            return typeInfo.Name;
        }
Esempio n. 17
0
        private void AppendTypeInstantiation(StringBuilder builder, TypeInfo typeInfo, Type[] genericArguments, ref int genericArgIndex, ObjectFormattingOptions options)
        {
            // generic arguments of all the outer types and the current type;
            int currentArgCount = (typeInfo.IsGenericTypeDefinition ? typeInfo.GenericTypeParameters.Length : typeInfo.GenericTypeArguments.Length) - genericArgIndex;

            if (currentArgCount > 0)
            {
                string name = typeInfo.Name;

                int backtick = name.IndexOf('`');
                if (backtick > 0)
                {
                    builder.Append(name.Substring(0, backtick));
                }
                else
                {
                    builder.Append(name);
                }

                builder.Append(GenericParameterOpening);

                for (int i = 0; i < currentArgCount; i++)
                {
                    if (i > 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append(FormatTypeName(genericArguments[genericArgIndex++], options));
                }

                builder.Append(GenericParameterClosing);
            }
            else
            {
                builder.Append(typeInfo.Name);
            }
        }
Esempio n. 18
0
        private void AppendTypeInstantiation(StringBuilder builder, TypeInfo typeInfo, Type[] genericArguments, ref int genericArgIndex, ObjectFormattingOptions options)
        {
            // generic arguments of all the outer types and the current type;
            int currentArgCount = (typeInfo.IsGenericTypeDefinition ? typeInfo.GenericTypeParameters.Length : typeInfo.GenericTypeArguments.Length) - genericArgIndex;

            if (currentArgCount > 0)
            {
                string name = typeInfo.Name;

                int backtick = name.IndexOf('`');
                if (backtick > 0)
                {
                    builder.Append(name.Substring(0, backtick));
                }
                else
                {
                    builder.Append(name);
                }

                builder.Append(GenericParameterOpening);

                for (int i = 0; i < currentArgCount; i++)
                {
                    if (i > 0)
                    {
                        builder.Append(", ");
                    }
                    builder.Append(FormatTypeName(genericArguments[genericArgIndex++], options));
                }

                builder.Append(GenericParameterClosing);
            }
            else
            {
                builder.Append(typeInfo.Name);
            }
        }
Esempio n. 19
0
 // TODO (tomat): Use DebuggerDisplay.Type if specified?
 public abstract string FormatTypeName(Type type, ObjectFormattingOptions options);