From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- .../XMainClient/ProtoBuf/Meta/CallbackSet.cs | 160 +++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs (limited to 'Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs') diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs new file mode 100644 index 00000000..d0e7c11a --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/CallbackSet.cs @@ -0,0 +1,160 @@ +using System; +using System.Reflection; + +namespace ProtoBuf.Meta +{ + public class CallbackSet + { + internal MethodInfo this[TypeModel.CallbackType callbackType] + { + get + { + MethodInfo result; + switch (callbackType) + { + case TypeModel.CallbackType.BeforeSerialize: + result = this.beforeSerialize; + break; + case TypeModel.CallbackType.AfterSerialize: + result = this.afterSerialize; + break; + case TypeModel.CallbackType.BeforeDeserialize: + result = this.beforeDeserialize; + break; + case TypeModel.CallbackType.AfterDeserialize: + result = this.afterDeserialize; + break; + default: + throw new ArgumentException("Callback type not supported: " + callbackType.ToString(), "callbackType"); + } + return result; + } + } + + public MethodInfo BeforeSerialize + { + get + { + return this.beforeSerialize; + } + set + { + this.beforeSerialize = this.SanityCheckCallback(this.metaType.Model, value); + } + } + + public MethodInfo BeforeDeserialize + { + get + { + return this.beforeDeserialize; + } + set + { + this.beforeDeserialize = this.SanityCheckCallback(this.metaType.Model, value); + } + } + + public MethodInfo AfterSerialize + { + get + { + return this.afterSerialize; + } + set + { + this.afterSerialize = this.SanityCheckCallback(this.metaType.Model, value); + } + } + + public MethodInfo AfterDeserialize + { + get + { + return this.afterDeserialize; + } + set + { + this.afterDeserialize = this.SanityCheckCallback(this.metaType.Model, value); + } + } + + public bool NonTrivial + { + get + { + return this.beforeSerialize != null || this.beforeDeserialize != null || this.afterSerialize != null || this.afterDeserialize != null; + } + } + + private readonly MetaType metaType; + + private MethodInfo beforeSerialize; + + private MethodInfo afterSerialize; + + private MethodInfo beforeDeserialize; + + private MethodInfo afterDeserialize; + + internal CallbackSet(MetaType metaType) + { + bool flag = metaType == null; + if (flag) + { + throw new ArgumentNullException("metaType"); + } + this.metaType = metaType; + } + + internal static bool CheckCallbackParameters(TypeModel model, MethodInfo method) + { + ParameterInfo[] parameters = method.GetParameters(); + for (int i = 0; i < parameters.Length; i++) + { + Type parameterType = parameters[i].ParameterType; + bool flag = parameterType == model.MapType(typeof(SerializationContext)); + if (!flag) + { + bool flag2 = parameterType == model.MapType(typeof(Type)); + if (!flag2) + { + return false; + } + } + } + return true; + } + + private MethodInfo SanityCheckCallback(TypeModel model, MethodInfo callback) + { + this.metaType.ThrowIfFrozen(); + bool flag = callback == null; + MethodInfo result; + if (flag) + { + result = callback; + } + else + { + bool isStatic = callback.IsStatic; + if (isStatic) + { + throw new ArgumentException("Callbacks cannot be static", "callback"); + } + bool flag2 = callback.ReturnType != model.MapType(typeof(void)) || !CallbackSet.CheckCallbackParameters(model, callback); + if (flag2) + { + throw CallbackSet.CreateInvalidCallbackSignature(callback); + } + result = callback; + } + return result; + } + + internal static Exception CreateInvalidCallbackSignature(MethodInfo method) + { + return new NotSupportedException("Invalid callback signature in " + method.DeclaringType.FullName + "." + method.Name); + } + } +} -- cgit v1.1-26-g67d0