public bool TryGet(USerializer serializer, Type type, out DataSerializer serializationMethods)
        {
            serializationMethods = default;

            if (type.IsConstructedGenericType == false)
            {
                return(false);
            }

            if (type.GetGenericTypeDefinition() != typeof(List <>))
            {
                return(false);
            }

            if (serializer.DataTypesDatabase.TryGet(out ArrayDataTypeLogic arrayDataTypeLogic) == false)
            {
                return(false);
            }

            var elementType = type.GetGenericArguments()[0];

            if (serializer.TryGetDataSerializer(elementType, out var elementDataSerializer, false) == false)
            {
                serializationMethods = default;
                return(false);
            }

            serializationMethods = new ListDataSerializer(type, elementType, elementDataSerializer, arrayDataTypeLogic.Value);
            return(true);
        }
Exemple #2
0
        public bool TryGet(USerializer serializer, Type type, out DataSerializer serializationMethods)
        {
            serializationMethods = default;

            if (serializer.DataTypesDatabase.TryGet(out ObjectDataTypeLogic dataTypeLogic) == false)
            {
                return(false);
            }

            if (type.IsArray)
            {
                return(false);
            }

            if (type.IsValueType == false)
            {
                return(false);
            }

            if (type.IsPrimitive)
            {
                return(false);
            }

            if (serializer.SerializationPolicy.ShouldSerialize(type) == false)
            {
                return(false);
            }

            serializationMethods = new StructDataSerializer(type, dataTypeLogic.Value);
            return(true);
        }
        public bool TryGet(USerializer serializer, Type type, out DataSerializer serializationMethods)
        {
            serializationMethods = default;

            if (type.IsArray == false)
            {
                serializationMethods = default;
                return(false);
            }

            if (type.GetArrayRank() > 1)
            {
                serializationMethods = default;
                return(false);
            }

            if (serializer.DataTypesDatabase.TryGet(out ArrayDataTypeLogic arrayDataTypeLogic) == false)
            {
                return(false);
            }

            var elementType = type.GetElementType();

            if (serializer.TryGetDataSerializer(elementType, out var elementSerializer, false) == false)
            {
                serializationMethods = default;
                return(false);
            }

            serializationMethods = new ArrayDataSerializer(elementType, elementSerializer, arrayDataTypeLogic.Value);
            return(true);
        }
Exemple #4
0
        public MemberAdder(USerializer serializer)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            _serializer = serializer;
            _members    = new List <MemberSerializerStruct>(6);
        }
Exemple #5
0
        public override bool TryInitialize(USerializer serializer)
        {
            if (serializer.DataTypesDatabase.TryGet(out ObjectDataTypeLogic objectDataTypeLogic))
            {
                _dataType = objectDataTypeLogic.Value;
                return(true);
            }

            return(false);
        }
        protected override void Initialize(USerializer serializer)
        {
            _elementSerializer.RootInitialize(serializer);

            _elementDataType = _elementSerializer.GetDataType();

            if (_elementDataType == DataType.None)
            {
                serializer.Logger.Error("Element data type is none, something went wrong!");
            }
        }
Exemple #7
0
        public bool TryGet(USerializer serializer, Type type, out DataSerializer serializationMethods)
        {
            if (type.IsEnum)
            {
                var enumType = type.GetEnumUnderlyingType();
                return(serializer.TryGetDataSerializer(enumType, out serializationMethods, false));
            }

            serializationMethods = default;
            return(false);
        }
        public override bool TryInitialize(USerializer serializer)
        {
            var typeLogic = serializer.DataTypesDatabase;

            if (typeLogic.TryGet(out SingleDataTypeLogic arrayDataTypeLogic) == false)
            {
                return(false);
            }

            _dataType = arrayDataTypeLogic.Value;
            return(true);
        }
Exemple #9
0
        public static                  FieldData[] GetFields(Type type, USerializer uSerializer, bool initializeDataSerializer = true)
        {
            var bindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            using (var fieldsIterator = new TypeFieldsIterator(8))
            {
                var size   = fieldsIterator.Fill(type, bindingFlags);
                var fields = new FieldData[size];
                var index  = 0;

                for (var i = 0; i < size; i++)
                {
                    var fieldInfo = fieldsIterator[i];

                    if (uSerializer.SerializationPolicy.ShouldSerialize(fieldInfo) == false)
                    {
                        continue;
                    }

                    if (uSerializer.TryGetDataSerializer(fieldInfo.FieldType,
                                                         out var serializationMethods,
                                                         initializeDataSerializer) == false)
                    {
                        continue;
                    }

                    if (serializationMethods == null)
                    {
                        throw new Exception($"Returned null serializer for {fieldInfo.FieldType}");
                    }

                    var fieldOffset = UnsafeUtils.GetFieldOffset(fieldInfo);
                    if (fieldOffset > short.MaxValue)
                    {
                        throw new Exception("Field offset way to big!");
                    }

                    var alternateNames = uSerializer.SerializationPolicy.GetAlternateNames(fieldInfo);

                    fields[index] = new FieldData(fieldInfo.Name, alternateNames, serializationMethods, (ushort)fieldOffset);
                    index++;
                }

                if (index != fields.Length)
                {
                    Array.Resize(ref fields, index);
                }

                OrderFields(fields);

                return(fields);
            }
        }
        public override bool TryInitialize(USerializer serializer)
        {
            _serializer = serializer;
            var type = typeof(TSurrogate);

            if (_serializer.TryGetDataSerializer(type, out _dataSerializer, false))
            {
                return(true);
            }

            _serializer.Logger.Error($"Could not get serialization data for {type}");
            return(false);
        }
Exemple #11
0
        protected override void Initialize(USerializer serializer)
        {
            var adder = new StructMemberAdder <T>(serializer);

            LocalInit(adder);
            var members = adder.GetMembers();

            _memberSerializer = new MemberSerializer(members, serializer.DataTypesDatabase);

            foreach (var member in _memberSerializer.Members)
            {
                member.DataSerializer.RootInitialize(serializer);
            }
        }
Exemple #12
0
        public void RootInitialize(USerializer serializer)
        {
            if (_initialized)
            {
                return;
            }

            _initialized = true;

            Initialize(serializer);

            var dataType = GetDataType();

            if (dataType == DataType.None)
            {
                serializer.Logger.Error($"Data type is none {this}, something went wrong!");
            }
        }
Exemple #13
0
        public override bool TryInitialize(USerializer serializer)
        {
            var typeLogic = serializer.DataTypesDatabase;

            if (typeLogic.TryGet(out BooleanDataTypeLogic result) == false)
            {
                return(false);
            }

            _elementDataType = result.Value;

            if (typeLogic.TryGet(out ArrayDataTypeLogic arrayDataTypeLogic) == false)
            {
                return(false);
            }

            _dataType = arrayDataTypeLogic.Value;
            return(true);
        }
Exemple #14
0
        public bool TryGet(USerializer serializer, Type type, out DataSerializer dataSerializer)
        {
            if (_map.TryGetValue(type, out var serializerType))
            {
                var instance = (CustomDataSerializer)Activator.CreateInstance(serializerType);

                if (instance.TryInitialize(serializer) == false)
                {
                    dataSerializer = default;
                    return(false);
                }

                dataSerializer = instance;
                return(true);
            }

            dataSerializer = default;
            return(false);
        }
Exemple #15
0
        protected override void Initialize(USerializer serializer)
        {
            var fields = FieldData.GetFields(_type, serializer);

            _fieldsSerializer = new FieldsSerializer(fields, serializer.DataTypesDatabase);
        }
Exemple #16
0
 protected abstract void Initialize(USerializer serializer);
Exemple #17
0
 public ClassMemberAdder(USerializer serializer) : base(serializer)
 {
 }
Exemple #18
0
 protected override void Initialize(USerializer serializer)
 {
     _dataSerializer.RootInitialize(serializer);
 }
Exemple #19
0
 public StructMemberAdder(USerializer serializer) : base(serializer)
 {
 }
Exemple #20
0
 public virtual bool TryInitialize(USerializer serializer)
 {
     return(true);
 }
Exemple #21
0
 protected override void Initialize(USerializer serializer)
 {
 }