コード例 #1
0
        protected override void Initialize(ContentCompiler compiler)
        {
            _compiler = compiler;
            var type = ReflectionHelpers.GetBaseType(TargetType);

            if (type != null && type != typeof(object) && !TargetType.IsValueType)
            {
                _baseType = type;
            }

            var runtimeType = TargetType.GetCustomAttributes(typeof(ContentSerializerRuntimeTypeAttribute), false).FirstOrDefault() as ContentSerializerRuntimeTypeAttribute;

            if (runtimeType != null)
            {
                _runtimeType = runtimeType.RuntimeType;
            }

            var typeVersion = TargetType.GetCustomAttributes(typeof(ContentSerializerTypeVersionAttribute), false).FirstOrDefault() as ContentSerializerTypeVersionAttribute;

            if (typeVersion != null)
            {
                _typeVersion = typeVersion.TypeVersion;
            }

            _properties = TargetType.GetAllProperties().Where(IsValidProperty).ToArray();
            _fields     = TargetType.GetAllFields().Where(IsValidField).ToArray();
        }
コード例 #2
0
ファイル: ReflectiveReader.cs プロジェクト: jocamar/Caravel
        protected internal override void Initialize(ContentTypeReaderManager manager)
        {
            base.Initialize(manager);

            var baseType = ReflectionHelpers.GetBaseType(TargetType);

            if (baseType != null && baseType != typeof(object))
            {
                _baseTypeReader = manager.GetTypeReader(baseType);
            }

            _constructor = TargetType.GetDefaultConstructor();

            var properties = TargetType.GetAllProperties();
            var fields     = TargetType.GetAllFields();

            _readers = new List <ReadElement>(fields.Length + properties.Length);

            // Gather the properties.
            foreach (var property in properties)
            {
                var read = GetElementReader(manager, property);
                if (read != null)
                {
                    _readers.Add(read);
                }
            }

            // Gather the fields.
            foreach (var field in fields)
            {
                var read = GetElementReader(manager, field);
                if (read != null)
                {
                    _readers.Add(read);
                }
            }
        }
コード例 #3
0
ファイル: ReflectiveReader.cs プロジェクト: khbecker/FNA
        protected internal override void Initialize(ContentTypeReaderManager manager)
        {
            base.Initialize(manager);

            Type baseType = TargetType.BaseType;

            if (baseType != null && baseType != typeof(object))
            {
                baseTypeReader = manager.GetTypeReader(baseType);
            }

            constructor = TargetType.GetDefaultConstructor();

            PropertyInfo[] properties = TargetType.GetAllProperties();
            FieldInfo[]    fields     = TargetType.GetAllFields();
            readers = new List <ReadElement>(fields.Length + properties.Length);

            // Gather the properties.
            foreach (PropertyInfo property in properties)
            {
                ReadElement read = GetElementReader(manager, property);
                if (read != null)
                {
                    readers.Add(read);
                }
            }

            // Gather the fields.
            foreach (FieldInfo field in fields)
            {
                ReadElement read = GetElementReader(manager, field);
                if (read != null)
                {
                    readers.Add(read);
                }
            }
        }
コード例 #4
0
        protected internal override void Initialize(IntermediateSerializer serializer)
        {
            var properties = TargetType.GetAllProperties();

            foreach (var prop in properties)
            {
                ElementInfo info;
                if (GetElementInfo(serializer, prop, out info))
                {
                    _elements.Add(info.Name, info);
                }
            }

            var fields = TargetType.GetAllFields();

            foreach (var field in fields)
            {
                ElementInfo info;
                if (GetElementInfo(serializer, field, out info))
                {
                    _elements.Add(info.Name, info);
                }
            }
        }