📄 igraphnode.cs
字号:
using System;
using System.Windows.Forms;
using System.Reflection;
using System.Collections;
using DDW.CSharp;
using DDW.CSharp.Dom;
namespace DDW.CSharpUI
{
/// <summary>
/// Summary description for IGraphNode.
/// </summary>
public class IGraphNode : TreeNode
{
private IGraph graph;
private Type type;
private static Hashtable iconIndex;
public IGraphNode(IGraph ig)
{
graph = ig;
type = graph.GetType();
object o = IconIndex[type];
int x = (int)o;
ImageIndex = (int)IconIndex[type];
// special icon cases
if(graph is AccessorDecl)
{
AccessorModifiers am = ((AccessorDecl)graph).AccessorModifier;
if(am == AccessorModifiers.Set || am == AccessorModifiers.Add)
ImageIndex = (int)CodeIcon.AccessorIn;
}
SelectedImageIndex = ImageIndex;
if(graph is ICollection)
{
ICollection col = (ICollection)graph;
int cnt = col.Count;
foreach(object gr in col)
{
if(gr is IGraph)
{
IGraphNode ign = new IGraphNode((IGraph)gr);
Nodes.Add(ign);
}
}
}
else
{
this.Text = graph.Text; // graph.GetType().Name + ": "+
}
GetChildren();
}
private void GetChildren()
{
// don't get children for the following : typeref, primaryExpr...
if( graph is DDW.CSharp.Dom.TypeRef ||
graph is DDW.CSharp.Dom.PrimitiveExpr ||
graph is DDW.CSharp.Dom.UnknownReference||
graph is DDW.CSharp.Dom.ArgumentRef ||
graph is DDW.CSharp.Dom.LocalRef
) return;
else if(graph is DDW.CSharp.Dom.PrimitiveExpr) return;
MemberInfo[] props = type.FindMembers(MemberTypes.Property,
BindingFlags.Public | BindingFlags.Instance,
new MemberFilter(MemberFilter),
null);
for(int i = 0; i < props.Length; i++)
{
object result = type.InvokeMember(
props[i].Name,
BindingFlags.Public |
BindingFlags.GetProperty |
BindingFlags.Instance,
null,
graph,
new object[]{} );
// ignore the following
if( result == null ||
result is LinePragma ||
(props[i].Name == "DimensionCount" && (int)result == 0)
) continue;
if(result is IGraph)
{
if(result is ICollection)
{
if( ((ICollection)result).Count == 0) continue;
IGraphNode node = new IGraphNode((IGraph)result);
node.Text = props[i].Name;
Nodes.Add(node);
}
else
{
IGraphNode node = new IGraphNode((IGraph)result);
Nodes.Add(node);
}
}
else if(result != null)
{
bool addToTree = true;
// literals etc.
TreeNode node =
new TreeNode(props[i].Name +" : "+result.ToString());
if(result is string)
{
node.ImageIndex = (int)CodeIcon.String;
if( (string)result == "") addToTree = false;
}
else if(result is int || result is long)
node.ImageIndex = (int)CodeIcon.Integer;
else if(result is float)
node.ImageIndex = (int)CodeIcon.Real;
else if(result is bool)
node.ImageIndex = (int)CodeIcon.Bool;
else if(result is Enum)
{
node.ImageIndex = (int)CodeIcon.EnumRef;
if( Enum.GetName(result.GetType(), result) == "Empty")
addToTree = false;
}
node.SelectedImageIndex = node.ImageIndex;
if(addToTree) Nodes.Insert(0,node);
}
}
}
public IGraph Graph
{
get
{
return graph;
}
}
public static bool MemberFilter(MemberInfo objMemberInfo, Object objSearch)
{
if(objMemberInfo.Name == "LinePragma") return false;
object[] oa = objMemberInfo.GetCustomAttributes(
CSharpGraph.GetTypeFromString("DDW.CSharp.Dom.CodeElementAttribute"), true);
if(oa.Length > 0)
{
return true;
}
return false;
}
private static Hashtable IconIndex
{
get
{
if(iconIndex != null) return iconIndex;
iconIndex = new Hashtable(125);
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.AccessorDecl"), CodeIcon.AccessorOut );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.ArgumentRef"), CodeIcon.Expr );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.ArrayCreateExpr"), CodeIcon.Expr );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.ArrayElementRef"), CodeIcon.Expr );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.ArrayInitializer"), CodeIcon.Expr );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.AssignExpr"), CodeIcon.Expr );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.AttachDelegateStmt"), CodeIcon.Stmt );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.BaseRef"), CodeIcon.Expr );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.BinaryExpr"), CodeIcon.Expr );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.BooleanLiteral"), CodeIcon.Bool );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.BreakStmt"), CodeIcon.Break );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.Case"), CodeIcon.Case );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.CaseCollection"), CodeIcon.CaseCol );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.CastExpr"), CodeIcon.Expr );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.Catch"), CodeIcon.Default );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.CatchCollection"), CodeIcon.Default );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.CharLiteral"), CodeIcon.Char );
iconIndex.Add(CSharpGraph.GetTypeFromString(
"DDW.CSharp.Dom.CheckedStmt"), CodeIcon.Stmt );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -