/// <summary>
        ///     Fetches all of the processors for the given type.
        /// </summary>
        private List <fsObjectProcessor> GetProcessors(Type type)
        {
            List <fsObjectProcessor> processors;

            // Check to see if the user has defined a custom processor for the type. If they
            // have, then we don't need to scan through all of the processor to check which
            // one can process the type; instead, we directly use the specified processor.
            fsObjectAttribute attr = fsPortableReflection.GetAttribute <fsObjectAttribute>(type);

            if (attr != null && attr.Processor != null)
            {
                fsObjectProcessor processor = (fsObjectProcessor)Activator.CreateInstance(attr.Processor);
                processors = new List <fsObjectProcessor>();
                processors.Add(processor);
                _cachedProcessors[type] = processors;
            }

            else if (_cachedProcessors.TryGetValue(type, out processors) == false)
            {
                processors = new List <fsObjectProcessor>();

                for (int i = 0; i < _processors.Count; ++i)
                {
                    fsObjectProcessor processor = _processors[i];
                    if (processor.CanProcess(type))
                    {
                        processors.Add(processor);
                    }
                }

                _cachedProcessors[type] = processors;
            }

            return(processors);
        }
Esempio n. 2
0
        // Token: 0x060004D1 RID: 1233 RVA: 0x0001DB68 File Offset: 0x0001BD68
        private static void CollectProperties(fsConfig config, List <fsMetaProperty> properties, Type reflectedType)
        {
            bool flag  = config.DefaultMemberSerialization == fsMemberSerialization.OptIn;
            bool flag2 = config.DefaultMemberSerialization == fsMemberSerialization.OptOut;
            fsObjectAttribute attribute = fsPortableReflection.GetAttribute <fsObjectAttribute>(reflectedType);

            if (attribute != null)
            {
                flag  = (attribute.MemberSerialization == fsMemberSerialization.OptIn);
                flag2 = (attribute.MemberSerialization == fsMemberSerialization.OptOut);
            }
            MemberInfo[] declaredMembers = reflectedType.GetDeclaredMembers();
            MemberInfo[] array           = declaredMembers;
            MemberInfo   member;

            for (int i = 0; i < array.Length; i++)
            {
                member = array[i];
                if (!config.IgnoreSerializeAttributes.Any((Type t) => fsPortableReflection.HasAttribute(member, t)))
                {
                    PropertyInfo propertyInfo = member as PropertyInfo;
                    FieldInfo    fieldInfo    = member as FieldInfo;
                    if (propertyInfo != null || fieldInfo != null)
                    {
                        if (propertyInfo == null || config.EnablePropertySerialization)
                        {
                            if (!flag || config.SerializeAttributes.Any((Type t) => fsPortableReflection.HasAttribute(member, t)))
                            {
                                if (!flag2 || !config.IgnoreSerializeAttributes.Any((Type t) => fsPortableReflection.HasAttribute(member, t)))
                                {
                                    if (propertyInfo != null)
                                    {
                                        if (fsMetaType.CanSerializeProperty(config, propertyInfo, declaredMembers, flag2))
                                        {
                                            properties.Add(new fsMetaProperty(config, propertyInfo));
                                        }
                                    }
                                    else if (fieldInfo != null && fsMetaType.CanSerializeField(config, fieldInfo, flag2))
                                    {
                                        properties.Add(new fsMetaProperty(config, fieldInfo));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (reflectedType.Resolve().BaseType != null)
            {
                fsMetaType.CollectProperties(config, properties, reflectedType.Resolve().BaseType);
            }
        }
Esempio n. 3
0
        private static void CollectProperties(fsConfig config, List <fsMetaProperty> properties, Type reflectedType)
        {
            // do we require a [SerializeField] or [fsProperty] attribute?
            bool requireOptIn  = config.DefaultMemberSerialization == fsMemberSerialization.OptIn;
            bool requireOptOut = config.DefaultMemberSerialization == fsMemberSerialization.OptOut;

            fsObjectAttribute attr = fsPortableReflection.GetAttribute <fsObjectAttribute>(reflectedType);

            if (attr != null)
            {
                requireOptIn  = attr.MemberSerialization == fsMemberSerialization.OptIn;
                requireOptOut = attr.MemberSerialization == fsMemberSerialization.OptOut;
            }

            MemberInfo[] members = reflectedType.GetDeclaredMembers();
            foreach (MemberInfo member in members)
            {
                // We don't serialize members annotated with any of the ignore
                // serialize attributes
                if (config.IgnoreSerializeAttributes.Any(t => fsPortableReflection.HasAttribute(member, t)))
                {
                    continue;
                }

                PropertyInfo property = member as PropertyInfo;
                FieldInfo    field    = member as FieldInfo;

                // Early out if it's neither a field or a property, since we
                // don't serialize anything else.
                if (property == null && field == null)
                {
                    continue;
                }

                // Skip properties if we don't want them, to avoid the cost of
                // checking attributes.
                if (property != null && !config.EnablePropertySerialization)
                {
                    continue;
                }

                // If an opt-in annotation is required, then skip the property if
                // it doesn't have one of the serialize attributes
                if (requireOptIn &&
                    !config.SerializeAttributes.Any(t => fsPortableReflection.HasAttribute(member, t)))
                {
                    continue;
                }

                // If an opt-out annotation is required, then skip the property
                // *only if* it has one of the not serialize attributes
                if (requireOptOut &&
                    config.IgnoreSerializeAttributes.Any(t => fsPortableReflection.HasAttribute(member, t)))
                {
                    continue;
                }

                if (property != null)
                {
                    if (CanSerializeProperty(config, property, members, requireOptOut))
                    {
                        properties.Add(new fsMetaProperty(config, property));
                    }
                }
                else if (field != null)
                {
                    if (CanSerializeField(config, field, requireOptOut))
                    {
                        properties.Add(new fsMetaProperty(config, field));
                    }
                }
            }

            if (reflectedType.Resolve().BaseType != null)
            {
                CollectProperties(config, properties, reflectedType.Resolve().BaseType);
            }
        }
Esempio n. 4
0
        private static void CollectProperties(List <fsMetaProperty> properties, Type reflectedType)
        {
            // do we require a [SerializeField] or [fsProperty] attribute?
            bool requireOptIn  = fsConfig.DefaultMemberSerialization == fsMemberSerialization.OptIn;
            bool requireOptOut = fsConfig.DefaultMemberSerialization == fsMemberSerialization.OptOut;

            fsObjectAttribute attr = fsPortableReflection.GetAttribute <fsObjectAttribute>(reflectedType);

            if (attr != null)
            {
                requireOptIn  = attr.MemberSerialization == fsMemberSerialization.OptIn;
                requireOptOut = attr.MemberSerialization == fsMemberSerialization.OptOut;
            }

            MemberInfo[] members = reflectedType.GetDeclaredMembers();
            foreach (var member in members)
            {
                // We don't serialize members annotated with any of the ignore serialize attributes
                if (fsConfig.IgnoreSerializeAttributes.Any(t => fsPortableReflection.HasAttribute(member, t)))
                {
                    continue;
                }

                PropertyInfo property = member as PropertyInfo;
                FieldInfo    field    = member as FieldInfo;

                // If an opt-in annotation is required, then skip the property if it doesn't have one
                // of the serialize attributes
                if (requireOptIn &&
                    !fsConfig.SerializeAttributes.Any(t => fsPortableReflection.HasAttribute(member, t)))
                {
                    continue;
                }

                // If an opt-out annotation is required, then skip the property *only if* it has one of
                // the not serialize attributes
                if (requireOptOut &&
                    fsConfig.IgnoreSerializeAttributes.Any(t => fsPortableReflection.HasAttribute(member, t)))
                {
                    continue;
                }

                if (property != null)
                {
                    if (CanSerializeProperty(property, members, requireOptOut))
                    {
                        properties.Add(new fsMetaProperty(property));
                    }
                }
                else if (field != null)
                {
                    if (CanSerializeField(field, requireOptOut))
                    {
                        properties.Add(new fsMetaProperty(field));
                    }
                }
            }

            if (reflectedType.Resolve().BaseType != null)
            {
                CollectProperties(properties, reflectedType.Resolve().BaseType);
            }
        }
        /// <summary>
        ///     Fetches a converter that can serialize/deserialize the given type.
        /// </summary>
        private fsBaseConverter GetConverter(Type type, Type overrideConverterType)
        {
            // Use an override converter type instead if that's what the user has requested.
            if (overrideConverterType != null)
            {
                fsBaseConverter overrideConverter;
                if (_cachedConverterTypeInstances.TryGetValue(overrideConverterType, out overrideConverter) == false)
                {
                    overrideConverter            = (fsBaseConverter)Activator.CreateInstance(overrideConverterType);
                    overrideConverter.Serializer = this;
                    _cachedConverterTypeInstances[overrideConverterType] = overrideConverter;
                }

                return(overrideConverter);
            }

            // Try to lookup an existing converter.
            fsBaseConverter converter;

            if (_cachedConverters.TryGetValue(type, out converter))
            {
                return(converter);
            }

            // Check to see if the user has defined a custom converter for the type. If they
            // have, then we don't need to scan through all of the converters to check which
            // one can process the type; instead, we directly use the specified converter.
            {
                fsObjectAttribute attr = fsPortableReflection.GetAttribute <fsObjectAttribute>(type);
                if (attr != null && attr.Converter != null)
                {
                    converter            = (fsBaseConverter)Activator.CreateInstance(attr.Converter);
                    converter.Serializer = this;
                    return(_cachedConverters[type] = converter);
                }
            }

            // Check for a [fsForward] attribute.
            {
                fsForwardAttribute attr = fsPortableReflection.GetAttribute <fsForwardAttribute>(type);
                if (attr != null)
                {
                    converter            = new fsForwardConverter(attr);
                    converter.Serializer = this;
                    return(_cachedConverters[type] = converter);
                }
            }


            // There is no specific converter specified; try all of the general ones to see
            // which ones matches.
            if (_cachedConverters.TryGetValue(type, out converter) == false)
            {
                if (_availableDirectConverters.ContainsKey(type))
                {
                    converter = _availableDirectConverters[type];
                    return(_cachedConverters[type] = converter);
                }
                for (int i = 0; i < _availableConverters.Count; ++i)
                {
                    if (_availableConverters[i].CanProcess(type))
                    {
                        converter = _availableConverters[i];
                        return(_cachedConverters[type] = converter);
                    }
                }
            }

            throw new InvalidOperationException("Internal error -- could not find a converter for " + type);
        }