Example #1
0
        public PythonClass(Type type, XDocument xmlDoc = null)
        {
            if (xmlDoc != null)
            {
                this.xmlDoc = new DocParser(xmlDoc);
            }
            className = type;
            ctr       = new PythonConstructor(this);
            if (type.BaseType != null)
            {
                parentClasses.Add(type.BaseType);
            }
            parentClasses.AddRange(type.GetInterfaces());

            foreach (MemberInfo member in type.GetMembers(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                Add(member, true);
            }

            foreach (MemberInfo member in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                Add(member, false);
            }
        }
Example #2
0
 public void Add(MemberInfo member, bool isStatic = false)
 {
     if (member is FieldInfo || member is PropertyInfo)
     {
         if (member is FieldInfo field)
         {
             if (isStatic)
             {
                 staticFields.Add(new PythonStaticField(this, field));
             }
             else
             {
                 fields.Add(new PythonField(this, field));
             }
         }
         if (member is PropertyInfo prop)
         {
             if (isStatic)
             {
                 staticFields.Add(new PythonStaticField(this, prop));
             }
             else
             {
                 fields.Add(new PythonField(this, prop));
             }
         }
     }
     else if (member is MethodInfo method)
     {
         if (!method.Name.StartsWith("set_") &&
             !method.Name.StartsWith("get_") &&
             !method.Name.StartsWith("add_") &&
             !method.Name.StartsWith("remove_"))
         {
             if (isStatic)
             {
                 staticMethods.Add(new PythonStaticMethod(this, method));
             }
             else
             {
                 methods.Add(new PythonMethod(this, method));
             }
         }
     }
     else if (member is ConstructorInfo ctr)
     {
         this.ctr = new PythonConstructor(this, ctr);
     }
     else if (member is EventInfo ev)
     {
         events.Add(new PythonEvent(this, ev));
     }
     else if (member is Type)
     {
         //TODO add child classes
         Console.WriteLine("child class found " + member);
     }
     else
     {
         throw new Exception("unsupported member " + member);
     }
 }
Example #3
0
 public void Set(PythonConstructor constructor)
 {
     ctr = constructor;
 }