📄 infoview.cs
字号:
ret.Append(singleRes.ToString());
}
return ret.ToString();
}
string GetAssemblyInfo(SA.SharpAssembly asm)
{
string text = String.Format(RT("AsmInfo"),
asm.Name, asm.FullName, asm.GetAssemblyName().Version.ToString(),
asm.Location, asm.FromGAC);
return String.Concat(text, GetCustomAttribs(asm));
}
string GetEventInfo(IEvent info)
{
StringBuilder ret = new StringBuilder(ambience.Convert(info));
ret.Append("<p>");
ret.Append(RT("Attributes"));
ret.Append("<br>");
ret.Append(GetCustomAttribs(info));
IClass c = parserService.GetClass(info.DeclaringType.FullyQualifiedName.Replace("+", "."));
if(c == null) goto noDoc;
foreach(IEvent e in c.Events) {
if(e.Name == info.Name) {
if (e.Documentation == null || e.Documentation == "") continue;
ret.Append("<p class='bottomline'>");
ret.Append(RT("Documentation"));
ret.Append("<p class='docmargin'>");
ret.Append(GetDocumentation(e.Documentation));
ret.Append("<p>");
break;
}
}
noDoc:
ret.Append("<br>");
ret.Append(GetInType(info.DeclaringType));
ret.Append("<p>");
ret.Append(GetInAsm((SA.SharpAssembly)info.DeclaringType.DeclaredIn));
return ret.ToString();
}
string GetFieldInfo(IField info)
{
StringBuilder ret = new StringBuilder(ambience.Convert(info));
if (info is SharpAssemblyField) {
SharpAssemblyField saField = info as SharpAssemblyField;
if (saField.InitialValue != null) {
ret.Append(" = ");
ret.Append(saField.InitialValue.ToString());
}
}
ret.Append("<p>");
ret.Append(RT("Attributes"));
ret.Append("<br>");
ret.Append(GetCustomAttribs(info));
IClass c = parserService.GetClass(info.DeclaringType.FullyQualifiedName.Replace("+", "."));
if(c == null) goto noDoc;
foreach(IField f in c.Fields) {
if(f.Name == info.Name) {
if (f.Documentation == null || f.Documentation == "") continue;
ret.Append("<p class='bottomline'>");
ret.Append(RT("Documentation"));
ret.Append("<p class='docmargin'>");
ret.Append(GetDocumentation(f.Documentation));
ret.Append("<p>");
break;
}
}
noDoc:
ret.Append("<br>");
ret.Append(GetInType(info.DeclaringType));
ret.Append("<p>");
ret.Append(GetInAsm((SA.SharpAssembly)info.DeclaringType.DeclaredIn));
return ret.ToString();
}
string GetMethodInfo(IMethod info)
{
StringBuilder ret = new StringBuilder(ambience.Convert(info));
ret.Append("<p>");
ret.Append(RT("Attributes"));
ret.Append("<br>");
ret.Append(GetCustomAttribs(info));
IClass c = parserService.GetClass(info.DeclaringType.FullyQualifiedName.Replace("+", "."));
if(c == null) goto noDoc;
foreach(IMethod cc in c.Methods) {
if (cc.Name == info.Name) {
if (cc.Documentation == null || cc.Documentation == "") continue;
ret.Append("<p class='bottomline'>");
ret.Append(RT("Documentation"));
ret.Append("<p class='docmargin'>");
ret.Append(GetDocumentation(cc.Documentation));
ret.Append("<p>");
break;
}
}
noDoc:
ret.Append("<br>");
ret.Append(GetInType(info.DeclaringType));
ret.Append("<p>");
ret.Append(GetInAsm((SA.SharpAssembly)info.DeclaringType.DeclaredIn));
return ret.ToString();
}
string GetPropInfo(IProperty info)
{
StringBuilder ret = new StringBuilder(ambience.Convert(info));
ret.Append("<p>");
ret.Append(RT("Attributes"));
ret.Append("<br>");
ret.Append(GetCustomAttribs(info));
IClass c = parserService.GetClass(info.DeclaringType.FullyQualifiedName.Replace("+", "."));
if(c == null) goto noDoc;
foreach(IProperty p in c.Properties) {
if(p.Name == info.Name) {
if (p.Documentation == null || p.Documentation == "") continue;
ret.Append("<p class='bottomline'>");
ret.Append(RT("Documentation"));
ret.Append("<p class='docmargin'>");
ret.Append(GetDocumentation(p.Documentation));
ret.Append("<p>");
break;
}
}
noDoc:
ret.Append("<br>");
ret.Append(GetInType(info.DeclaringType));
ret.Append("<p>");
ret.Append(GetInAsm((SA.SharpAssembly)info.DeclaringType.DeclaredIn));
return ret.ToString();
}
string GetTypeInfo(IClass type)
{
StringBuilder t = new StringBuilder(ambience.Convert(type));
t.Append("<p>");
t.Append(RT("BaseTypes"));
t.Append("<br>");
t.Append(GetBaseTypes(type as SharpAssemblyClass));
t.Append("<br>");
t.Append(RT("Attributes"));
t.Append("<br>");
t.Append(GetCustomAttribs(type));
IClass c = parserService.GetClass(type.FullyQualifiedName.Replace("+", "."));
if (c == null) goto noDoc;
if (c.Documentation == null || c.Documentation == "") goto noDoc;
t.Append("<p class='bottomline'>");
t.Append(RT("Documentation"));
t.Append("<p class='docmargin'>");
t.Append(GetDocumentation(c.Documentation));
t.Append("<p>");
noDoc:
if (type.Namespace == null || type.Namespace == "") goto inAsm;
t.Append("<br>");
t.Append(GetInNS((SA.SharpAssembly)type.DeclaredIn, type.Namespace));
inAsm:
t.Append("<p>");
t.Append(GetInAsm((SA.SharpAssembly)type.DeclaredIn));
return t.ToString();
}
string GetCustomAttribs(SA.SharpAssembly assembly)
{
return GetCustomAttribs(SharpAssemblyAttribute.GetAssemblyAttributes(assembly));
}
string GetCustomAttribs(IClass type)
{
if (type.Attributes.Count == 0) return "";
return GetCustomAttribs(type.Attributes[0].Attributes);
}
string GetCustomAttribs(IMember member)
{
if (member.Attributes.Count == 0) return "";
return GetCustomAttribs(member.Attributes[0].Attributes);
}
string GetCustomAttribs(AttributeCollection ca)
{
StringBuilder text = new StringBuilder();
try {
foreach(SharpAssemblyAttribute obj in ca) {
text.Append(ln(references.Add(obj.AttributeType), obj.Name));
text.Append(obj.ToString().Substring(obj.Name.Length));
text.Append("<br>");
}
} catch {
return "An error occured while looking for attributes.<br>";
}
return text.ToString();
}
string GetBaseTypes(SharpAssemblyClass type)
{
if (type == null || type.BaseTypeCollection.Count == 0) {
return String.Empty;
}
StringBuilder text = new StringBuilder();
foreach (SharpAssemblyClass basetype in type.BaseTypeCollection) {
text.Append(ln(references.Add(basetype), basetype.FullyQualifiedName));
text.Append("<br>");
}
return text.ToString();
}
string GetInAsm(SA.SharpAssembly asm)
{
StringBuilder text = new StringBuilder(RT("ContainedIn"));
text.Append(" ");
text.Append(ln(references.Add(new AssemblyTree.RefNodeAttribute(asm, asm.GetAssemblyName())), asm.Name));
return text.ToString();
}
string GetInNS(SA.SharpAssembly asm, string ns)
{
return String.Concat(RT("Namespace"),
" ",
ln(references.Add(new NamespaceLink(asm, ns)), ns));
}
string GetInType(IClass type)
{
return String.Concat(RT("Type"),
" ",
ln(references.Add(type), type.FullyQualifiedName));
}
void back_click(object sender, LinkLabelLinkClickedEventArgs ev)
{
try {
tree.GoBack();
} catch {}
}
class SaveResLink
{
public SA.SharpAssembly Asm;
public string Name;
public SaveResLink(SA.SharpAssembly asm, string name)
{
Asm = asm;
Name = name;
}
}
class NamespaceLink
{
public SA.SharpAssembly Asm;
public string Name;
public NamespaceLink(SA.SharpAssembly asm, string name)
{
Asm = asm;
Name = name;
}
}
readonly static Regex whitespace = new Regex(@"\s+");
public string GetDocumentation(string doc)
{
StringReader reader = new StringReader(String.Concat("<docroot>", doc, "</docroot>"));
XmlTextReader xml = new XmlTextReader(reader);
StringBuilder ret = new StringBuilder();
try {
xml.Read();
do {
if (xml.NodeType == XmlNodeType.Element) {
string elname = xml.Name.ToLower();
if (elname == "remarks") {
ret.Append(String.Concat("<b>", RTD("Remarks"), "</b><br>"));
} else if (elname == "example") {
ret.Append(String.Concat("<b>", RTD("Example"), "</b><br>"));
} else if (elname == "exception") {
ret.Append(String.Concat("<b>", RTD("Exception"), "</b> ", GetCref(xml["cref"]), ":<br>"));
} else if (elname == "returns") {
ret.Append(String.Concat("<b>", RTD("Returns"), "</b> "));
} else if (elname == "see") {
ret.Append(String.Concat(GetCref(xml["cref"]), xml["langword"]));
} else if (elname == "seealso") {
ret.Append(String.Concat("<b>", RTD("SeeAlso"), "</b> ", GetCref(xml["cref"]), xml["langword"]));
} else if (elname == "paramref") {
ret.Append(String.Concat("<i>", xml["name"], "</i>"));
} else if (elname == "param") {
ret.Append(String.Concat("<i>", xml["name"].Trim(), "</i>: "));
} else if (elname == "value") {
ret.Append(String.Concat("<b>", RTD("Value"), "</b> "));
} else if (elname == "summary") {
ret.Append(String.Concat("<b>", RTD("Summary"), "</b> "));
}
} else if (xml.NodeType == XmlNodeType.EndElement) {
string elname = xml.Name.ToLower();
if (elname == "para" || elname == "param") {
ret.Append("<br>");
}
if (elname == "exception") {
ret.Append("<br>");
}
} else if (xml.NodeType == XmlNodeType.Text) {
ret.Append(whitespace.Replace(xml.Value, " "));
}
} while(xml.Read());
} catch {
return doc;
}
return ret.ToString();
}
string GetCref(string cref)
{
if (cref == null) {
return String.Empty;
}
if (cref.Length < 2) {
return cref;
}
if (cref.Substring(1, 1) == ":") {
return String.Concat("<u>", cref.Substring(2, cref.Length - 2), "</u>");
}
return String.Concat("<u>", cref, "</u>");
}
string RT(string ResName)
{
return tree.ress.GetString(String.Concat("ObjectBrowser.Info.", ResName));
}
string RTD(string ResName)
{
return tree.ress.GetString(String.Concat("ObjectBrowser.Info.Doc.", ResName));
}
string ln(int rnr, string text)
{
return String.Concat("<a href='as://", rnr, "'>", text, "</a>");
}
bool CreateImage(Image pv)
{
try {
using (Bitmap b = new Bitmap(170, 170, PixelFormat.Format24bppRgb)) {
Graphics g = Graphics.FromImage(b);
g.FillRectangle(SystemBrushes.Control, 0, 0, 170, 170);
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(pv, 5, 5, 160, 160);
using (Brush brush = new SolidBrush(Color.FromArgb(220, SystemColors.Control))) {
g.FillRectangle(brush, 0, 0, 170, 170);
}
g.Dispose();
b.Save(imgPath, System.Drawing.Imaging.ImageFormat.Png);
}
return true;
} catch { return false; }
}
}
public class GradientLabel : Label
{
protected override void OnPaintBackground(PaintEventArgs pe)
{
base.OnPaintBackground(pe);
Graphics g = pe.Graphics;
g.FillRectangle(SystemBrushes.Control, pe.ClipRectangle);
using (Brush brush = new LinearGradientBrush(new Point(0, 0), new Point(Width, Height),
SystemColors.ControlLightLight,
SystemColors.Control)) {
g.FillRectangle(brush, new Rectangle(0, 0, Width, Height));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -