Example #1
0
        private IProtoSerializer GetMoreSpecificSerializer(object value)
        {
            if (!CanHaveInheritance)
            {
                return(null);
            }
            Type actualType = PBType.GetPType(value);

            if (actualType == forType)
            {
                return(null);
            }
            for (int i = 0; i < serializers.Length; i++)
            {
                IProtoSerializer ser = serializers[i];
                if (ser.ExpectedType != forType && Helpers.IsAssignableFrom(ser.ExpectedType, actualType))
                {
                    return(ser);
                }
            }
            if (actualType == constructType)
            {
                return(null);                                      // needs to be last in case the default concrete type is also a known sub-type
            }
            TypeModel.ThrowUnexpectedSubtype(forType, actualType); // might throw (if not a proxy)
            return(null);
        }
Example #2
0
        public static void Init()
        {
            List <Type> types = Game.EventSystem.GetTypes();

            foreach (Type type in types)
            {
                if (type.GetCustomAttributes(typeof(ProtoContractAttribute), false).Length == 0 && type.GetCustomAttributes(typeof(ProtoMemberAttribute), false).Length == 0)
                {
                    continue;
                }
                PBType.RegisterType(type.FullName, type);
            }
        }
Example #3
0
        /// <summary>
        /// 注册CLR重定向
        /// </summary>
        /// <param name="appdomain"></param>
        static unsafe void RegisterILRuntimeCLRRedirection(AppDomain appdomain)
        {
            //注册3种Log
            Type debugType = typeof(Debug);
            var  logMethod = debugType.GetMethod("Log", new[] { typeof(object) });

            appdomain.RegisterCLRMethodRedirection(logMethod, Log);
            var logWarningMethod = debugType.GetMethod("LogWarning", new[] { typeof(object) });

            appdomain.RegisterCLRMethodRedirection(logWarningMethod, LogWarning);
            var logErrorMethod = debugType.GetMethod("LogError", new[] { typeof(object) });

            appdomain.RegisterCLRMethodRedirection(logErrorMethod, LogError);

            //LitJson适配
            LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(appdomain);
            //Protobuf适配
            PBType.RegisterILRuntimeCLRRedirection(appdomain);
        }
Example #4
0
        private string GetDevKey(PBType pBType)
        {
            string devKey = string.Empty;
            Random random = new Random();

            switch (pBType)
            {
            case PBType.BuildShare:
                devKey = DevKeysBuildShare[random.Next(DevKeysBuildShare.Length)];
                break;

            case PBType.Error:
                devKey = DevKeysError[random.Next(DevKeysError.Length)];
                break;

            default:
                break;
            }

            return(devKey);
        }
Example #5
0
        object CreateInstance(ProtoReader source, bool includeLocalCallback)
        {
            //Helpers.DebugWriteLine("* creating : " + forType.FullName);
            object obj;

            if (factory != null)
            {
                obj = InvokeCallback(factory, null, source.Context);
            }
            else if (useConstructor)
            {
                if (!hasConstructor)
                {
                    TypeModel.ThrowCannotCreateInstance(constructType);
                }
                obj = PBType.CreateInstance(constructType);
            }
            else
            {
                obj = BclHelpers.GetUninitializedObject(constructType);
            }
            ProtoReader.NoteObject(obj, source);
            if (baseCtorCallbacks != null)
            {
                for (int i = 0; i < baseCtorCallbacks.Length; i++)
                {
                    InvokeCallback(baseCtorCallbacks[i], obj, source.Context);
                }
            }
            if (includeLocalCallback && callbacks != null)
            {
                InvokeCallback(callbacks.BeforeDeserialize, obj, source.Context);
            }
            if (obj == null)
            {
                throw new ProtoException("obj is null.");
            }
            return(obj);
        }
Example #6
0
        void genLuaPB(Type t, string saveFolder)
        {
            if (hasGen.Contains(t))
            {
                return;
            }
            hasGen.Add(t);
            //=======Gen Code==========
            PBType pbType     = new PBType(t);
            string pbTypeCode = pbType.genLuaCode();

            Debug.LogError(pbTypeCode);
            string path = saveFolder + t.Namespace + ".lua";

            if (!File.Exists(path))
            {
                File.WriteAllText(path, "--AutoGen Code,Don't Modify" + RET + RET);
            }
            string str = File.ReadAllText(path);

            str += pbTypeCode;
            File.WriteAllText(path, str);
            //=========================
        }
Example #7
0
 public PasteBinClient(PBType pBType)
 {
     _apiDevKey = GetDevKey(pBType);
 }