Beispiel #1
0
        /// <summary>
        /// 创建动态序列化器
        /// </summary>
        /// <param name="type"></param>
        public DynmaicClassSerialize()
        {
            var type = typeof(T);

            if (CheckTypeLoopRefer(type))
            {
                throw new System.Exception($"检查到序列化的对象中包含有循环引用。错误类型 :{type.FullName}");
            }
            this._serializerType = type;
            var serializerAttr = type.GetTypeSerializeAttr();

            this._serializerName = serializerAttr.TypeCode.IsEmpty(type.FullName);

            var ctor = type.GetConstructor(Type.EmptyTypes);

            if (ctor == null)
            {
                throw Error.NonEmptyCtor(type);
            }

            var r  = GenerateReadMethod(type);
            var w  = GenerateWriteMethod(type);
            var ur = GenerateUnsafeReadMethod(type);

            this.ReaderInfo       = r;
            this.WriterInfo       = w;
            this.UnsafeReaderInfo = ur;


            WriterHandle       = (Writer)w.CreateDelegate(typeof(Writer));
            ReaderHandle       = (Reader)r.CreateDelegate(typeof(Reader));
            UnsafeReaderHandle = ur?.CreateDelegate(typeof(delUnsafeReaderMethod)) as delUnsafeReaderMethod;
        }
Beispiel #2
0
        public unsafe override System.Reflection.MethodInfo GetUnsafeReaderMethod()
        {
            delUnsafeReaderMethod reader = UnsafeRead;

            return(reader.Method);
        }
        public unsafe override MethodInfo GetUnsafeReaderMethod()
        {
            delUnsafeReaderMethod reader = UnsafeRead;

            return(reader.Method);
        }