修复一些内容
This commit is contained in:
Submodule Convention/[RScript] updated: 52e8e85542...d3e21cad15
@@ -1,12 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Runtime.Serialization;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Xml;
|
||||||
|
|
||||||
namespace Convention
|
namespace Convention
|
||||||
{
|
{
|
||||||
@@ -79,6 +80,39 @@ namespace Convention
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 序列化
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static byte[] Serialize<T>(T obj)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(obj);
|
||||||
|
|
||||||
|
using var memoryStream = new MemoryStream();
|
||||||
|
DataContractSerializer ser = new DataContractSerializer(typeof(T));
|
||||||
|
ser.WriteObject(memoryStream, obj);
|
||||||
|
var data = memoryStream.ToArray();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 反序列化
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static T Deserialize<T>(byte[] data)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(data);
|
||||||
|
|
||||||
|
using var memoryStream = new MemoryStream(data);
|
||||||
|
XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(memoryStream, new XmlDictionaryReaderQuotas());
|
||||||
|
DataContractSerializer ser = new DataContractSerializer(typeof(T));
|
||||||
|
var result = (T)ser.ReadObject(reader, true);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static object SeekValue(object obj, string name, BindingFlags flags, out bool isSucceed)
|
public static object SeekValue(object obj, string name, BindingFlags flags, out bool isSucceed)
|
||||||
{
|
{
|
||||||
Type type = obj.GetType();
|
Type type = obj.GetType();
|
||||||
@@ -409,5 +443,25 @@ namespace Convention
|
|||||||
{
|
{
|
||||||
return DateTime.Now.ToString(format);
|
return DateTime.Now.ToString(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class EnumerableClass : IEnumerable
|
||||||
|
{
|
||||||
|
private readonly IEnumerator ir;
|
||||||
|
|
||||||
|
public EnumerableClass(IEnumerator ir)
|
||||||
|
{
|
||||||
|
this.ir = ir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator GetEnumerator()
|
||||||
|
{
|
||||||
|
return ir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable AsEnumerable(this IEnumerator ir)
|
||||||
|
{
|
||||||
|
return new EnumerableClass(ir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
using Convention.RScript;
|
using Convention;
|
||||||
|
using Convention.EasySave;
|
||||||
|
using Convention.RScript;
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
@@ -21,7 +24,9 @@ public class Program
|
|||||||
typeof(ExpressionMath),
|
typeof(ExpressionMath),
|
||||||
typeof(Test)
|
typeof(Test)
|
||||||
};
|
};
|
||||||
var result = engine.Run(@"
|
|
||||||
|
/*
|
||||||
|
var result = engine.Compile(@"
|
||||||
int i= 2;
|
int i= 2;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
label(test);
|
label(test);
|
||||||
@@ -44,6 +49,8 @@ namespace(func1)
|
|||||||
|
|
||||||
label(end);
|
label(end);
|
||||||
", import);
|
", import);
|
||||||
Console.WriteLine($"Script executed successfully. Result: {result["i"].data}");
|
*/
|
||||||
|
//EasySave.Save("data", result, "F:\\test.json");
|
||||||
|
var result = engine.Run(EasySave.Load<RScriptContext.SerializableClass>("data", "F:\\test.json"), import);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user