Skip to content

Repository files navigation

Mono4J

Java bindings for Mono runtime via JNA.

通过 JNA 实现的 Mono 运行时 Java 绑定。

Features / 功能

  • Load and execute .NET assemblies from Java / 从 Java 加载和执行 .NET 程序集
  • Call C# methods and access fields/properties / 调用 C# 方法并访问字段/属性
  • Type conversion between Java and C# / Java 与 C# 之间的类型转换
  • Exception handling / 异常处理
  • Thread management / 线程管理
  • JIT compilation control / JIT 编译控制

Requirements / 依赖

  • Java 11+
  • Mono 6.12.0.199
  • JNA 5.13.0+

Quick Start / 快速开始

import starray.java.mono4j.*;
public class Main {
    static void main() {
        // Initialize Mono runtime / 初始化 Mono 运行时
        MonoRuntime.initialize();

        // Initialize JIT domain with assembly search path
        // 初始化 JIT 域并设置程序集搜索路径
        MonoDomain domain = MonoDomain.init("my-app", "C:\\Program Files\\Mono\\lib\\mono\\4.5");

        // Load assembly / 加载程序集
        MonoAssembly assembly = domain.openAssembly("MyApp.exe");

        // Execute entry point / 执行入口点
        int exitCode = assembly.exec();

        // Or get class and invoke methods / 或获取类并调用方法
        MonoImage image = assembly.getImage();
        MonoClass klass = image.getClass("MyNamespace", "MyClass");
        MonoMethod method = klass.getMethod("MyMethod", 0);
        MonoObject result = method.invoke(null);
    }
}

API Overview / API 概览

Core Classes / 核心类

Class Description
MonoRuntime Runtime initialization and info / 运行时初始化和信息
MonoDomain Application domain management / 应用程序域管理
MonoAssembly Assembly loading and execution / 程序集加载和执行
MonoImage Assembly metadata image / 程序集元数据镜像
MonoClass Class information and member access / 类信息和成员访问
MonoMethod Method invocation / 方法调用
MonoField Field access / 字段访问
MonoProperty Property access / 属性访问
MonoObject Base object wrapper / 基础对象包装
MonoString String handling / 字符串处理
MonoArray Array operations / 数组操作
MonoThread Thread management / 线程管理
MonoException Exception handling / 异常处理

Primitive Types / 基础类型

  • CSharpInt16, CSharpInt32, CSharpInt64
  • CSharpUInt32
  • CSharpSingle, CSharpDouble
  • CSharpBoolean, CSharpByte, CSharpChar
  • CSharpEnum

Building / 构建

./gradlew build

Testing / 测试

./gradlew test

License / 许可证

GPLv3

Third Party Libraries / 第三方库


Note: Part of the code was generated with assistance from Claude (Anthropic).

注:部分代码由 Claude Opus 4.5 (Anthropic) 辅助生成。

About

mono api binding in java

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages