Tree Node representing a field, method, property, or event.
Inheritance: ILSpyTreeNode, IMemberTreeNode
コード例 #1
0
        /// <summary>
        /// Looks up the method node corresponding to the method definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public ILSpyTreeNode FindMethodNode(MethodDef def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureChildrenFiltered();
            MethodTreeNode methodNode = typeNode.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def);

            if (methodNode != null)
            {
                return(methodNode);
            }
            foreach (var p in typeNode.Children.OfType <ILSpyTreeNode>())
            {
                if (p is PropertyTreeNode || p is EventTreeNode)
                {
                    p.EnsureChildrenFiltered();
                    methodNode = p.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def);
                    if (methodNode != null)
                    {
                        return(methodNode);
                    }
                }
            }

            return(null);
        }
コード例 #2
0
ファイル: FieldTreeNode.cs プロジェクト: zyj0021/ILSpy
		public static ImageSource GetIcon(IField field)
		{
			if (field.DeclaringType.Kind == TypeKind.Enum && field.ReturnType.Kind == TypeKind.Enum)
				return Images.GetIcon(MemberIcon.EnumValue, MethodTreeNode.GetOverlayIcon(field.Accessibility), false);

			if (field.IsConst)
				return Images.GetIcon(MemberIcon.Literal, MethodTreeNode.GetOverlayIcon(field.Accessibility), false);

			if (field.IsReadOnly)
				return Images.GetIcon(MemberIcon.FieldReadOnly, MethodTreeNode.GetOverlayIcon(field.Accessibility), field.IsStatic);

			return Images.GetIcon(MemberIcon.Field, MethodTreeNode.GetOverlayIcon(field.Accessibility), field.IsStatic);
		}
コード例 #3
0
        /// <summary>
        /// Looks up the method node corresponding to the method definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public ILSpyTreeNode FindMethodNode(MethodDefinition def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureLazyChildren();
            MethodTreeNode methodNode = typeNode.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def && !m.IsHidden);

            if (methodNode != null)
            {
                return(methodNode);
            }
            foreach (var p in typeNode.Children.OfType <ILSpyTreeNode>())
            {
                if (p.IsHidden)
                {
                    continue;
                }

                // method might be a child of a property or event
                if (p is PropertyTreeNode || p is EventTreeNode)
                {
                    p.EnsureLazyChildren();
                    methodNode = p.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def);
                    if (methodNode != null)
                    {
                        // If the requested method is a property or event accessor, and accessors are
                        // hidden in the UI, then return the owning property or event.
                        if (methodNode.IsHidden)
                        {
                            return(p);
                        }
                        else
                        {
                            return(methodNode);
                        }
                    }
                }
            }

            return(null);
        }
コード例 #4
0
		static MemberIcon GetMemberIcon(PropertyDef property) {
			MethodDef method = GetMostAccessibleMethod(property);
			if (method == null)
				return MemberIcon.Property;

			var access = MethodTreeNode.GetMemberAccess(method);
			if (method.IsStatic) {
				switch (access) {
				case MemberAccess.Public: return MemberIcon.StaticProperty;
				case MemberAccess.Private: return MemberIcon.StaticPropertyPrivate;
				case MemberAccess.Protected: return MemberIcon.StaticPropertyProtected;
				case MemberAccess.Internal: return MemberIcon.StaticPropertyInternal;
				case MemberAccess.CompilerControlled: return MemberIcon.StaticPropertyCompilerControlled;
				case MemberAccess.ProtectedInternal: return MemberIcon.StaticPropertyProtectedInternal;
				default:
					Debug.Fail("Invalid MemberAccess");
					goto case MemberAccess.Public;
				}
			}

			if (method.IsVirtual) {
				switch (access) {
				case MemberAccess.Public: return MemberIcon.VirtualProperty;
				case MemberAccess.Private: return MemberIcon.VirtualPropertyPrivate;
				case MemberAccess.Protected: return MemberIcon.VirtualPropertyProtected;
				case MemberAccess.Internal: return MemberIcon.VirtualPropertyInternal;
				case MemberAccess.CompilerControlled: return MemberIcon.VirtualPropertyCompilerControlled;
				case MemberAccess.ProtectedInternal: return MemberIcon.VirtualPropertyProtectedInternal;
				default:
					Debug.Fail("Invalid MemberAccess");
					goto case MemberAccess.Public;
				}
			}

			switch (access) {
			case MemberAccess.Public: return MemberIcon.Property;
			case MemberAccess.Private: return MemberIcon.PropertyPrivate;
			case MemberAccess.Protected: return MemberIcon.PropertyProtected;
			case MemberAccess.Internal: return MemberIcon.PropertyInternal;
			case MemberAccess.CompilerControlled: return MemberIcon.PropertyCompilerControlled;
			case MemberAccess.ProtectedInternal: return MemberIcon.PropertyProtectedInternal;
			default:
				Debug.Fail("Invalid MemberAccess");
				goto case MemberAccess.Public;
			}
		}
コード例 #5
0
        /// <summary>
        /// Looks up the method node corresponding to the method definition.
        /// Returns null if no matching node is found.
        /// </summary>
        public MethodTreeNode FindMethodNode(MethodDefinition def)
        {
            if (def == null)
            {
                return(null);
            }
            TypeTreeNode typeNode = FindTypeNode(def.DeclaringType);

            if (typeNode == null)
            {
                return(null);
            }
            typeNode.EnsureLazyChildren();
            MethodTreeNode methodNode = typeNode.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def && !m.IsHidden);

            if (methodNode != null)
            {
                return(methodNode);
            }
            foreach (var p in typeNode.Children.OfType <ILSpyTreeNode>())
            {
                if (p.IsHidden)
                {
                    continue;
                }
                // method might be a child or a property or events
                p.EnsureLazyChildren();
                methodNode = p.Children.OfType <MethodTreeNode>().FirstOrDefault(m => m.MethodDefinition == def && !m.IsHidden);
                if (methodNode != null)
                {
                    return(methodNode);
                }
            }

            return(null);
        }
コード例 #6
0
ファイル: EventTreeNode.cs プロジェクト: zwkjgs/ILSpy
 public static ImageSource GetIcon(IEvent @event)
 {
     return(Images.GetIcon(MemberIcon.Event, MethodTreeNode.GetOverlayIcon(@event.Accessibility), @event.IsStatic));
 }
コード例 #7
0
ファイル: MethodDefCommands.cs プロジェクト: arkanoid1/dnSpy
		MethodDefSettingsCommand(MethodTreeNode methodNode, MethodDefOptions options) {
			this.methodNode = methodNode;
			this.newOptions = options;
			this.origOptions = new MethodDefOptions(methodNode.MethodDef);

			this.origParentNode = (ILSpyTreeNode)methodNode.Parent;
			this.origParentChildIndex = this.origParentNode.Children.IndexOf(methodNode);
			Debug.Assert(this.origParentChildIndex >= 0);
			if (this.origParentChildIndex < 0)
				throw new InvalidOperationException();

			this.nameChanged = origOptions.Name != newOptions.Name;
			if (this.nameChanged)
				this.memberRefInfos = RefFinder.FindMemberRefsToThisModule(ILSpyTreeNode.GetModule(methodNode)).Where(a => RefFinder.MethodEqualityComparerInstance.Equals(a, methodNode.MethodDef)).Select(a => new Field.MemberRefInfo(a)).ToArray();
		}
コード例 #8
0
ファイル: MethodDefCommands.cs プロジェクト: arkanoid1/dnSpy
		CreateMethodDefCommand(TypeTreeNode ownerNode, MethodDefOptions options) {
			this.ownerNode = ownerNode;
			this.methodNode = new MethodTreeNode(options.CreateMethodDef(ownerNode.TypeDef.Module));
		}
コード例 #9
0
ファイル: MethodDefCommands.cs プロジェクト: arkanoid1/dnSpy
		DeleteMethodDefCommand(MethodTreeNode[] methodNodes) {
			this.nodes = new DeletableNodes<MethodTreeNode>(methodNodes);
		}
コード例 #10
0
ファイル: MethodDefCommands.cs プロジェクト: arkanoid1/dnSpy
			public void Restore(MethodTreeNode[] nodes) {
				Debug.Assert(infos != null);
				if (infos == null)
					throw new InvalidOperationException();
				Debug.Assert(infos.Length == nodes.Length);
				if (infos.Length != nodes.Length)
					throw new InvalidOperationException();

				for (int i = infos.Length - 1; i >= 0; i--) {
					var node = nodes[i];
					var info = infos[i];

					info.OwnerType.Methods.Insert(info.MethodIndex, node.MethodDef);

					for (int j = info.PropEventInfos.Count - 1; j >= 0; j--) {
						var pinfo = info.PropEventInfos[i];
						EventDef evt;
						switch (pinfo.PropEventType) {
						case ModelInfo.PropEventType.PropertyGetter:
							((PropertyDef)pinfo.PropOrEvent).GetMethods.Insert(pinfo.Index, node.MethodDef);
							break;

						case ModelInfo.PropEventType.PropertySetter:
							((PropertyDef)pinfo.PropOrEvent).SetMethods.Insert(pinfo.Index, node.MethodDef);
							break;

						case ModelInfo.PropEventType.PropertyOther:
							((PropertyDef)pinfo.PropOrEvent).OtherMethods.Insert(pinfo.Index, node.MethodDef);
							break;

						case ModelInfo.PropEventType.EventAdd:
							evt = (EventDef)pinfo.PropOrEvent;
							Debug.Assert(evt.AddMethod == null);
							if (evt.AddMethod != null)
								throw new InvalidOperationException();
							evt.AddMethod = node.MethodDef;
							break;

						case ModelInfo.PropEventType.EventInvoke:
							evt = (EventDef)pinfo.PropOrEvent;
							Debug.Assert(evt.InvokeMethod == null);
							if (evt.InvokeMethod != null)
								throw new InvalidOperationException();
							evt.InvokeMethod = node.MethodDef;
							break;

						case ModelInfo.PropEventType.EventRemove:
							evt = (EventDef)pinfo.PropOrEvent;
							Debug.Assert(evt.RemoveMethod == null);
							if (evt.RemoveMethod != null)
								throw new InvalidOperationException();
							evt.RemoveMethod = node.MethodDef;
							break;

						case ModelInfo.PropEventType.EventOther:
							((EventDef)pinfo.PropOrEvent).OtherMethods.Insert(pinfo.Index, node.MethodDef);
							break;

						default:
							throw new InvalidOperationException();
						}
					}
				}

				infos = null;
			}
コード例 #11
0
ファイル: MethodDefCommands.cs プロジェクト: arkanoid1/dnSpy
			public void Delete(MethodTreeNode[] nodes) {
				Debug.Assert(infos == null);
				if (infos != null)
					throw new InvalidOperationException();

				infos = new ModelInfo[nodes.Length];

				for (int i = 0; i < infos.Length; i++) {
					var node = nodes[i];

					var info = new ModelInfo(node.MethodDef);
					infos[i] = info;

					foreach (var prop in info.OwnerType.Properties) {
						info.AddMethods(prop, ModelInfo.PropEventType.PropertyGetter, prop.GetMethods, node.MethodDef);
						info.AddMethods(prop, ModelInfo.PropEventType.PropertySetter, prop.SetMethods, node.MethodDef);
						info.AddMethods(prop, ModelInfo.PropEventType.PropertyOther, prop.OtherMethods, node.MethodDef);
					}

					foreach (var evt in info.OwnerType.Events) {
						if (evt.AddMethod == node.MethodDef) {
							evt.AddMethod = null;
							info.PropEventInfos.Add(new ModelInfo.PropEventInfo(evt, ModelInfo.PropEventType.EventAdd, -1));
						}
						if (evt.InvokeMethod == node.MethodDef) {
							evt.InvokeMethod = null;
							info.PropEventInfos.Add(new ModelInfo.PropEventInfo(evt, ModelInfo.PropEventType.EventInvoke, -1));
						}
						if (evt.RemoveMethod == node.MethodDef) {
							evt.RemoveMethod = null;
							info.PropEventInfos.Add(new ModelInfo.PropEventInfo(evt, ModelInfo.PropEventType.EventRemove, -1));
						}
						info.AddMethods(evt, ModelInfo.PropEventType.EventOther, evt.OtherMethods, node.MethodDef);
					}

					info.OwnerType.Methods.RemoveAt(info.MethodIndex);
				}
			}
コード例 #12
0
 public static IBitmap GetIcon(IProperty property)
 {
     return(Images.GetIcon(property.IsIndexer ? MemberIcon.Indexer : MemberIcon.Property,
                           MethodTreeNode.GetOverlayIcon(property.Accessibility), property.IsStatic));
 }
コード例 #13
0
ファイル: MethodDefCommands.cs プロジェクト: BahNahNah/dnSpy
        MethodDefSettingsCommand(MethodTreeNode methodNode, MethodDefOptions options)
        {
            this.methodNode = methodNode;
            this.newOptions = options;
            this.origOptions = new MethodDefOptions(methodNode.MethodDefinition);

            this.origParentNode = (ILSpyTreeNode)methodNode.Parent;
            this.origParentChildIndex = this.origParentNode.Children.IndexOf(methodNode);
            Debug.Assert(this.origParentChildIndex >= 0);
            if (this.origParentChildIndex < 0)
                throw new InvalidOperationException();

            this.nameChanged = origOptions.Name != newOptions.Name;
        }
コード例 #14
0
ファイル: MethodBodyCommands.cs プロジェクト: se7ensoft/dnSpy
 MethodBodySettingsCommand(MethodTreeNode methodNode, MethodBodyOptions options)
 {
     this.methodNode = methodNode;
     this.newOptions = options;
     this.origMethodBody = methodNode.MethodDefinition.MethodBody;
 }
コード例 #15
0
ファイル: EventTreeNode.cs プロジェクト: xornand/dnSpy
        static MemberIcon GetMemberIcon(EventDef eventDef)
        {
            MethodDef method = eventDef.AddMethod ?? eventDef.RemoveMethod;

            if (method == null)
            {
                return(MemberIcon.Event);
            }

            var access = MethodTreeNode.GetMemberAccess(method);

            if (method.IsStatic)
            {
                switch (access)
                {
                case MemberAccess.Public: return(MemberIcon.StaticEvent);

                case MemberAccess.Private: return(MemberIcon.StaticEventPrivate);

                case MemberAccess.Protected: return(MemberIcon.StaticEventProtected);

                case MemberAccess.Internal: return(MemberIcon.StaticEventInternal);

                case MemberAccess.CompilerControlled: return(MemberIcon.StaticEventCompilerControlled);

                case MemberAccess.ProtectedInternal: return(MemberIcon.StaticEventProtectedInternal);

                default:
                    Debug.Fail("Invalid MemberAccess");
                    goto case MemberAccess.Public;
                }
            }

            if (method.IsVirtual)
            {
                switch (access)
                {
                case MemberAccess.Public: return(MemberIcon.VirtualEvent);

                case MemberAccess.Private: return(MemberIcon.VirtualEventPrivate);

                case MemberAccess.Protected: return(MemberIcon.VirtualEventProtected);

                case MemberAccess.Internal: return(MemberIcon.VirtualEventInternal);

                case MemberAccess.CompilerControlled: return(MemberIcon.VirtualEventCompilerControlled);

                case MemberAccess.ProtectedInternal: return(MemberIcon.VirtualEventProtectedInternal);

                default:
                    Debug.Fail("Invalid MemberAccess");
                    goto case MemberAccess.Public;
                }
            }

            switch (access)
            {
            case MemberAccess.Public: return(MemberIcon.Event);

            case MemberAccess.Private: return(MemberIcon.EventPrivate);

            case MemberAccess.Protected: return(MemberIcon.EventProtected);

            case MemberAccess.Internal: return(MemberIcon.EventInternal);

            case MemberAccess.CompilerControlled: return(MemberIcon.EventCompilerControlled);

            case MemberAccess.ProtectedInternal: return(MemberIcon.EventProtectedInternal);

            default:
                Debug.Fail("Invalid MemberAccess");
                goto case MemberAccess.Public;
            }
        }