
import clr
import sys
import os
import System
from System import AppDomain
from System.Reflection import BindingFlags

def inspect_dll(dll_path):
    print(f"Inspecting: {dll_path}")
    try:
        clr.AddReference(dll_path)
        assembly = None
        for a in AppDomain.CurrentDomain.GetAssemblies():
            if "rapiplus" in a.FullName.lower():
                assembly = a
                break
        
        if not assembly:
            print("Assembly not found.")
            return

        t = assembly.GetType("com.omnesys.rapi.AdmCallbacks")
        if not t:
            print("com.omnesys.rapi.AdmCallbacks not found.")
            return

        results = []
        results.append(f"Class: {t.FullName}")
        results.append(f"IsAbstract: {t.IsAbstract}")
        results.append(f"BaseType: {t.BaseType.FullName if t.BaseType else 'None'}")
        
        results.append("\n--- Interfaces ---")
        for i in t.GetInterfaces():
            results.append(f"  Interface: {i.FullName}")

        results.append("\n--- All Methods (Public & Non-Public, Instance & Static) ---")
        # すべてのメソッドをチェック
        for m in t.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy):
            kind = ""
            if m.IsAbstract: kind += "[ABSTRACT] "
            if m.IsVirtual: kind += "[VIRTUAL] "
            if m.IsStatic: kind += "[STATIC] "
            if m.IsFinal: kind += "[FINAL] "
            
            params = [f"{p.ParameterType.Name} {p.Name}" for p in m.GetParameters()]
            results.append(f"  {kind}{m.Name}({', '.join(params)}) returning {m.ReturnType.Name}")

        results.append("\n--- All Properties ---")
        for p in t.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static):
            results.append(f"  Property: {p.Name} ({p.PropertyType.Name})")

        with open("inspect_adm_full.txt", "w") as f:
            f.write("\n".join(results))
        print("Done. Results in inspect_adm_full.txt")

    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    dll_path = os.path.join(os.getcwd(), "libs", "rapiplus.dll")
    inspect_dll(dll_path)
