protected SearchResult ResultFromEntity(IEntity item) { var declaringType = item.DeclaringTypeDefinition; return(new SearchResult { Member = item, Fitness = CalculateFitness(item), Image = GetIcon(item), Name = GetLanguageSpecificName(item), LocationImage = declaringType != null?TypeTreeNode.GetIcon(declaringType) : Images.Namespace, Location = declaringType != null?language.TypeToString(declaringType, includeNamespace : true) : item.Namespace }); }
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); }
public MemberSearchResult Create(IEntity entity) { var declaringType = entity.DeclaringTypeDefinition; return(new MemberSearchResult { Member = entity, Fitness = CalculateFitness(entity), Name = GetLanguageSpecificName(entity), Location = declaringType != null?language.TypeToString(declaringType, includeNamespace : true) : entity.Namespace, Assembly = entity.ParentModule.FullAssemblyName, ToolTip = entity.ParentModule.PEFile?.FileName, Image = Images.Assembly, LocationImage = declaringType != null?TypeTreeNode.GetIcon(declaringType) : Images.Namespace, AssemblyImage = Images.Assembly, }); }
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) }); } } }
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); } }
IBitmap GetIcon(IEntity member) { switch (member) { case ITypeDefinition t: return(TypeTreeNode.GetIcon(t)); case IField f: return(FieldTreeNode.GetIcon(f)); case IProperty p: return(PropertyTreeNode.GetIcon(p)); case IMethod m: return(MethodTreeNode.GetIcon(m)); case IEvent e: return(EventTreeNode.GetIcon(e)); default: throw new NotSupportedException(member?.GetType() + " not supported!"); } }
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) }); } } }
public static ImageSource GetIcon(TypeIcon icon, BackgroundType bgType) { return(TypeTreeNode.GetIcon(icon, bgType)); }
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) }); } } }
public TypeInfo Type(TypeDefinition typeDefinition) { if (typeDefinition == null) { return(null); } if (_typeCorrespondence.ContainsKey(typeDefinition)) { return(_typeCorrespondence[typeDefinition]); } var methods = typeDefinition.Methods .Where(m => !m.IsGetter && !m.IsSetter && !m.IsAddOn && !m.IsRemoveOn) .ToArray(); var typeInfo = new TypeInfo { BaseTypeRetriever = () => Type(typeDefinition.BaseType), DeclaringType = Type(typeDefinition.DeclaringType), Name = MainWindow.Instance.CurrentLanguage.FormatTypeName(typeDefinition), Icon = TypeTreeNode.GetIcon(typeDefinition), Events = typeDefinition.Events.Select(e => Event(e)), Fields = typeDefinition.Fields.Select(f => Field(f)), Methods = methods.Select(m => Method(m)), Accessors = typeDefinition.Methods.Except(methods).Select(m => Method(m)), Properties = typeDefinition.Properties.Select(p => Property(p)), MembersCount = methods.Count() + typeDefinition.Events.Count + typeDefinition.Properties.Count + typeDefinition.Fields.Count, IsInternal = typeDefinition.IsNotPublic || typeDefinition.IsNestedAssembly || typeDefinition.IsNestedFamilyAndAssembly || typeDefinition.IsNestedPrivate, IsPublic = typeDefinition.IsPublic || typeDefinition.IsNestedPublic || typeDefinition.IsNestedFamilyOrAssembly || typeDefinition.IsNestedFamily, MemberReference = typeDefinition, IsEnum = typeDefinition.IsEnum, IsInterface = typeDefinition.IsInterface, IsValueType = typeDefinition.IsValueType, IsSealed = typeDefinition.IsSealed, IsAbstract = typeDefinition.IsAbstract }; _typeCorrespondence.Add(typeDefinition, typeInfo); typeInfo.FullName = GetFullName(typeDefinition.Namespace, typeInfo.Name); foreach (var eventInfo in typeInfo.Events) { eventInfo.DeclaringType = typeInfo; } foreach (var methodInfo in typeInfo.Methods) { methodInfo.DeclaringType = typeInfo; } foreach (var methodInfo in typeInfo.Accessors) { methodInfo.DeclaringType = typeInfo; } foreach (var fieldInfo in typeInfo.Fields) { fieldInfo.DeclaringType = typeInfo; } foreach (var propertyInfo in typeInfo.Properties) { propertyInfo.DeclaringType = typeInfo; } typeInfo.Module = Module(typeDefinition.Module); return(typeInfo); }
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) }); } } }