TypeToString() public method

Converts a type reference into a string. This method is used by the member tree node for parameter and return types.
public TypeToString ( TypeReference type, bool includeNamespace, ICustomAttributeProvider typeAttributes = null ) : string
type Mono.Cecil.TypeReference
includeNamespace bool
typeAttributes ICustomAttributeProvider
return string
コード例 #1
0
        public override void Search(TypeDefinition type, Language language, Action <SearchResult> addResult)
        {
            if (MatchName(type, language))
            {
                addResult(new SearchResult
                {
                    Member        = type,
                    Image         = TypeTreeNode.GetIcon(type),
                    Name          = language.TypeToString(type, includeNamespace: false),
                    LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace,
                    Location      = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace
                });
            }

            base.Search(type, language, addResult);
        }
コード例 #2
0
ファイル: SearchStrategies.cs プロジェクト: yrest/ILSpy
        public override void Search(TypeDefinition type, Language language, Action <SearchResult> addResult)
        {
            if (MatchName(type, language))
            {
                string name = language.TypeToString(type, includeNamespace: false);
                addResult(new SearchResult {
                    Member        = type,
                    Fitness       = CalculateFitness(type, name),
                    Image         = TypeTreeNode.GetIcon(type),
                    Name          = name,
                    LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace,
                    Location      = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace
                });
            }

            foreach (TypeDefinition nestedType in type.NestedTypes)
            {
                Search(nestedType, language, addResult);
            }
        }
コード例 #3
0
ファイル: SearchStrategies.cs プロジェクト: yrest/ILSpy
        string GetLanguageSpecificName(Language language, IMemberDefinition member, bool fullName = false)
        {
            switch (member)
            {
            case TypeDefinition t:
                return(language.TypeToString(t, fullName));

            case FieldDefinition f:
                return(fullName ? language.TypeToString(f.DeclaringType, fullName) + "." + language.FormatFieldName(f) : language.FormatFieldName(f));

            case PropertyDefinition p:
                return(fullName ? language.TypeToString(p.DeclaringType, fullName) + "." + language.FormatPropertyName(p) : language.FormatPropertyName(p));

            case MethodDefinition m:
                return(fullName ? language.TypeToString(m.DeclaringType, fullName) + "." + language.FormatMethodName(m) : language.FormatMethodName(m));

            case EventDefinition e:
                return(fullName ? language.TypeToString(e.DeclaringType, fullName) + "." + language.FormatEventName(e) : language.FormatEventName(e));

            default:
                throw new NotSupportedException(member?.GetType() + " not supported!");
            }
        }
コード例 #4
0
ファイル: SearchStrategies.cs プロジェクト: neolithos/ILSpy
 void Add <T>(IEnumerable <T> items, TypeDefinition type, Language language, Action <SearchResult> addResult, Func <T, bool> matcher, Func <T, ImageSource> image) where T : MemberReference
 {
     foreach (var item in items)
     {
         if (matcher(item))
         {
             addResult(new SearchResult
             {
                 Member        = item,
                 Image         = image(item),
                 Name          = item.Name,
                 LocationImage = TypeTreeNode.GetIcon(type),
                 Location      = language.TypeToString(type, includeNamespace: true)
             });
         }
     }
 }
コード例 #5
0
ファイル: SearchStrategies.cs プロジェクト: zjuflyer/ILSpy
        void Add <T>(Func <IEnumerable <T> > itemsGetter, TypeDefinition type, Language language, Action <SearchResult> addResult, Func <T, Language, bool> matcher, Func <T, ImageSource> image) where T : MemberReference
        {
            IEnumerable <T> items = Enumerable.Empty <T>();

            try {
                items = itemsGetter();
            } catch (Exception ex) {
                System.Diagnostics.Debug.Print(ex.ToString());
            }
            foreach (var item in items)
            {
                if (matcher(item, language))
                {
                    addResult(new SearchResult {
                        Member        = item,
                        Fitness       = CalculateFitness(item),
                        Image         = image(item),
                        Name          = GetLanguageSpecificName(language, (IMemberDefinition)item),
                        LocationImage = TypeTreeNode.GetIcon(type),
                        Location      = language.TypeToString(type, includeNamespace: true)
                    });
                }
            }
        }
コード例 #6
0
ファイル: SearchPane.cs プロジェクト: lopezycj/ILSpy
            void PerformSearch(TypeDefinition type)
            {
                if (searchMode == SearchMode_Type && IsMatch(type.Name))
                {
                    AddResult(new SearchResult {
                        Member        = type,
                        Image         = TypeTreeNode.GetIcon(type),
                        Name          = language.TypeToString(type, includeNamespace: false),
                        LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace,
                        Location      = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace
                    });
                }

                foreach (TypeDefinition nestedType in type.NestedTypes)
                {
                    PerformSearch(nestedType);
                }

                if (searchMode == SearchMode_Type)
                {
                    return;
                }

                foreach (FieldDefinition field in type.Fields)
                {
                    if (IsMatch(field))
                    {
                        AddResult(new SearchResult {
                            Member        = field,
                            Image         = FieldTreeNode.GetIcon(field),
                            Name          = field.Name,
                            LocationImage = TypeTreeNode.GetIcon(type),
                            Location      = language.TypeToString(type, includeNamespace: true)
                        });
                    }
                }
                foreach (PropertyDefinition property in type.Properties)
                {
                    if (IsMatch(property))
                    {
                        AddResult(new SearchResult {
                            Member        = property,
                            Image         = PropertyTreeNode.GetIcon(property),
                            Name          = property.Name,
                            LocationImage = TypeTreeNode.GetIcon(type),
                            Location      = language.TypeToString(type, includeNamespace: true)
                        });
                    }
                }
                foreach (EventDefinition ev in type.Events)
                {
                    if (IsMatch(ev))
                    {
                        AddResult(new SearchResult {
                            Member        = ev,
                            Image         = EventTreeNode.GetIcon(ev),
                            Name          = ev.Name,
                            LocationImage = TypeTreeNode.GetIcon(type),
                            Location      = language.TypeToString(type, includeNamespace: true)
                        });
                    }
                }
                foreach (MethodDefinition method in type.Methods)
                {
                    switch (method.SemanticsAttributes)
                    {
                    case MethodSemanticsAttributes.Setter:
                    case MethodSemanticsAttributes.Getter:
                    case MethodSemanticsAttributes.AddOn:
                    case MethodSemanticsAttributes.RemoveOn:
                    case MethodSemanticsAttributes.Fire:
                        continue;
                    }
                    if (IsMatch(method))
                    {
                        AddResult(new SearchResult {
                            Member        = method,
                            Image         = MethodTreeNode.GetIcon(method),
                            Name          = method.Name,
                            LocationImage = TypeTreeNode.GetIcon(type),
                            Location      = language.TypeToString(type, includeNamespace: true)
                        });
                    }
                }
            }
コード例 #7
0
ファイル: SearchPane.cs プロジェクト: xornand/dnSpy
        void CreateUI(ITextOutput output, object o, bool includeNamespace)
        {
            var ns = o as NamespaceSearchResult;

            if (ns != null)
            {
                output.WriteNamespace(ns.Namespace);
                return;
            }

            var td = o as TypeDef;

            if (td != null)
            {
                Debug.Assert(Language != null);
                Language.TypeToString(output, td, includeNamespace);
                return;
            }

            var md = o as MethodDef;

            if (md != null)
            {
                output.Write(IdentifierEscaper.Escape(md.Name), TextTokenHelper.GetTextTokenType(md));
                return;
            }

            var fd = o as FieldDef;

            if (fd != null)
            {
                output.Write(IdentifierEscaper.Escape(fd.Name), TextTokenHelper.GetTextTokenType(fd));
                return;
            }

            var pd = o as PropertyDef;

            if (pd != null)
            {
                output.Write(IdentifierEscaper.Escape(pd.Name), TextTokenHelper.GetTextTokenType(pd));
                return;
            }

            var ed = o as EventDef;

            if (ed != null)
            {
                output.Write(IdentifierEscaper.Escape(ed.Name), TextTokenHelper.GetTextTokenType(ed));
                return;
            }

            var asm = o as AssemblyDef;

            if (asm != null)
            {
                output.Write(asm);
                return;
            }

            var mod = o as ModuleDef;

            if (mod != null)
            {
                output.WriteModule(mod.FullName);
                return;
            }

            var asmRef = o as AssemblyRef;

            if (asmRef != null)
            {
                output.Write(asmRef);
                return;
            }

            var modRef = o as ModuleRef;

            if (modRef != null)
            {
                output.WriteModule(modRef.FullName);
                return;
            }

            // non-.NET file
            var file = o as DnSpyFile;

            if (file != null)
            {
                output.Write(file.ShortName, TextTokenType.Text);
                return;
            }

            var resNode = o as ResourceTreeNode;

            if (resNode != null)
            {
                output.WriteFilename(resNode.Name);
                return;
            }

            var resElNode = o as ResourceElementTreeNode;

            if (resElNode != null)
            {
                output.WriteFilename(resElNode.Name);
                return;
            }

            var s = o as string;

            if (s != null)
            {
                output.Write(s, TextTokenType.Text);
                return;
            }

            Debug.Assert(s == null);
        }
コード例 #8
0
            void PerformSearch(TypeDef type)
            {
                if (searchMode == SearchMode_Type && IsMatch(type.Name))
                {
                    AddResult(new SearchResult {
                        Member        = type,
                        Image         = TypeTreeNode.GetIcon(type),
                        Name          = language.TypeToString(type, includeNamespace: false),
                        LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace,
                        Location      = type.DeclaringType != null ? language.TypeToString(type.DeclaringType, includeNamespace: true) : type.Namespace.String
                    });
                }

                foreach (TypeDef nestedType in type.NestedTypes)
                {
                    PerformSearch(nestedType);
                }

                if (searchMode == SearchMode_Type)
                {
                    return;
                }

                foreach (FieldDef field in type.Fields)
                {
                    if (IsMatch(field))
                    {
                        AddResult(new SearchResult {
                            Member        = field,
                            Image         = FieldTreeNode.GetIcon(field),
                            Name          = field.Name,
                            LocationImage = TypeTreeNode.GetIcon(type),
                            Location      = language.TypeToString(type, includeNamespace: true)
                        });
                    }
                }
                foreach (PropertyDef property in type.Properties)
                {
                    if (IsMatch(property))
                    {
                        AddResult(new SearchResult {
                            Member        = property,
                            Image         = PropertyTreeNode.GetIcon(property),
                            Name          = property.Name,
                            LocationImage = TypeTreeNode.GetIcon(type),
                            Location      = language.TypeToString(type, includeNamespace: true)
                        });
                    }
                }
                foreach (EventDef ev in type.Events)
                {
                    if (IsMatch(ev))
                    {
                        AddResult(new SearchResult {
                            Member        = ev,
                            Image         = EventTreeNode.GetIcon(ev),
                            Name          = ev.Name,
                            LocationImage = TypeTreeNode.GetIcon(type),
                            Location      = language.TypeToString(type, includeNamespace: true)
                        });
                    }
                }
                foreach (MethodDef method in type.Methods)
                {
                    if (Decompiler.DnlibExtensions.HasSemantics(method))
                    {
                        continue;
                    }
                    if (IsMatch(method))
                    {
                        AddResult(new SearchResult {
                            Member        = method,
                            Image         = MethodTreeNode.GetIcon(method),
                            Name          = method.Name,
                            LocationImage = TypeTreeNode.GetIcon(type),
                            Location      = language.TypeToString(type, includeNamespace: true)
                        });
                    }
                }
            }