[C#] GTK#으로 타입의 데이터를 확인하는 프로그램을 작성했는데 제대로 동작하지 않습니다.

HDNua의 이미지

MonoDevelop 툴, Gtk# 2.0을 사용하고 있습니다.
프로젝트 작성할 때 Empty Project로 선택하고 Gtk# Support 체크한 후
Reference에 atk-sharp, gdk-sharp, glib-sharp, gtk-sharp를 추가하였습니다.

ILogger.cs

using System;
 
namespace ReflectionTest
{
    public interface ILogger
    {
        void PrintInterfaces(Type type);
        void PrintFields(Type type);
        void PrintProperties(Type type);
        void PrintEvents(Type type);
        void PrintMethods(Type type);
    }
}

ConsoleLogger.cs

using System;
using System.Reflection;
 
namespace ReflectionTest
{
    public class ConsoleLogger: ILogger
    {
        // constructor
        public ConsoleLogger ()
        {
        }
 
        // interface: ILogger
        void ILogger.PrintInterfaces (Type type)
        {
            Console.WriteLine ("--- Interfaces ---");
 
            Type[] interfaces = type.GetInterfaces ();
            foreach (Type i in interfaces)
                Console.WriteLine ("Name: {0}", i.Name);
            Console.WriteLine ();
        }
        void ILogger.PrintFields (Type type)
        {
            Console.WriteLine ("--- Fields ---");
 
            FieldInfo[] fields = type.GetFields ();
            foreach (FieldInfo f in fields) 
            {
                string access = "protected";
                if (f.IsPublic) access = "public";
                else if (f.IsPrivate) access = "private";
 
                Console.Write ("{0} ", access);
                Console.Write ("{0}", f.FieldType.Name);
                Console.WriteLine ("{0} ", f.Name);
            }
            Console.WriteLine ();
        }
        void ILogger.PrintProperties (Type type)
        {
            Console.WriteLine ("--- Properties ---");
 
            PropertyInfo[] props = type.GetProperties ();
            foreach (PropertyInfo p in props) 
            {
                Console.WriteLine ("{0} {1}",
                                   p.PropertyType.Name, p.Name);
            }
            Console.WriteLine();
        }
        void ILogger.PrintEvents (Type type)
        {
            Console.WriteLine ("--- Events ---");
 
            EventInfo[] events = type.GetEvents ();
            foreach (EventInfo e in events) 
            {
                Console.WriteLine ("{0}", e.Name);
            }
            Console.WriteLine ();
        }
        void ILogger.PrintMethods (Type type)
        {
            Console.WriteLine ("--- Methods ---");
 
            MethodInfo[] methods = type.GetMethods ();
            foreach (MethodInfo m in methods)
            {
                Console.Write("{0} {1} (",
                                  m.ReturnType, m.Name);
                ParameterInfo[] parameters = 
                    m.GetParameters();
                for (int i=0; i<parameters.Length; ++i)
                {
                    Console.Write ("{0}", parameters[i]);
                    if (i<parameters.Length-1)
                        Console.Write (", ");
                }
                Console.WriteLine (")");
            }
            Console.WriteLine ();
        }
    }
}

StringLogger.cs

using System;
using System.Reflection;
 
namespace ReflectionTest
{
    public class StringLogger: ILogger
    {
        string log;
        public string Log{ get { return log; } }
 
        // constructor
        public StringLogger (Type type)
        {
            log = "";
 
            PrintInterfaces(type);
            PrintFields(type);
            PrintProperties(type);
            PrintEvents(type);
            PrintMethods(type);
        }
 
        // methods
        public void Add (string str)
        {
            log += str;
        }
        public void Add (string str, params object[] args)
        {
            log += string.Format (str, args);
        }
        public void AddLine ()
        {
            log += '\n';
        }
        public void AddLine (string str)
        {
            Add (str);
            AddLine ();
        }
        public void AddLine (string str, params object[] args)
        {
            Add (str, args);
            AddLine ();
        }
 
        // interface: ILogger
        public void PrintInterfaces (Type type)
        {
            AddLine ("--- Interfaces ---");
 
            Type[] interfaces = type.GetInterfaces ();
            foreach (Type i in interfaces)
                AddLine ("Name: {0}", i.Name);
            AddLine ();
        }
        public void PrintFields (Type type)
        {
            AddLine ("--- Fields ---");
 
            FieldInfo[] fields = type.GetFields ();
            foreach (FieldInfo f in fields) 
            {
                string access = "protected";
                if (f.IsPublic) access = "public";
                else if (f.IsPrivate) access = "private";
 
                Add ("{0} ", access);
                Add ("{0}", f.FieldType.Name);
                AddLine ("{0} ", f.Name);
            }
            AddLine ();
        }
        public void PrintProperties (Type type)
        {
            AddLine ("--- Properties ---");
 
            PropertyInfo[] props = type.GetProperties ();
            foreach (PropertyInfo p in props) 
            {
                AddLine ("{0} {1}",
                                   p.PropertyType.Name, p.Name);
            }
            AddLine();
        }
        public void PrintEvents (Type type)
        {
            AddLine ("--- Events ---");
 
            EventInfo[] events = type.GetEvents ();
            foreach (EventInfo e in events) 
            {
                AddLine ("{0}", e.Name);
            }
            AddLine ();
        }
        public void PrintMethods (Type type)
        {
            AddLine ("--- Methods ---");
 
            MethodInfo[] methods = type.GetMethods ();
            foreach (MethodInfo m in methods)
            {
                Add("{0} {1} (",
                              m.ReturnType, m.Name);
                ParameterInfo[] parameters = 
                    m.GetParameters();
                for (int i=0; i<parameters.Length; ++i)
                {
                    Add ("{0}", parameters[i]);
                    if (i<parameters.Length-1)
                        Add (", ");
                }
                AddLine (")");
            }
            AddLine ();
        }
    }
}

SharpApp.cs

using System;
using System.Reflection;
 
namespace PrintWidgetEvent
{
    public class SharpApp: Gtk.Window
    {
        SharpApp self;
        Gtk.Entry entry;
        Gtk.Label label;
        Gtk.Button button;
 
        public SharpApp(): base("Widget's event")
        {
            self = this;
 
            SetDefaultSize (250, 200);
            SetPosition(Gtk.WindowPosition.Center);
            DeleteEvent += (o, args) => Gtk.Application.Quit ();
 
            // create vertical box
            Gtk.VBox vbox = new Gtk.VBox(false, 2);
 
            // create vertical alignment
            //  and put it into vbox
            Gtk.Alignment valign
                = new Gtk.Alignment(0, 0, 1, 0);
            vbox.Add (valign);
 
            // create another box
            //  that can pack two or more widgets
            Gtk.VBox vbox2 = new Gtk.VBox(false, 2);
            valign.Add (vbox2);
 
            // create entry
            //  and put it into vbox2
            entry = new Gtk.Entry();
            vbox2.Add (entry);
 
            // create button
            //  and put it into vbox2
            button = new Gtk.Button("Press!");
            button.Pressed += OnButtonPressed;
            vbox2.Add (button);
 
            // create label
            //  and put it into vbox2
            label = new Gtk.Label("Test");
            label.SetAlignment(0, 0);
            label.CanFocus = true;
            vbox2.Add (label);
 
            // add vbox to window
            Add (vbox);
 
            // test
            Console.WriteLine ("Type: {0}", this.button.GetType ());
 
            // show all widgets in window
            ShowAll ();
        }
 
        // event handler
        public void OnButtonPressed (object o, EventArgs args)
        {
            if (entry.Text == "") {
                label.Text = "Entry is null";
                return;
            }
 
            string typestr = entry.Text;
            System.Type type = System.Type.GetType (typestr);
            if (type == null) {
                label.Text = "Type does not exist";
                return;
            }
 
            ReflectionTest.StringLogger slgr 
                = new ReflectionTest.StringLogger(type);
            label.Text = "Printed";
//            label.Text = slgr.Log;
 
            Console.WriteLine ("{0}", entry.Text);
            Console.WriteLine (slgr.Log);
//            self.SetPosition (Gtk.WindowPosition.Center);
        }
 
        // main
        public static void Main(string[] args)
        {
            Gtk.Application.Init ();
            new SharpApp();
            Gtk.Application.Run ();
        }
    }
}

System, 제가 만든 네임스페이스에 대해서는 제대로 동작하는 것 같은데
유독 Gtk 네임스페이스에 대해서만 제대로 동작을 안 하고 있네요.
도움 부탁드립니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.