Zarch 1.0.3

dotnet add package Zarch --version 1.0.3
                    
NuGet\Install-Package Zarch -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Zarch" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zarch" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Zarch" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zarch --version 1.0.3
                    
#r "nuget: Zarch, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Zarch@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zarch&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Zarch&version=1.0.3
                    
Install as a Cake Tool

Zarch

C#的辅助语言,用于管理依赖,远程调用,热更新等。

  • 1.自动创建并注入使用Attribute标记的类的对象。
  • 2.用Zarch语言字符串控制被管理的对象的行为。
  • 3.网络传输的Zarch语言字符串以实现RPC功能。

Net Framework 使用

  • 导入NuGet包 点击 Project-Add NuGetPackages-搜索Zarch-勾选-Add Package

  • 使用Z命名空间 using Z;

非Visual Studio的用户,也可在这里下载DLL,在解决方案中编辑引用导入dll

Unity3D 使用

Get Started

Zarch Code

  • 分句符 ;
code ;
  • 赋值 =
y = x ;
  • 调用成员 .
user.name ;
  • 调用函数 [函数名(传入参数)]
say() ;
  • 注释标记 #
# 这是一条注释
  • 字符串(String) ''
x = '你好这是一条字符串';
  • 整数(Int)
x = 100 ;
  • 双精度小数(Double)
x = 0.75 ;
  • 浮点数
x = float(0.75) ;
  • 布尔型
x = bool(1) ;
  • 列表
x = list(1,2,3,4,5) ;
  • 字典
x.name = '小明' ; x.age = 15 ;
  • 委托代码块 {}
x = {print('hello');print(',world');} ;
  • 取委托符 []
# x.play()
y = [x.play]
  • 流程控制
if([条件(布尔值)],[条件为真执行的委托],[条件为假执行的委托])

示例

yes = {print('a = b');} ; no = {print('a != b')};
if(bool('x','x'),yes,no)
  • 循环语句
for([起始],[步长],[终止],[被循环的委托])

示例

for(0,1,100,[x.play])
  • 面向对象

Zarch Code

x = T(); x.play();
  • 内置函数
int(x);
str(x);
float(x);
double(x);
null();
bool(x);bool(a,b)
list(1,2,3,4,5);
for(start,step,end,delegate,parameters1,parameters2...)
if(condition,trueDelegate,falseDelegate,parameters1,parameters2)
print(a,b,c,d...)

Zarch in C Sharp

  • 在一切之前 需要使用命名空间 Z
using Z;
  • 执行 Zarch 代码
Zarch.code = Zarch代码
  • 自动注入标记
[ZarchBean]
  • 带有多层依赖的自动注入标记
[ZarchBean(依赖的对象的Zarch对象名)]
  • 注入一个类
Zarch.classes[ZarchCode类名]=typeof(C#类名)

在Zarch代码中实例化

Zarch.code = "x = ZarchCode类名();x.say();";
  • 手动注入对象
Zarch.objects[Zarch对象名] = CSharpObject对象
  • 手动获取对象
var obj = Zarch.objects[Zarch对象名];
  • 手动注入方法
Zarch.methods[Zarch方法名] = CSharpDelegate委托
  • 手动获取方法
Zarch.methods[Zarch方法名]
((Func<object[],object>)Zarch.methods[Zarch方法名])(parameters);
  • 手动调用一个Zarch中的方法
Zarch.call(Zarch方法名,参数1,参数2)
  • 手动唤起自动注入

用于当未使用Zarch.code时访问自动注入的对象

Zarch.init()
  • 手动刷新自动注入

用于当自动注入内容的多层依赖达到三层以上

Zarch.refresh()
  • 将Zarch代码中的方法提取成为C#委托

委托类型例如typeof(Action)

Zarch.CreateDelegate(ZarchCode方法名,C#委托类型)
  • 配置反射的程序集 默认Entry

Uninty3D是Executing,

.NetFramework是Entry,

反射指定的程序集(比如加载的Dll)ByContainedClass+设置那个程序集中包含的类,

调取方的程序集是Calling

Zarch.ReflectConfig.Assembly = ReflectHelper.AssemblyType.Entry;
//Zarch.ReflectConfig.ContainedClass = typeof(SomeClass); //如果是ByContainedClass则需要设置

以下是全部类型

public enum AssemblyType
{
        Entry ,
        Executing ,
        Calling ,
        ByContainedClass 
}

示例

  • 标准实体类

[ZarchBean]  // <-
public class User { 
  public string name = "小明"; 
  public void Say()
  { Console.Write( "你好我是" + name ); } }

public class MainClass{
    public static void Main(string[] args)
    { Zarch.code = "User.Say()"; } }  // <-
        

输出 你好我是小明

  • 多层依赖

[ZarchBean]  // <-
public class Engine 
{ public string name = "myEngine"; }

[ZarchBean("Engine")]  // <-
public class Car {
    Engine e;
        
    public void Info()
    { Console.WriteLine(e.name); } 
        
    public Car(Engine _e) { this.e = _e; } }
        
public class MainClass{
      public static void Main(string[] args)
      { Zarch.code = "Car.Info()"; } }  // <-
        

输出 myEngine

  • 多层依赖的手动注入

public class Engine 
{ public string name = "myEngine"; }

[ZarchBean("Engine")]  // <-
public class Car {
    Engine e;
        
    public void Info()
    { Console.WriteLine(e.name); } }
        
    public Car(Engine _e) { this.e = _e; }
        
public class MainClass{
    public static void Main(string[] args) { 
         Zarch.objects["Engine"] = new Engine();  // <-
         Zarch.code = "Car.Info()"; } }  // <-
        	

输出 myEngine

实用示例

using System;
using Z;
class MainClass{
    public static void Main(string[] args) {
        Zarch.methods["print"] = param => { print(param[0].ToString()); return null; };   // <-
        Zarch.methods["toStr"] = param => { return ToStringResult((bool)param[0]); };   // <-
        Zarch.code = "res = toStr(Connector.Connect());print(res);"; }  // <-

    public static string ToStringResult(bool res) {
        if (res) { return "Success"; }
        else { return "Error"; } }

    public static void print(string msg) {
        Console.WriteLine(msg);}
    }

[ZarchBean]  // <-
public class Config {
    public string host = "http://localhost:8080";
    public string name = "admin";
    public string password = "admin123"; } 

[ZarchBean("Config")]   // <-
public class Connector{
    Config config;
    public Connector(Config _config)
    { config = _config; }

    public bool Connect()
    { if (config.host != null) { return true; } return false; } }


版本

1.0.3 修复已知Bug,增加实例化对象功能,增加支持代码块、取委托,增加包含if和for在内的十个内置方法。

1.0.2 修复已知Bug,增加可赋值类型

1.0.1 增加简单自定义赋值功能

1.0.0 依赖管理

Product Compatible and additional computed target framework versions.
.NET Framework net47 is compatible.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.7

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 732 7/11/2019
1.0.2 603 7/10/2019
1.0.1 605 7/10/2019
1.0.0 605 7/9/2019