Esempio n. 1
0
        static void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var doc = CodistPackage.DTE.ActiveDocument;

            if (doc == null)
            {
                return;
            }
            var docWindow = TextEditorHelper.GetActiveWpfDocumentView();

            if (docWindow == null)
            {
                return;
            }
            var t = docWindow.TextBuffer.ContentType;

            using (var b = ReusableStringBuilder.AcquireDefault(100)) {
                var sb = b.Resource;
                var d  = docWindow.TextBuffer.GetTextDocument();
                sb.Append(R.T_ContentTypeOfDocument);
                if (d != null)
                {
                    sb.Append(System.IO.Path.GetFileName(d.FilePath));
                }
                sb.AppendLine();
                sb.AppendLine();
                var h = new HashSet <IContentType>();
                ShowContentType(t, sb, h, 0);
                System.Windows.Forms.MessageBox.Show(sb.ToString(), nameof(Codist));
            }

            void ShowContentType(IContentType type, StringBuilder sb, HashSet <IContentType> h, int indent)
            {
                sb.Append(' ', indent)
                .Append(type.DisplayName);
                if (type.DisplayName != type.TypeName)
                {
                    sb.Append('(')
                    .Append(type.TypeName)
                    .Append(')');
                }
                sb.AppendLine();
                foreach (var bt in type.BaseTypes)
                {
                    if (h.Add(bt))
                    {
                        ShowContentType(bt, sb, h, indent + 2);
                    }
                }
            }
        }
Esempio n. 2
0
 static string ToBinString(byte[] bytes)
 {
     using (var sbr = ReusableStringBuilder.AcquireDefault((bytes.Length << 3) + bytes.Length)) {
         var sb = sbr.Resource;
         for (int i = 0; i < bytes.Length; i++)
         {
             ref var b = ref bytes[i];
             if (b == 0 && sb.Length == 0)
             {
                 continue;
             }
             if (sb.Length > 0)
             {
                 sb.Append(' ');
             }
             sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
         }
         return(sb.Length == 0 ? "00000000" : sb.ToString());
     }
Esempio n. 3
0
        public static string GetSignatureString(this ISymbol symbol)
        {
            if (symbol.Kind != SymbolKind.Method)
            {
                return(symbol.Name);
            }
            using (var sbr = ReusableStringBuilder.AcquireDefault(100)) {
                var sb = sbr.Resource;
                var m  = symbol as IMethodSymbol;
                sb.Append(m.Name);
                if (m.IsGenericMethod)
                {
                    sb.Append('<');
                    var s = false;
                    foreach (var item in m.TypeParameters)
                    {
                        if (s)
                        {
                            sb.Append(", ");
                        }
                        else
                        {
                            s = true;
                        }
                        sb.Append(item.Name);
                    }
                    sb.Append('>');
                }
                sb.Append('(');
                var p = false;
                foreach (var item in m.Parameters)
                {
                    if (p)
                    {
                        sb.Append(", ");
                    }
                    else
                    {
                        p = true;
                    }
                    GetTypeName(item.Type, sb);
                }
                sb.Append(')');
                return(sb.ToString());
            }
            void GetTypeName(ITypeSymbol type, StringBuilder output)
            {
                switch (type.TypeKind)
                {
                case TypeKind.Array:
                    GetTypeName((type as IArrayTypeSymbol).ElementType, output);
                    output.Append("[]");
                    return;

                case TypeKind.Dynamic:
                    output.Append('?'); return;

                case TypeKind.Module:
                case TypeKind.TypeParameter:
                case TypeKind.Enum:
                case TypeKind.Error:
                    output.Append(type.Name); return;

                case TypeKind.Pointer:
                    GetTypeName((type as IPointerTypeSymbol).PointedAtType, output);
                    output.Append('*');
                    return;
                }
                output.Append(type.Name);
                var nt = type as INamedTypeSymbol;

                if (nt == null)
                {
                    return;
                }
                if (nt.IsGenericType == false)
                {
                    return;
                }
                var s = false;

                output.Append('<');
                foreach (var item in nt.TypeArguments)
                {
                    if (s)
                    {
                        output.Append(", ");
                    }
                    else
                    {
                        s = true;
                    }
                    GetTypeName(item, output);
                }
                output.Append('>');
            }
        }