📄 reflectiontypenode.cs
字号:
// ReflectionTypeNode.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Collections;
using System.IO;
using System.Drawing.Printing;
using System.Windows.Forms;
using System.Reflection;
using System.Reflection.Emit;
using SharpDevelop.Gui.Edit;
using SharpDevelop.Internal.Undo;
using SharpDevelop.Gui.Window;
namespace SharpDevelop.Gui.Edit.Reflection {
public class ReflectionTypeNode : ReflectionNode
{
public ReflectionTypeNode(string name, Type type) : base (name, type, ReflectionNodeType.Type)
{
}
int GetIcon(Type type)
{
int BASE = CLASSINDEX;
if (type.IsValueType)
BASE = STRUCTINDEX;
if (type.IsEnum)
BASE = ENUMINDEX;
if (type.IsInterface)
BASE = INTERFACEINDEX;
if (type.IsNestedPrivate) {
return BASE + 3;
} else
if (type.IsNotPublic) {
return BASE + 2;
} else
if (type.IsNestedAssembly) {
return BASE + 1;
}
return BASE;
}
protected override void SetIcon()
{
ImageIndex = SelectedImageIndex = GetIcon((Type)attribute);
}
public override void Populate()
{
Type type = (Type)attribute;
// object[] attr = type.GetCustomAttributes(false);
// foreach (object o in attr)
// Console.WriteLine("ATTR : " + o.ToString());
Nodes.Clear();
ConstructorInfo[] constructorinfos = type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic);
MethodInfo[] methodinfos = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
FieldInfo[] fieldinfos = type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
PropertyInfo[] propertyinfos = type.GetProperties(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
EventInfo[] eventinfos = type.GetEvents(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
ReflectionNode supertype = new ReflectionNode("SuperTypes", type, ReflectionNodeType.SuperTypes);
Nodes.Add(supertype);
if (type.BaseType != null) {
ReflectionNode basetype = new ReflectionNode(type.BaseType.Name, type.BaseType, ReflectionNodeType.Link);
basetype.ImageIndex = basetype.SelectedImageIndex = GetIcon(type.BaseType);
supertype.Nodes.Add(basetype);
}
foreach (Type baseinterface in type.GetInterfaces()) {
ReflectionNode inode = new ReflectionNode(baseinterface.Name, baseinterface, ReflectionNodeType.Link);
inode.ImageIndex = inode.SelectedImageIndex = GetIcon(baseinterface);
supertype.Nodes.Add(inode);
}
Nodes.Add(new ReflectionNode("SubTypes", type, ReflectionNodeType.SubTypes));
foreach (ConstructorInfo constructorinfo in constructorinfos) {
Nodes.Add(new ReflectionMethodNode(constructorinfo));
}
foreach (MethodInfo methodinfo in methodinfos) {
if (methodinfo.DeclaringType.Equals(type))
if ((methodinfo.Attributes & MethodAttributes.SpecialName) == 0)
Nodes.Add(new ReflectionMethodNode(methodinfo));
}
foreach (FieldInfo fieldinfo in fieldinfos) {
if (fieldinfo.DeclaringType.Equals(type))
Nodes.Add(new ReflectionNode(fieldinfo.Name, fieldinfo, ReflectionNodeType.Field));
}
foreach (PropertyInfo propertyinfo in propertyinfos) {
if (propertyinfo.DeclaringType.Equals(type))
Nodes.Add(new ReflectionNode(propertyinfo.Name, propertyinfo, ReflectionNodeType.Property));
}
foreach (EventInfo eventinfo in eventinfos) {
if (eventinfo.DeclaringType.Equals(type))
Nodes.Add(new ReflectionNode(eventinfo.Name, eventinfo, ReflectionNodeType.Event));
}
populated = true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -