
import clr
import sys
import os
import System
from System import AppDomain

def inspect_dll(dll_path):
    print(f"Inspecting: {dll_path}")
    if not os.path.exists(dll_path):
        print("  File not found.")
        return

    try:
        ref = clr.AddReference(dll_path)
        print(f"  Loaded Assembly: {ref.FullName}")
        
        assembly = None
        for a in AppDomain.CurrentDomain.GetAssemblies():
             if a.FullName == ref.FullName:
                  assembly = a
                  break
        
        if not assembly:
            print("  Could not find assembly in AppDomain.")
            return

        results = []
        target_callbacks = ["AdmCallbacks", "RCallbacks", "REngine"]
        results.append("\n--- Detailed Member Check ---")
        for name in target_callbacks:
            t = assembly.GetType(f"com.omnesys.rapi.{name}")
            if not t: continue
            results.append(f"\n--- {t.FullName} ---")
            results.append(f"  IsAbstract: {t.IsAbstract}")
            results.append(f"  IsInterface: {t.IsInterface}")
            
            # Check for any abstract methods (including properties' get/set)
            for m in t.GetMethods(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static):
                if m.IsAbstract:
                    params = [f"{p.ParameterType.Name} {p.Name}" for p in m.GetParameters()]
                    results.append(f"  [ABSTRACT METHOD] {m.Name}({', '.join(params)})")
            
            for p in t.GetProperties():
                # Properties are abstract if their accessors are abstract
                is_abstract = False
                if p.GetMethod and p.GetMethod.IsAbstract: is_abstract = True
                if p.SetMethod and p.SetMethod.IsAbstract: is_abstract = True
                if is_abstract:
                    results.append(f"  [ABSTRACT PROPERTY] {p.Name} ({p.PropertyType.Name})")

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

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

if __name__ == "__main__":
    dll_dir = os.path.join(os.getcwd(), "libs")
    target_dll = os.path.join(dll_dir, "rapiplus.dll")
    sys.path.append(dll_dir)
    inspect_dll(target_dll)
