18个文件已修改
13个文件已删除
4 文件已复制
6个文件已添加
1 文件已重命名
New file |
| | |
| | | #if UNITY_EDITOR |
| | | using UnityEditor; |
| | | using UnityEngine; |
| | | using System; |
| | | [System.Reflection.Obfuscation(Exclude = true)] |
| | | public class ILRuntimeCrossBinding : EditorWindow |
| | | { |
| | | [MenuItem("ILRuntime/生成跨域继承适配器")] |
| | | public static void ShowWindow() |
| | | { |
| | | EditorWindow.GetWindow<ILRuntimeCrossBinding>("生成跨域继承适配器").Show(); |
| | | } |
| | | |
| | | Type type = typeof(MonoBehaviour); |
| | | |
| | | private void OnGUI() |
| | | { |
| | | EditorGUILayout.Space(); |
| | | EditorGUILayout.Space(); |
| | | EditorGUILayout.Space(); |
| | | EditorGUILayout.Space(); |
| | | GUILayout.Label(string.Format("类名:{0}", type.Name)); |
| | | EditorGUILayout.Space(); |
| | | |
| | | if (GUILayout.Button("生成")) |
| | | { |
| | | GenerateCrossbindAdapter(); |
| | | } |
| | | } |
| | | |
| | | void GenerateCrossbindAdapter() |
| | | { |
| | | var path = "Assets/ILRuntime/Src/Inheritance/{0}Adapter.cs"; |
| | | using (System.IO.StreamWriter sw = new System.IO.StreamWriter(string.Format(path, type.Name))) |
| | | { |
| | | sw.WriteLine(ILRuntime.Runtime.Enviorment.CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(type, "ILRuntimeDemo")); |
| | | } |
| | | AssetDatabase.Refresh(); |
| | | } |
| | | } |
| | | #endif |
copy from Assets/Plugins/LitJson/Netstandard15Polyfill.cs.meta
copy to Assets/ILRuntime/Editor/ILRuntimeCrossBinding.cs.meta
File was copied from Assets/Plugins/LitJson/Netstandard15Polyfill.cs.meta |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 155770190c61cbb4dbbde393aec4c23e |
| | | guid: 077d29cbd51762b43bf8163a1b0df776 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | |
| | | { |
| | | class CLRBindings |
| | | { |
| | | |
| | | |
| | | /// <summary> |
| | | /// Initialize the CLR binding, please invoke this AFTER CLR Redirection registration |
| | | /// </summary> |
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Runtime.InteropServices; |
| | | |
| | | using ILRuntime.CLR.TypeSystem; |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using ILRuntime.Runtime.Stack; |
| | | using ILRuntime.Reflection; |
| | | using ILRuntime.CLR.Utils; |
| | | |
| | | namespace ILRuntime.Runtime.Generated |
| | | { |
| | | unsafe class UnityEngine_GameObject_Binding |
| | | { |
| | | public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app) |
| | | { |
| | | BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly; |
| | | MethodBase method; |
| | | Type[] args; |
| | | Type type = typeof(UnityEngine.GameObject); |
| | | args = new Type[]{typeof(System.String)}; |
| | | method = type.GetMethod("GetComponent", flag, null, args, null); |
| | | app.RegisterCLRMethodRedirection(method, GetComponent_0); |
| | | Dictionary<string, List<MethodInfo>> genericMethods = new Dictionary<string, List<MethodInfo>>(); |
| | | List<MethodInfo> lst = null; |
| | | foreach(var m in type.GetMethods()) |
| | | { |
| | | if(m.IsGenericMethodDefinition) |
| | | { |
| | | if (!genericMethods.TryGetValue(m.Name, out lst)) |
| | | { |
| | | lst = new List<MethodInfo>(); |
| | | genericMethods[m.Name] = lst; |
| | | } |
| | | lst.Add(m); |
| | | } |
| | | } |
| | | args = new Type[]{typeof(UnityEngine.UI.Button)}; |
| | | if (genericMethods.TryGetValue("GetComponent", out lst)) |
| | | { |
| | | foreach(var m in lst) |
| | | { |
| | | if(m.MatchGenericParameters(args, typeof(UnityEngine.UI.Button))) |
| | | { |
| | | method = m.MakeGenericMethod(args); |
| | | app.RegisterCLRMethodRedirection(method, GetComponent_1); |
| | | |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | args = new Type[]{typeof(UnityEngine.UI.Text)}; |
| | | if (genericMethods.TryGetValue("GetComponent", out lst)) |
| | | { |
| | | foreach(var m in lst) |
| | | { |
| | | if(m.MatchGenericParameters(args, typeof(UnityEngine.UI.Text))) |
| | | { |
| | | method = m.MakeGenericMethod(args); |
| | | app.RegisterCLRMethodRedirection(method, GetComponent_2); |
| | | |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | static StackObject* GetComponent_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj) |
| | | { |
| | | ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; |
| | | StackObject* ptr_of_this_method; |
| | | StackObject* __ret = ILIntepreter.Minus(__esp, 2); |
| | | |
| | | ptr_of_this_method = ILIntepreter.Minus(__esp, 1); |
| | | System.String @type = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); |
| | | __intp.Free(ptr_of_this_method); |
| | | |
| | | ptr_of_this_method = ILIntepreter.Minus(__esp, 2); |
| | | UnityEngine.GameObject instance_of_this_method = (UnityEngine.GameObject)typeof(UnityEngine.GameObject).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); |
| | | __intp.Free(ptr_of_this_method); |
| | | |
| | | var result_of_this_method = instance_of_this_method.GetComponent(@type); |
| | | |
| | | return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method); |
| | | } |
| | | |
| | | static StackObject* GetComponent_1(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj) |
| | | { |
| | | ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; |
| | | StackObject* ptr_of_this_method; |
| | | StackObject* __ret = ILIntepreter.Minus(__esp, 1); |
| | | |
| | | ptr_of_this_method = ILIntepreter.Minus(__esp, 1); |
| | | UnityEngine.GameObject instance_of_this_method = (UnityEngine.GameObject)typeof(UnityEngine.GameObject).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); |
| | | __intp.Free(ptr_of_this_method); |
| | | |
| | | var result_of_this_method = instance_of_this_method.GetComponent<UnityEngine.UI.Button>(); |
| | | |
| | | return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method); |
| | | } |
| | | |
| | | static StackObject* GetComponent_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj) |
| | | { |
| | | ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; |
| | | StackObject* ptr_of_this_method; |
| | | StackObject* __ret = ILIntepreter.Minus(__esp, 1); |
| | | |
| | | ptr_of_this_method = ILIntepreter.Minus(__esp, 1); |
| | | UnityEngine.GameObject instance_of_this_method = (UnityEngine.GameObject)typeof(UnityEngine.GameObject).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); |
| | | __intp.Free(ptr_of_this_method); |
| | | |
| | | var result_of_this_method = instance_of_this_method.GetComponent<UnityEngine.UI.Text>(); |
| | | |
| | | return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | } |
copy from Assets/Plugins/LitJson/Netstandard15Polyfill.cs.meta
copy to Assets/ILRuntime/Generated/UnityEngine_GameObject_Binding.cs.meta
File was copied from Assets/Plugins/LitJson/Netstandard15Polyfill.cs.meta |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 155770190c61cbb4dbbde393aec4c23e |
| | | guid: 9ddc23a444a3d9243abc9d888542bd1a |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
New file |
| | |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using UnityEngine; |
| | | |
| | | public class ILBehaviour : WidgetBehavior |
| | | { |
| | | [Tooltip("Logic工程的代码,例:命名空间.类名")] |
| | | public string className; |
| | | ILTypeInstance obj; |
| | | |
| | | IMethod awake, start, onEnable, onDisable, update, fixedUpdate, lateUpdate, onDestroy; |
| | | |
| | | AppDomain appDomain { |
| | | get { return ILRuntimeUtility.Instance.appDomain; } |
| | | } |
| | | |
| | | public object ILInstance { |
| | | get { return obj; } |
| | | } |
| | | |
| | | private void Init() |
| | | { |
| | | InitWidgts(); |
| | | obj = appDomain.Instantiate(className, new object[] { this }); |
| | | var baseType = appDomain.LoadedTypes["LogicProject.BaseILBehaviour"]; |
| | | if (obj == null) |
| | | { |
| | | DebugEx.LogErrorFormat("ILBehaviour �ȸ����벻���ڣ�{0}", className); |
| | | return; |
| | | } |
| | | var type = obj.Type; |
| | | awake = type.GetMethod("Awake"); |
| | | start = type.GetMethod("Start"); |
| | | onEnable = type.GetMethod("OnEnable"); |
| | | onDisable = type.GetMethod("OnDisable"); |
| | | update = type.GetMethod("Update"); |
| | | fixedUpdate = type.GetMethod("FixedUpdate"); |
| | | lateUpdate = type.GetMethod("LateUpdate"); |
| | | onDestroy = baseType.GetMethod("OnDestroy",0); |
| | | } |
| | | |
| | | private void Awake() |
| | | { |
| | | Init(); |
| | | if (awake != null) |
| | | appDomain.Invoke(awake, obj); |
| | | } |
| | | |
| | | private void Start() |
| | | { |
| | | if (start != null) |
| | | appDomain.Invoke(start, obj); |
| | | } |
| | | |
| | | private void OnEnable() |
| | | { |
| | | if (onEnable != null) |
| | | appDomain.Invoke(onEnable, obj); |
| | | } |
| | | |
| | | private void OnDisable() |
| | | { |
| | | if (onDisable != null) |
| | | appDomain.Invoke(onDisable, obj); |
| | | } |
| | | |
| | | private void Update() |
| | | { |
| | | if (update != null) |
| | | appDomain.Invoke(update, obj); |
| | | } |
| | | |
| | | private void FixedUpdate() |
| | | { |
| | | if (fixedUpdate != null) |
| | | appDomain.Invoke(fixedUpdate, obj); |
| | | } |
| | | |
| | | private void LateUpdate() |
| | | { |
| | | if (lateUpdate != null) |
| | | appDomain.Invoke(lateUpdate, obj); |
| | | } |
| | | |
| | | private void OnDestroy() |
| | | { |
| | | if (onDestroy != null) |
| | | appDomain.Invoke(onDestroy, obj); |
| | | awake = null; |
| | | start = null; |
| | | onEnable = null; |
| | | onDisable = null; |
| | | update = null; |
| | | fixedUpdate = null; |
| | | lateUpdate = null; |
| | | onDestroy = null; |
| | | obj = null; |
| | | } |
| | | |
| | | } |
copy from Assets/Plugins/LitJson/Netstandard15Polyfill.cs.meta
copy to Assets/ILRuntime/Src/ILBehaviour.cs.meta
File was copied from Assets/Plugins/LitJson/Netstandard15Polyfill.cs.meta |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 155770190c61cbb4dbbde393aec4c23e |
| | | guid: 989c3eeebc5c0d64eb1689f9710ba192 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | |
| | | using System; |
| | | using System.IO; |
| | | using ILRuntime.Mono.Cecil.Pdb; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | |
| | | class ILRuntimeUtility : SingletonMonobehaviour<ILRuntimeUtility> |
| | | { |
| | | private AppDomain appdomain; |
| | | public const string NameSpace = "LogicProject"; |
| | | |
| | | FileStream dllFS, pdbFS; |
| | | |
| | | private ILRuntime.Runtime.Enviorment.AppDomain _appdomain; |
| | | |
| | | public ILRuntime.Runtime.Enviorment.AppDomain appDomain |
| | | { |
| | | get { return _appdomain; } |
| | | } |
| | | |
| | | public void Init() |
| | | { |
| | | LoadILRuntime(); |
| | | #if DEBUG && (UNITY_EDITOR || UNITY_ANDROID || UNITY_IPHONE) |
| | | //由于Unity的Profiler接口只允许在主线程使用,为了避免出异常,需要告诉ILRuntime主线程的线程ID才能正确将函数运行耗时报告给Profiler |
| | | _appdomain.UnityMainThreadID = System.Threading.Thread.CurrentThread.ManagedThreadId; |
| | | #endif |
| | | //对LitJson进行注册 |
| | | LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(_appdomain); |
| | | } |
| | | |
| | | void LoadILRuntime() |
| | | { |
| | | appdomain = new AppDomain(); |
| | | _appdomain = new ILRuntime.Runtime.Enviorment.AppDomain(); |
| | | var dllPath = string.Empty; |
| | | var pdbPath = string.Empty; |
| | | if (AssetSource.refdataFromEditor) |
| | |
| | | dllPath = AssetVersionUtility.GetAssetFilePath("logic/Logic.dll.bytes"); |
| | | pdbPath = AssetVersionUtility.GetAssetFilePath("logic/Logic.pdb"); |
| | | } |
| | | var fs = new FileStream(dllPath, FileMode.Open); |
| | | var p = new FileStream(pdbPath, FileMode.Open); |
| | | appdomain.LoadAssembly(fs, p, new PdbReaderProvider()); |
| | | if (!File.Exists(dllPath)) |
| | | { |
| | | DebugEx.LogErrorFormat("找不到热更代码:{0}", dllPath); |
| | | return; |
| | | } |
| | | |
| | | dllFS = new FileStream(dllPath, FileMode.Open); |
| | | if (File.Exists(pdbPath)) |
| | | pdbFS = new FileStream(pdbPath, FileMode.Open); |
| | | |
| | | _appdomain.LoadAssembly(dllFS, pdbFS, new PdbReaderProvider()); |
| | | } |
| | | |
| | | public void LaunchStart() |
| | | { |
| | | appdomain.Invoke("GameLogicMgr", "Init", null, null); |
| | | _appdomain.Invoke(NameSpace + ".GameLogicMgr", "Init", null, null); |
| | | } |
| | | |
| | | protected override void OnDestroy() |
| | | { |
| | | base.OnDestroy(); |
| | | dllFS?.Close(); |
| | | pdbFS?.Close(); |
| | | } |
| | | } |
New file |
| | |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using Snxxz.UI; |
| | | using UnityEngine; |
| | | |
| | | public class ILWindow : Window |
| | | { |
| | | ILTypeInstance obj; |
| | | |
| | | IMethod bindController, addListeners, onPreOpen, onAfterOpen, onPreClose, onAfterClose, onDestroy, lateUpdate, onActived; |
| | | |
| | | AppDomain appDomain |
| | | { |
| | | get { return ILRuntimeUtility.Instance.appDomain; } |
| | | } |
| | | private void Init() |
| | | { |
| | | //使用与预制同名的代码文件 |
| | | var windowName = string.Format("{0}.{1}", ILRuntimeUtility.NameSpace, gameObject.name); |
| | | obj = appDomain.Instantiate(windowName, new object[] { this }); |
| | | if (obj == null) |
| | | { |
| | | DebugEx.LogErrorFormat("ILWindow 热更代码不存在:{0}", windowName); |
| | | return; |
| | | } |
| | | var type = obj.Type; |
| | | bindController = type.GetMethod("BindController"); |
| | | addListeners = type.GetMethod("AddListeners"); |
| | | onPreOpen = type.GetMethod("OnPreOpen"); |
| | | onAfterOpen = type.GetMethod("OnAfterOpen"); |
| | | onPreClose = type.GetMethod("OnPreClose"); |
| | | onAfterClose = type.GetMethod("OnAfterClose"); |
| | | onDestroy = type.GetMethod("OnDestroy"); |
| | | |
| | | lateUpdate = type.GetMethod("LateUpdate"); |
| | | onActived = type.GetMethod("OnActived"); |
| | | } |
| | | |
| | | protected override void OnActived() |
| | | { |
| | | if (onActived != null) |
| | | appDomain.Invoke(onActived, obj); |
| | | } |
| | | |
| | | protected override void LateUpdate() |
| | | { |
| | | if (lateUpdate != null) |
| | | appDomain.Invoke(lateUpdate, obj); |
| | | } |
| | | |
| | | protected override void BindController() |
| | | { |
| | | Init(); |
| | | if (bindController != null) |
| | | appDomain.Invoke(bindController, obj); |
| | | } |
| | | protected override void AddListeners() |
| | | { |
| | | if (addListeners != null) |
| | | appDomain.Invoke(addListeners, obj); |
| | | } |
| | | protected override void OnPreOpen() |
| | | { |
| | | if (onPreOpen != null) |
| | | appDomain.Invoke(onPreOpen, obj); |
| | | } |
| | | protected override void OnAfterOpen() |
| | | { |
| | | if (onAfterOpen != null) |
| | | appDomain.Invoke(onAfterOpen, obj); |
| | | } |
| | | protected override void OnPreClose() |
| | | { |
| | | if (onPreClose != null) |
| | | appDomain.Invoke(onPreClose, obj); |
| | | } |
| | | protected override void OnAfterClose() |
| | | { |
| | | if (onAfterClose != null) |
| | | appDomain.Invoke(onAfterClose, obj); |
| | | } |
| | | |
| | | private void OnDestroy() |
| | | { |
| | | if (onDestroy != null) |
| | | appDomain.Invoke(onDestroy, obj); |
| | | bindController = null; |
| | | addListeners = null; |
| | | onPreOpen = null; |
| | | onAfterOpen = null; |
| | | onPreClose = null; |
| | | onAfterClose = null; |
| | | onDestroy = null; |
| | | lateUpdate = null; |
| | | onActived = null; |
| | | obj = null; |
| | | } |
| | | |
| | | } |
copy from Assets/Plugins/LitJson/Netstandard15Polyfill.cs.meta
copy to Assets/ILRuntime/Src/ILWindow.cs.meta
File was copied from Assets/Plugins/LitJson/Netstandard15Polyfill.cs.meta |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 155770190c61cbb4dbbde393aec4c23e |
| | | guid: 2a213fa9936d841438d8bfb460783b93 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
New file |
| | |
| | | fileFormatVersion: 2 |
| | | guid: a36d462b97cf6824cb7d430aaeb583f7 |
| | | folderAsset: yes |
| | | DefaultImporter: |
| | | externalObjects: {} |
| | | userData: |
| | | assetBundleName: |
| | | assetBundleVariant: |
New file |
| | |
| | | using System; |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.Runtime.Enviorment; |
| | | using ILRuntime.Runtime.Intepreter; |
| | | |
| | | namespace ILRuntimeDemo |
| | | { |
| | | public class MonoBehaviourAdapter : CrossBindingAdaptor |
| | | { |
| | | public override Type BaseCLRType |
| | | { |
| | | get |
| | | { |
| | | return typeof(UnityEngine.MonoBehaviour); |
| | | } |
| | | } |
| | | |
| | | public override Type AdaptorType |
| | | { |
| | | get |
| | | { |
| | | return typeof(Adapter); |
| | | } |
| | | } |
| | | |
| | | public override object CreateCLRInstance(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) |
| | | { |
| | | return new Adapter(appdomain, instance); |
| | | } |
| | | |
| | | public class Adapter : UnityEngine.MonoBehaviour, CrossBindingAdaptorType |
| | | { |
| | | ILTypeInstance instance; |
| | | ILRuntime.Runtime.Enviorment.AppDomain appdomain; |
| | | |
| | | public Adapter() |
| | | { |
| | | |
| | | } |
| | | |
| | | public Adapter(ILRuntime.Runtime.Enviorment.AppDomain appdomain, ILTypeInstance instance) |
| | | { |
| | | this.appdomain = appdomain; |
| | | this.instance = instance; |
| | | } |
| | | |
| | | public ILTypeInstance ILInstance { get { return instance; } } |
| | | |
| | | public override string ToString() |
| | | { |
| | | IMethod m = appdomain.ObjectType.GetMethod("ToString", 0); |
| | | m = instance.Type.GetVirtualMethod(m); |
| | | if (m == null || m is ILMethod) |
| | | { |
| | | return instance.ToString(); |
| | | } |
| | | else |
| | | return instance.Type.FullName; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
File was renamed from Assets/Plugins/LitJson/Netstandard15Polyfill.cs.meta |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 155770190c61cbb4dbbde393aec4c23e |
| | | guid: b7a960416ca33054c9080b81c999f783 |
| | | MonoImporter: |
| | | externalObjects: {} |
| | | serializedVersion: 2 |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 9afdb420954c32c4d8f0a85cda35cd37 |
| | | guid: feab2fabf79187c48bbc4aeb3f483571 |
| | | folderAsset: yes |
| | | timeCreated: 1485153550 |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | DefaultImporter: |
| | | userData: |
| | |
| | | fileFormatVersion: 2 |
| | | guid: bc9dd9797d276a94482023e6b143e67f |
| | | timeCreated: 1485153551 |
| | | guid: 764689d90315f244d8141804e4d561c6 |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | MonoImporter: |
| | | serializedVersion: 2 |
| | |
| | | public ICollection<string> Keys { |
| | | get { EnsureDictionary (); return inst_object.Keys; } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Determines whether the json contains an element that has the specified key. |
| | | /// </summary> |
| | | /// <param name="key">The key to locate in the json.</param> |
| | | /// <returns>true if the json contains an element that has the specified key; otherwise, false.</returns> |
| | | public Boolean ContainsKey(String key) { |
| | | EnsureDictionary(); |
| | | return this.inst_object.Keys.Contains(key); |
| | | } |
| | | #endregion |
| | | |
| | | |
| | |
| | | return data.inst_double; |
| | | } |
| | | |
| | | public static explicit operator Int32(JsonData data) |
| | | public static explicit operator Int32 (JsonData data) |
| | | { |
| | | if (data.type != JsonType.Int && data.type != JsonType.Long) |
| | | { |
| | | throw new InvalidCastException( |
| | | if (data.type != JsonType.Int) |
| | | throw new InvalidCastException ( |
| | | "Instance of JsonData doesn't hold an int"); |
| | | } |
| | | |
| | | // cast may truncate data... but that's up to the user to consider |
| | | return data.type == JsonType.Int ? data.inst_int : (int)data.inst_long; |
| | | return data.inst_int; |
| | | } |
| | | |
| | | public static explicit operator Int64(JsonData data) |
| | | public static explicit operator Int64 (JsonData data) |
| | | { |
| | | if (data.type != JsonType.Long && data.type != JsonType.Int) |
| | | { |
| | | throw new InvalidCastException( |
| | | "Instance of JsonData doesn't hold a long"); |
| | | } |
| | | if (data.type != JsonType.Long) |
| | | throw new InvalidCastException ( |
| | | "Instance of JsonData doesn't hold an int"); |
| | | |
| | | return data.type == JsonType.Long ? data.inst_long : data.inst_int; |
| | | return data.inst_long; |
| | | } |
| | | |
| | | public static explicit operator String (JsonData data) |
| | |
| | | return EnsureList ().Add (data); |
| | | } |
| | | |
| | | public bool Remove(object obj) |
| | | { |
| | | json = null; |
| | | if(IsObject) |
| | | { |
| | | JsonData value = null; |
| | | if (inst_object.TryGetValue((string)obj, out value)) |
| | | return inst_object.Remove((string)obj) && object_list.Remove(new KeyValuePair<string, JsonData>((string)obj, value)); |
| | | else |
| | | throw new KeyNotFoundException("The specified key was not found in the JsonData object."); |
| | | } |
| | | if(IsArray) |
| | | { |
| | | return inst_array.Remove(ToJsonData(obj)); |
| | | } |
| | | throw new InvalidOperationException ( |
| | | "Instance of JsonData is not an object or a list."); |
| | | } |
| | | |
| | | public void Clear () |
| | | { |
| | | if (IsObject) { |
| | |
| | | return false; |
| | | |
| | | if (x.type != this.type) |
| | | { |
| | | // further check to see if this is a long to int comparison |
| | | if ((x.type != JsonType.Int && x.type != JsonType.Long) |
| | | || (this.type != JsonType.Int && this.type != JsonType.Long)) |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | return false; |
| | | |
| | | switch (this.type) { |
| | | case JsonType.None: |
| | |
| | | return this.inst_string.Equals (x.inst_string); |
| | | |
| | | case JsonType.Int: |
| | | { |
| | | if (x.IsLong) |
| | | { |
| | | if (x.inst_long < Int32.MinValue || x.inst_long > Int32.MaxValue) |
| | | return false; |
| | | return this.inst_int.Equals((int)x.inst_long); |
| | | } |
| | | return this.inst_int.Equals(x.inst_int); |
| | | } |
| | | return this.inst_int.Equals (x.inst_int); |
| | | |
| | | case JsonType.Long: |
| | | { |
| | | if (x.IsInt) |
| | | { |
| | | if (this.inst_long < Int32.MinValue || this.inst_long > Int32.MaxValue) |
| | | return false; |
| | | return x.inst_int.Equals((int)this.inst_long); |
| | | } |
| | | return this.inst_long.Equals(x.inst_long); |
| | | } |
| | | return this.inst_long.Equals (x.inst_long); |
| | | |
| | | case JsonType.Double: |
| | | return this.inst_double.Equals (x.inst_double); |
| | |
| | | fileFormatVersion: 2 |
| | | guid: b71ea4f4f0a0c444793c92d185eb71ae |
| | | timeCreated: 1485153551 |
| | | guid: 0698a207332b63040b8ff6588024c70a |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | MonoImporter: |
| | | serializedVersion: 2 |
| | |
| | | |
| | | namespace LitJson |
| | | { |
| | | public class JsonException : |
| | | #if NETSTANDARD1_5 |
| | | Exception |
| | | #else |
| | | ApplicationException |
| | | #endif |
| | | public class JsonException : ApplicationException |
| | | { |
| | | public JsonException () : base () |
| | | { |
| | |
| | | fileFormatVersion: 2 |
| | | guid: d29aaf447eab3a24684bbffbe17ac446 |
| | | timeCreated: 1485153551 |
| | | guid: b3b535e68508c694d8b5be3e0669ffb8 |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | MonoImporter: |
| | | serializedVersion: 2 |
| | |
| | | using System.Globalization; |
| | | using System.IO; |
| | | using System.Reflection; |
| | | |
| | | using ILRuntime.Runtime.Intepreter; |
| | | using ILRuntime.Runtime.Stack; |
| | | using ILRuntime.CLR.Method; |
| | | using ILRuntime.CLR.Utils; |
| | | |
| | | namespace LitJson |
| | | { |
| | |
| | | public class JsonMapper |
| | | { |
| | | #region Fields |
| | | private static readonly int max_nesting_depth; |
| | | private static int max_nesting_depth; |
| | | |
| | | private static readonly IFormatProvider datetime_format; |
| | | private static IFormatProvider datetime_format; |
| | | |
| | | private static readonly IDictionary<Type, ExporterFunc> base_exporters_table; |
| | | private static readonly IDictionary<Type, ExporterFunc> custom_exporters_table; |
| | | private static IDictionary<Type, ExporterFunc> base_exporters_table; |
| | | private static IDictionary<Type, ExporterFunc> custom_exporters_table; |
| | | |
| | | private static readonly IDictionary<Type, |
| | | private static IDictionary<Type, |
| | | IDictionary<Type, ImporterFunc>> base_importers_table; |
| | | private static readonly IDictionary<Type, |
| | | private static IDictionary<Type, |
| | | IDictionary<Type, ImporterFunc>> custom_importers_table; |
| | | |
| | | private static readonly IDictionary<Type, ArrayMetadata> array_metadata; |
| | | private static IDictionary<Type, ArrayMetadata> array_metadata; |
| | | private static readonly object array_metadata_lock = new Object (); |
| | | |
| | | private static readonly IDictionary<Type, |
| | | private static IDictionary<Type, |
| | | IDictionary<Type, MethodInfo>> conv_ops; |
| | | private static readonly object conv_ops_lock = new Object (); |
| | | |
| | | private static readonly IDictionary<Type, ObjectMetadata> object_metadata; |
| | | private static IDictionary<Type, ObjectMetadata> object_metadata; |
| | | private static readonly object object_metadata_lock = new Object (); |
| | | |
| | | private static readonly IDictionary<Type, |
| | | private static IDictionary<Type, |
| | | IList<PropertyMetadata>> type_properties; |
| | | private static readonly object type_properties_lock = new Object (); |
| | | |
| | | private static readonly JsonWriter static_writer; |
| | | private static JsonWriter static_writer; |
| | | private static readonly object static_writer_lock = new Object (); |
| | | #endregion |
| | | |
| | |
| | | if (type.GetInterface ("System.Collections.IList") != null) |
| | | data.IsList = true; |
| | | |
| | | foreach (PropertyInfo p_info in type.GetProperties ()) { |
| | | if (p_info.Name != "Item") |
| | | continue; |
| | | |
| | | ParameterInfo[] parameters = p_info.GetIndexParameters (); |
| | | |
| | | if (parameters.Length != 1) |
| | | continue; |
| | | |
| | | if (parameters[0].ParameterType == typeof (int)) |
| | | data.ElementType = p_info.PropertyType; |
| | | if (type is ILRuntime.Reflection.ILRuntimeWrapperType) |
| | | { |
| | | var wt = (ILRuntime.Reflection.ILRuntimeWrapperType)type; |
| | | if (data.IsArray) |
| | | { |
| | | data.ElementType = wt.CLRType.ElementType.ReflectionType; |
| | | } |
| | | else |
| | | { |
| | | data.ElementType = wt.CLRType.GenericArguments[0].Value.ReflectionType; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | foreach (PropertyInfo p_info in type.GetProperties()) |
| | | { |
| | | if (p_info.Name != "Item") |
| | | continue; |
| | | |
| | | ParameterInfo[] parameters = p_info.GetIndexParameters(); |
| | | |
| | | if (parameters.Length != 1) |
| | | continue; |
| | | |
| | | if (parameters[0].ParameterType == typeof(int)) |
| | | data.ElementType = p_info.PropertyType; |
| | | } |
| | | } |
| | | lock (array_metadata_lock) { |
| | | try { |
| | | array_metadata.Add (type, data); |
| | |
| | | data.IsDictionary = true; |
| | | |
| | | data.Properties = new Dictionary<string, PropertyMetadata> (); |
| | | |
| | | foreach (PropertyInfo p_info in type.GetProperties ()) { |
| | | if (p_info.Name == "Item") { |
| | | ParameterInfo[] parameters = p_info.GetIndexParameters (); |
| | |
| | | if (parameters.Length != 1) |
| | | continue; |
| | | |
| | | if (parameters[0].ParameterType == typeof (string)) |
| | | data.ElementType = p_info.PropertyType; |
| | | if (parameters[0].ParameterType == typeof(string)) |
| | | { |
| | | if (type is ILRuntime.Reflection.ILRuntimeWrapperType) |
| | | { |
| | | data.ElementType = ((ILRuntime.Reflection.ILRuntimeWrapperType)type).CLRType.GenericArguments[1].Value.ReflectionType; |
| | | } |
| | | else |
| | | data.ElementType = p_info.PropertyType; |
| | | } |
| | | |
| | | continue; |
| | | } |
| | |
| | | if (reader.Token == JsonToken.ArrayEnd) |
| | | return null; |
| | | |
| | | Type underlying_type = Nullable.GetUnderlyingType(inst_type); |
| | | Type value_type = underlying_type ?? inst_type; |
| | | //ILRuntime doesn't support nullable valuetype |
| | | Type underlying_type = inst_type;//Nullable.GetUnderlyingType(inst_type); |
| | | Type value_type = inst_type; |
| | | |
| | | if (reader.Token == JsonToken.Null) { |
| | | #if NETSTANDARD1_5 |
| | | if (inst_type.IsClass() || underlying_type != null) { |
| | | return null; |
| | | } |
| | | #else |
| | | if (inst_type.IsClass || underlying_type != null) { |
| | | return null; |
| | | } |
| | | #endif |
| | | |
| | | throw new JsonException (String.Format ( |
| | | "Can't assign null to an instance of type {0}", |
| | |
| | | reader.Token == JsonToken.String || |
| | | reader.Token == JsonToken.Boolean) { |
| | | |
| | | Type json_type = reader.Value.GetType (); |
| | | Type json_type = reader.Value.GetType(); |
| | | var vt = value_type is ILRuntime.Reflection.ILRuntimeWrapperType ? ((ILRuntime.Reflection.ILRuntimeWrapperType)value_type).CLRType.TypeForCLR : value_type; |
| | | |
| | | if (value_type.IsAssignableFrom (json_type)) |
| | | if (vt.IsAssignableFrom(json_type)) |
| | | return reader.Value; |
| | | |
| | | if (vt is ILRuntime.Reflection.ILRuntimeType && ((ILRuntime.Reflection.ILRuntimeType)vt).ILType.IsEnum) |
| | | { |
| | | if (json_type == typeof(int) || json_type == typeof(long) || json_type == typeof(short) || json_type == typeof(byte)) |
| | | return reader.Value; |
| | | } |
| | | // If there's a custom importer that fits, use it |
| | | if (custom_importers_table.ContainsKey (json_type) && |
| | | custom_importers_table[json_type].ContainsKey ( |
| | | value_type)) { |
| | | vt)) { |
| | | |
| | | ImporterFunc importer = |
| | | custom_importers_table[json_type][value_type]; |
| | | custom_importers_table[json_type][vt]; |
| | | |
| | | return importer (reader.Value); |
| | | } |
| | |
| | | // Maybe there's a base importer that works |
| | | if (base_importers_table.ContainsKey (json_type) && |
| | | base_importers_table[json_type].ContainsKey ( |
| | | value_type)) { |
| | | vt)) { |
| | | |
| | | ImporterFunc importer = |
| | | base_importers_table[json_type][value_type]; |
| | | base_importers_table[json_type][vt]; |
| | | |
| | | return importer (reader.Value); |
| | | } |
| | | |
| | | // Maybe it's an enum |
| | | #if NETSTANDARD1_5 |
| | | if (value_type.IsEnum()) |
| | | return Enum.ToObject (value_type, reader.Value); |
| | | #else |
| | | if (value_type.IsEnum) |
| | | return Enum.ToObject (value_type, reader.Value); |
| | | #endif |
| | | if (vt.IsEnum) |
| | | return Enum.ToObject (vt, reader.Value); |
| | | |
| | | // Try using an implicit conversion operator |
| | | MethodInfo conv_op = GetConvOp (value_type, json_type); |
| | | MethodInfo conv_op = GetConvOp (vt, json_type); |
| | | |
| | | if (conv_op != null) |
| | | return conv_op.Invoke (null, |
| | |
| | | list = new ArrayList (); |
| | | elem_type = inst_type.GetElementType (); |
| | | } |
| | | |
| | | list.Clear(); |
| | | |
| | | while (true) { |
| | | object item = ReadValue (elem_type, reader); |
| | | if (item == null && reader.Token == JsonToken.ArrayEnd) |
| | | break; |
| | | |
| | | var rt = elem_type is ILRuntime.Reflection.ILRuntimeWrapperType ? ((ILRuntime.Reflection.ILRuntimeWrapperType)elem_type).RealType : elem_type; |
| | | rt = elem_type is ILRuntime.Reflection.ILRuntimeType ? ((ILRuntime.Reflection.ILRuntimeType)elem_type).ILType.TypeForCLR : elem_type; |
| | | item = rt.CheckCLRTypes(item); |
| | | list.Add (item); |
| | | } |
| | | |
| | | if (t_data.IsArray) { |
| | | int n = list.Count; |
| | | instance = Array.CreateInstance (elem_type, n); |
| | | var rt = elem_type is ILRuntime.Reflection.ILRuntimeWrapperType ? ((ILRuntime.Reflection.ILRuntimeWrapperType)elem_type).RealType : elem_type; |
| | | rt = elem_type is ILRuntime.Reflection.ILRuntimeType ? ((ILRuntime.Reflection.ILRuntimeType)elem_type).ILType.TypeForCLR : elem_type; |
| | | instance = Array.CreateInstance (rt, n); |
| | | |
| | | for (int i = 0; i < n; i++) |
| | | ((Array) instance).SetValue (list[i], i); |
| | |
| | | } else if (reader.Token == JsonToken.ObjectStart) { |
| | | AddObjectMetadata (value_type); |
| | | ObjectMetadata t_data = object_metadata[value_type]; |
| | | |
| | | instance = Activator.CreateInstance (value_type); |
| | | |
| | | if (value_type is ILRuntime.Reflection.ILRuntimeType) |
| | | instance = ((ILRuntime.Reflection.ILRuntimeType)value_type).ILType.Instantiate(); |
| | | else |
| | | { |
| | | if (value_type is ILRuntime.Reflection.ILRuntimeWrapperType) |
| | | value_type = ((ILRuntime.Reflection.ILRuntimeWrapperType)value_type).RealType; |
| | | instance = Activator.CreateInstance(value_type); |
| | | } |
| | | while (true) { |
| | | reader.Read (); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | var rt = t_data.ElementType is ILRuntime.Reflection.ILRuntimeWrapperType ? ((ILRuntime.Reflection.ILRuntimeWrapperType)t_data.ElementType).RealType : t_data.ElementType; |
| | | ((IDictionary) instance).Add ( |
| | | property, ReadValue ( |
| | | t_data.ElementType, reader)); |
| | | property, rt.CheckCLRTypes(ReadValue ( |
| | | t_data.ElementType, reader))); |
| | | } |
| | | |
| | | } |
| | |
| | | delegate (object obj, JsonWriter writer) { |
| | | writer.Write ((ulong) obj); |
| | | }; |
| | | |
| | | base_exporters_table[typeof(DateTimeOffset)] = |
| | | delegate (object obj, JsonWriter writer) { |
| | | writer.Write(((DateTimeOffset)obj).ToString("yyyy-MM-ddTHH:mm:ss.fffffffzzz", datetime_format)); |
| | | }; |
| | | } |
| | | |
| | | private static void RegisterBaseImporters () |
| | |
| | | typeof (ulong), importer); |
| | | |
| | | importer = delegate (object input) { |
| | | return Convert.ToInt64((int)input); |
| | | }; |
| | | RegisterImporter(base_importers_table, typeof(int), |
| | | typeof(long), importer); |
| | | |
| | | importer = delegate (object input) { |
| | | return Convert.ToSByte ((int) input); |
| | | }; |
| | | RegisterImporter (base_importers_table, typeof (int), |
| | |
| | | }; |
| | | RegisterImporter (base_importers_table, typeof (int), |
| | | typeof (short), importer); |
| | | |
| | | importer = delegate (object input) { |
| | | return Convert.ToInt64((int)input); |
| | | }; |
| | | RegisterImporter(base_importers_table, typeof(int), |
| | | typeof(long), importer); |
| | | |
| | | importer = delegate (object input) { |
| | | return Convert.ToUInt16 ((int) input); |
| | |
| | | }; |
| | | RegisterImporter (base_importers_table, typeof (string), |
| | | typeof (DateTime), importer); |
| | | |
| | | importer = delegate (object input) { |
| | | return DateTimeOffset.Parse((string)input, datetime_format); |
| | | }; |
| | | RegisterImporter(base_importers_table, typeof(string), |
| | | typeof(DateTimeOffset), importer); |
| | | } |
| | | |
| | | private static void RegisterImporter ( |
| | |
| | | return; |
| | | } |
| | | |
| | | if (obj is IDictionary dictionary) { |
| | | if (obj is IDictionary) { |
| | | writer.WriteObjectStart (); |
| | | foreach (DictionaryEntry entry in dictionary) { |
| | | var propertyName = entry.Key is string key ? |
| | | key |
| | | : Convert.ToString(entry.Key, CultureInfo.InvariantCulture); |
| | | writer.WritePropertyName (propertyName); |
| | | foreach (DictionaryEntry entry in (IDictionary) obj) { |
| | | writer.WritePropertyName ((string) entry.Key); |
| | | WriteValue (entry.Value, writer, writer_is_private, |
| | | depth + 1); |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | Type obj_type = obj.GetType (); |
| | | Type obj_type; |
| | | if (obj is ILRuntime.Runtime.Intepreter.ILTypeInstance) |
| | | { |
| | | obj_type = ((ILRuntime.Runtime.Intepreter.ILTypeInstance)obj).Type.ReflectionType; |
| | | } |
| | | else if(obj is ILRuntime.Runtime.Enviorment.CrossBindingAdaptorType) |
| | | { |
| | | obj_type = ((ILRuntime.Runtime.Enviorment.CrossBindingAdaptorType)obj).ILInstance.Type.ReflectionType; |
| | | } |
| | | else |
| | | obj_type = obj.GetType(); |
| | | |
| | | // See if there's a custom exporter for the object |
| | | if (custom_exporters_table.ContainsKey (obj_type)) { |
| | |
| | | |
| | | return (T) ReadValue (typeof (T), reader); |
| | | } |
| | | |
| | | public static object ToObject(string json, Type ConvertType ) |
| | | { |
| | | JsonReader reader = new JsonReader(json); |
| | | |
| | | return ReadValue(ConvertType, reader); |
| | | } |
| | | |
| | | public static IJsonWrapper ToWrapper (WrapperFactory factory, |
| | | JsonReader reader) |
| | |
| | | { |
| | | custom_importers_table.Clear (); |
| | | } |
| | | |
| | | public unsafe static void RegisterILRuntimeCLRRedirection(ILRuntime.Runtime.Enviorment.AppDomain appdomain) |
| | | { |
| | | foreach(var i in typeof(JsonMapper).GetMethods()) |
| | | { |
| | | if(i.Name == "ToObject" && i.IsGenericMethodDefinition) |
| | | { |
| | | var param = i.GetParameters(); |
| | | if(param[0].ParameterType == typeof(string)) |
| | | { |
| | | appdomain.RegisterCLRMethodRedirection(i, JsonToObject); |
| | | } |
| | | else if(param[0].ParameterType == typeof(JsonReader)) |
| | | { |
| | | appdomain.RegisterCLRMethodRedirection(i, JsonToObject2); |
| | | } |
| | | else if (param[0].ParameterType == typeof(TextReader)) |
| | | { |
| | | appdomain.RegisterCLRMethodRedirection(i, JsonToObject3); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public unsafe static StackObject* JsonToObject(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | ILRuntime.Runtime.Enviorment.AppDomain __domain = intp.AppDomain; |
| | | StackObject* ptr_of_this_method; |
| | | StackObject* __ret = ILIntepreter.Minus(esp, 1); |
| | | ptr_of_this_method = ILIntepreter.Minus(esp, 1); |
| | | System.String json = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, mStack)); |
| | | intp.Free(ptr_of_this_method); |
| | | var type = method.GenericArguments[0].ReflectionType; |
| | | var result_of_this_method = ReadValue(type, new JsonReader(json)); |
| | | |
| | | return ILIntepreter.PushObject(__ret, mStack, result_of_this_method); |
| | | } |
| | | |
| | | public unsafe static StackObject* JsonToObject2(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | ILRuntime.Runtime.Enviorment.AppDomain __domain = intp.AppDomain; |
| | | StackObject* ptr_of_this_method; |
| | | StackObject* __ret = ILIntepreter.Minus(esp, 1); |
| | | ptr_of_this_method = ILIntepreter.Minus(esp, 1); |
| | | JsonReader json = (JsonReader)typeof(JsonReader).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, mStack)); |
| | | intp.Free(ptr_of_this_method); |
| | | var type = method.GenericArguments[0].ReflectionType; |
| | | var result_of_this_method = ReadValue(type, json); |
| | | |
| | | return ILIntepreter.PushObject(__ret, mStack, result_of_this_method); |
| | | } |
| | | |
| | | public unsafe static StackObject* JsonToObject3(ILIntepreter intp, StackObject* esp, IList<object> mStack, CLRMethod method, bool isNewObj) |
| | | { |
| | | ILRuntime.Runtime.Enviorment.AppDomain __domain = intp.AppDomain; |
| | | StackObject* ptr_of_this_method; |
| | | StackObject* __ret = ILIntepreter.Minus(esp, 1); |
| | | ptr_of_this_method = ILIntepreter.Minus(esp, 1); |
| | | TextReader json = (TextReader)typeof(TextReader).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, mStack)); |
| | | intp.Free(ptr_of_this_method); |
| | | var type = method.GenericArguments[0].ReflectionType; |
| | | var result_of_this_method = ReadValue(type, new JsonReader(json)); |
| | | |
| | | return ILIntepreter.PushObject(__ret, mStack, result_of_this_method); |
| | | } |
| | | } |
| | | } |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 113d1f95e9ecad949b22e237b614d021 |
| | | timeCreated: 1485153551 |
| | | guid: 934218b2d4d36e94099e4fd9c2b038cf |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | MonoImporter: |
| | | serializedVersion: 2 |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 9f138d7885d61c54396ad60be3ac1afd |
| | | timeCreated: 1485153551 |
| | | guid: b54c1e09579995a4690bddeb757058ef |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | MonoImporter: |
| | | serializedVersion: 2 |
| | |
| | | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Globalization; |
| | | using System.IO; |
| | | using System.Text; |
| | | |
| | |
| | | public class JsonReader |
| | | { |
| | | #region Fields |
| | | private static readonly IDictionary<int, IDictionary<int, int[]>> parse_table; |
| | | private static IDictionary<int, IDictionary<int, int[]>> parse_table; |
| | | |
| | | private Stack<int> automaton_stack; |
| | | private int current_input; |
| | |
| | | #region Constructors |
| | | static JsonReader () |
| | | { |
| | | parse_table = PopulateParseTable (); |
| | | PopulateParseTable (); |
| | | } |
| | | |
| | | public JsonReader (string json_text) : |
| | |
| | | |
| | | |
| | | #region Static Methods |
| | | private static IDictionary<int, IDictionary<int, int[]>> PopulateParseTable () |
| | | private static void PopulateParseTable () |
| | | { |
| | | // See section A.2. of the manual for details |
| | | IDictionary<int, IDictionary<int, int[]>> parse_table = new Dictionary<int, IDictionary<int, int[]>> (); |
| | | parse_table = new Dictionary<int, IDictionary<int, int[]>> (); |
| | | |
| | | TableAddRow (parse_table, ParserToken.Array); |
| | | TableAddCol (parse_table, ParserToken.Array, '[', |
| | | '[', |
| | | (int) ParserToken.ArrayPrime); |
| | | TableAddRow (ParserToken.Array); |
| | | TableAddCol (ParserToken.Array, '[', |
| | | '[', |
| | | (int) ParserToken.ArrayPrime); |
| | | |
| | | TableAddRow (parse_table, ParserToken.ArrayPrime); |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, '"', |
| | | (int) ParserToken.Value, |
| | | TableAddRow (ParserToken.ArrayPrime); |
| | | TableAddCol (ParserToken.ArrayPrime, '"', |
| | | (int) ParserToken.Value, |
| | | |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, '[', |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, ']', |
| | | ']'); |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, '{', |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.Number, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.True, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.False, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (parse_table, ParserToken.ArrayPrime, (int) ParserToken.Null, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, '[', |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, ']', |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, '{', |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, (int) ParserToken.Number, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, (int) ParserToken.True, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, (int) ParserToken.False, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | TableAddCol (ParserToken.ArrayPrime, (int) ParserToken.Null, |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest, |
| | | ']'); |
| | | |
| | | TableAddRow (parse_table, ParserToken.Object); |
| | | TableAddCol (parse_table, ParserToken.Object, '{', |
| | | '{', |
| | | (int) ParserToken.ObjectPrime); |
| | | TableAddRow (ParserToken.Object); |
| | | TableAddCol (ParserToken.Object, '{', |
| | | '{', |
| | | (int) ParserToken.ObjectPrime); |
| | | |
| | | TableAddRow (parse_table, ParserToken.ObjectPrime); |
| | | TableAddCol (parse_table, ParserToken.ObjectPrime, '"', |
| | | (int) ParserToken.Pair, |
| | | (int) ParserToken.PairRest, |
| | | '}'); |
| | | TableAddCol (parse_table, ParserToken.ObjectPrime, '}', |
| | | '}'); |
| | | TableAddRow (ParserToken.ObjectPrime); |
| | | TableAddCol (ParserToken.ObjectPrime, '"', |
| | | (int) ParserToken.Pair, |
| | | (int) ParserToken.PairRest, |
| | | '}'); |
| | | TableAddCol (ParserToken.ObjectPrime, '}', |
| | | '}'); |
| | | |
| | | TableAddRow (parse_table, ParserToken.Pair); |
| | | TableAddCol (parse_table, ParserToken.Pair, '"', |
| | | (int) ParserToken.String, |
| | | ':', |
| | | (int) ParserToken.Value); |
| | | TableAddRow (ParserToken.Pair); |
| | | TableAddCol (ParserToken.Pair, '"', |
| | | (int) ParserToken.String, |
| | | ':', |
| | | (int) ParserToken.Value); |
| | | |
| | | TableAddRow (parse_table, ParserToken.PairRest); |
| | | TableAddCol (parse_table, ParserToken.PairRest, ',', |
| | | ',', |
| | | (int) ParserToken.Pair, |
| | | (int) ParserToken.PairRest); |
| | | TableAddCol (parse_table, ParserToken.PairRest, '}', |
| | | (int) ParserToken.Epsilon); |
| | | TableAddRow (ParserToken.PairRest); |
| | | TableAddCol (ParserToken.PairRest, ',', |
| | | ',', |
| | | (int) ParserToken.Pair, |
| | | (int) ParserToken.PairRest); |
| | | TableAddCol (ParserToken.PairRest, '}', |
| | | (int) ParserToken.Epsilon); |
| | | |
| | | TableAddRow (parse_table, ParserToken.String); |
| | | TableAddCol (parse_table, ParserToken.String, '"', |
| | | '"', |
| | | (int) ParserToken.CharSeq, |
| | | '"'); |
| | | TableAddRow (ParserToken.String); |
| | | TableAddCol (ParserToken.String, '"', |
| | | '"', |
| | | (int) ParserToken.CharSeq, |
| | | '"'); |
| | | |
| | | TableAddRow (parse_table, ParserToken.Text); |
| | | TableAddCol (parse_table, ParserToken.Text, '[', |
| | | (int) ParserToken.Array); |
| | | TableAddCol (parse_table, ParserToken.Text, '{', |
| | | (int) ParserToken.Object); |
| | | TableAddRow (ParserToken.Text); |
| | | TableAddCol (ParserToken.Text, '[', |
| | | (int) ParserToken.Array); |
| | | TableAddCol (ParserToken.Text, '{', |
| | | (int) ParserToken.Object); |
| | | |
| | | TableAddRow (parse_table, ParserToken.Value); |
| | | TableAddCol (parse_table, ParserToken.Value, '"', |
| | | (int) ParserToken.String); |
| | | TableAddCol (parse_table, ParserToken.Value, '[', |
| | | (int) ParserToken.Array); |
| | | TableAddCol (parse_table, ParserToken.Value, '{', |
| | | (int) ParserToken.Object); |
| | | TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.Number, |
| | | (int) ParserToken.Number); |
| | | TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.True, |
| | | (int) ParserToken.True); |
| | | TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.False, |
| | | (int) ParserToken.False); |
| | | TableAddCol (parse_table, ParserToken.Value, (int) ParserToken.Null, |
| | | (int) ParserToken.Null); |
| | | TableAddRow (ParserToken.Value); |
| | | TableAddCol (ParserToken.Value, '"', |
| | | (int) ParserToken.String); |
| | | TableAddCol (ParserToken.Value, '[', |
| | | (int) ParserToken.Array); |
| | | TableAddCol (ParserToken.Value, '{', |
| | | (int) ParserToken.Object); |
| | | TableAddCol (ParserToken.Value, (int) ParserToken.Number, |
| | | (int) ParserToken.Number); |
| | | TableAddCol (ParserToken.Value, (int) ParserToken.True, |
| | | (int) ParserToken.True); |
| | | TableAddCol (ParserToken.Value, (int) ParserToken.False, |
| | | (int) ParserToken.False); |
| | | TableAddCol (ParserToken.Value, (int) ParserToken.Null, |
| | | (int) ParserToken.Null); |
| | | |
| | | TableAddRow (parse_table, ParserToken.ValueRest); |
| | | TableAddCol (parse_table, ParserToken.ValueRest, ',', |
| | | ',', |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest); |
| | | TableAddCol (parse_table, ParserToken.ValueRest, ']', |
| | | (int) ParserToken.Epsilon); |
| | | |
| | | return parse_table; |
| | | TableAddRow (ParserToken.ValueRest); |
| | | TableAddCol (ParserToken.ValueRest, ',', |
| | | ',', |
| | | (int) ParserToken.Value, |
| | | (int) ParserToken.ValueRest); |
| | | TableAddCol (ParserToken.ValueRest, ']', |
| | | (int) ParserToken.Epsilon); |
| | | } |
| | | |
| | | private static void TableAddCol (IDictionary<int, IDictionary<int, int[]>> parse_table, ParserToken row, int col, |
| | | private static void TableAddCol (ParserToken row, int col, |
| | | params int[] symbols) |
| | | { |
| | | parse_table[(int) row].Add (col, symbols); |
| | | } |
| | | |
| | | private static void TableAddRow (IDictionary<int, IDictionary<int, int[]>> parse_table, ParserToken rule) |
| | | private static void TableAddRow (ParserToken rule) |
| | | { |
| | | parse_table.Add ((int) rule, new Dictionary<int, int[]> ()); |
| | | } |
| | |
| | | number.IndexOf ('E') != -1) { |
| | | |
| | | double n_double; |
| | | if (double.TryParse (number, NumberStyles.Any, CultureInfo.InvariantCulture, out n_double)) { |
| | | if (Double.TryParse (number, out n_double)) { |
| | | token = JsonToken.Double; |
| | | token_value = n_double; |
| | | |
| | |
| | | } |
| | | |
| | | int n_int32; |
| | | if (int.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int32)) { |
| | | if (Int32.TryParse (number, out n_int32)) { |
| | | token = JsonToken.Int; |
| | | token_value = n_int32; |
| | | |
| | |
| | | } |
| | | |
| | | long n_int64; |
| | | if (long.TryParse (number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_int64)) { |
| | | if (Int64.TryParse (number, out n_int64)) { |
| | | token = JsonToken.Long; |
| | | token_value = n_int64; |
| | | |
| | |
| | | } |
| | | |
| | | ulong n_uint64; |
| | | if (ulong.TryParse(number, NumberStyles.Integer, CultureInfo.InvariantCulture, out n_uint64)) |
| | | if (UInt64.TryParse(number, out n_uint64)) |
| | | { |
| | | token = JsonToken.Long; |
| | | token_value = n_uint64; |
| | |
| | | end_of_json = true; |
| | | |
| | | if (reader_is_owned) |
| | | { |
| | | using(reader){} |
| | | } |
| | | reader.Close (); |
| | | |
| | | reader = null; |
| | | } |
| | |
| | | fileFormatVersion: 2 |
| | | guid: f1479093188b62f40ac8bdd21d0f4f52 |
| | | timeCreated: 1485153553 |
| | | guid: 9c6387b3fbeef8f40b27fae67b97e857 |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | MonoImporter: |
| | | serializedVersion: 2 |
| | |
| | | public class JsonWriter |
| | | { |
| | | #region Fields |
| | | private static readonly NumberFormatInfo number_format; |
| | | private static NumberFormatInfo number_format; |
| | | |
| | | private WriterContext context; |
| | | private Stack<WriterContext> ctx_stack; |
| | |
| | | private StringBuilder inst_string_builder; |
| | | private bool pretty_print; |
| | | private bool validate; |
| | | private bool lower_case_properties; |
| | | private TextWriter writer; |
| | | #endregion |
| | | |
| | |
| | | public bool Validate { |
| | | get { return validate; } |
| | | set { validate = value; } |
| | | } |
| | | |
| | | public bool LowerCaseProperties { |
| | | get { return lower_case_properties; } |
| | | set { lower_case_properties = value; } |
| | | } |
| | | #endregion |
| | | |
| | |
| | | indent_value = 4; |
| | | pretty_print = false; |
| | | validate = true; |
| | | lower_case_properties = false; |
| | | |
| | | ctx_stack = new Stack<WriterContext> (); |
| | | context = new WriterContext (); |
| | |
| | | writer.Write (','); |
| | | |
| | | if (pretty_print && ! context.ExpectingValue) |
| | | writer.Write (Environment.NewLine); |
| | | writer.Write ('\n'); |
| | | } |
| | | |
| | | private void PutString (string str) |
| | |
| | | context.ExpectingValue = false; |
| | | } |
| | | |
| | | [CLSCompliant(false)] |
| | | public void Write (ulong number) |
| | | { |
| | | DoValidation (Condition.Value); |
| | |
| | | { |
| | | DoValidation (Condition.Property); |
| | | PutNewline (); |
| | | string propertyName = (property_name == null || !lower_case_properties) |
| | | ? property_name |
| | | : property_name.ToLowerInvariant(); |
| | | |
| | | PutString (propertyName); |
| | | PutString (property_name); |
| | | |
| | | if (pretty_print) { |
| | | if (propertyName.Length > context.Padding) |
| | | context.Padding = propertyName.Length; |
| | | if (property_name.Length > context.Padding) |
| | | context.Padding = property_name.Length; |
| | | |
| | | for (int i = context.Padding - propertyName.Length; |
| | | for (int i = context.Padding - property_name.Length; |
| | | i >= 0; i--) |
| | | writer.Write (' '); |
| | | |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 391bc87836467d94588b267ced4def17 |
| | | timeCreated: 1485153551 |
| | | guid: 76cc8a9d77cadda45a61376f5d2711b7 |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | MonoImporter: |
| | | serializedVersion: 2 |
| | |
| | | #region Fields |
| | | private delegate bool StateHandler (FsmContext ctx); |
| | | |
| | | private static readonly int[] fsm_return_table; |
| | | private static readonly StateHandler[] fsm_handler_table; |
| | | private static int[] fsm_return_table; |
| | | private static StateHandler[] fsm_handler_table; |
| | | |
| | | private bool allow_comments; |
| | | private bool allow_single_quoted_strings; |
| | |
| | | #region Constructors |
| | | static Lexer () |
| | | { |
| | | PopulateFsmTables (out fsm_handler_table, out fsm_return_table); |
| | | PopulateFsmTables (); |
| | | } |
| | | |
| | | public Lexer (TextReader reader) |
| | |
| | | } |
| | | } |
| | | |
| | | private static void PopulateFsmTables (out StateHandler[] fsm_handler_table, out int[] fsm_return_table) |
| | | private static void PopulateFsmTables () |
| | | { |
| | | // See section A.1. of the manual for details of the finite |
| | | // state machine. |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 255abca690abbf64e8c596cbbaa66aff |
| | | timeCreated: 1485153551 |
| | | guid: 8dba2340c538ddd4b89e83b99a240a67 |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | MonoImporter: |
| | | serializedVersion: 2 |
| | |
| | | fileFormatVersion: 2 |
| | | guid: 5ec22fb6a74b86c4f80e97dfde156f8a |
| | | timeCreated: 1485153551 |
| | | guid: 10fae80686f10bd4dad2f2d96d0d4330 |
| | | timeCreated: 1499871438 |
| | | licenseType: Free |
| | | MonoImporter: |
| | | serializedVersion: 2 |