示例#1
0
        protected override void Initialize(ContentCompiler compiler)
        {
            _compiler = compiler;
            var type = TargetType.BaseType;

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

            if (TargetType.GetCustomAttributes(typeof(ContentSerializerRuntimeTypeAttribute), false)
                .FirstOrDefault() is ContentSerializerRuntimeTypeAttribute runtimeType)
            {
                _runtimeType = runtimeType.RuntimeType;
            }

            if (TargetType.GetCustomAttributes(typeof(ContentSerializerTypeVersionAttribute), false)
                .FirstOrDefault() is ContentSerializerTypeVersionAttribute typeVersion)
            {
                _typeVersion = typeVersion.TypeVersion;
            }

            _properties = TargetType.GetAllProperties().Where(IsValidProperty).ToArray();
            _fields     = TargetType.GetAllFields().Where(IsValidField).ToArray();
        }
        /// <summary>
        /// Creates a new instance of ContentWriter.
        /// </summary>
        /// <param name="compiler">The compiler object that created this writer.</param>
        /// <param name="output">The stream to write the XNB file to.</param>
        /// <param name="targetPlatform">The platform the XNB is intended for.</param>
        /// <param name="targetProfile">The graphics profile of the target.</param>
        /// <param name="compressContent">True if the content should be compressed.</param>
        /// <param name="rootDirectory">The root directory of the content.</param>
        /// <param name="referenceRelocationPath">The path of the XNB file, used to calculate relative paths for external references.</param>
        internal ContentWriter(
            ContentCompiler compiler, Stream output, TargetPlatform targetPlatform, GraphicsProfile targetProfile,
            bool compressContent, string rootDirectory, string referenceRelocationPath)
            : base(output)
        {
            this.compiler        = compiler;
            TargetPlatform       = targetPlatform;
            TargetProfile        = targetProfile;
            this.compressContent = compressContent;
            this.rootDirectory   = rootDirectory;

            // Normalize the directory format so PathHelper.GetRelativePath will compute external references correctly.
            this.referenceRelocationPath = PathHelper.NormalizeDirectory(referenceRelocationPath);

            outputStream = OutStream;
            bodyStream   = RecyclableMemoryManager.Default.GetMemoryStream();
            OutStream    = bodyStream;
        }