// Copyright (c) Cristian Civera (cristian@aspitalia.com) // This code is distributed under the MS-PL (for details please see \doc\MS-PL.txt) using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Resources; using System.Text; using System.Windows; namespace Ricciolo.StylesExplorer.MarkupReflection { /// /// Rappresenta un singole file Baml all'interno di un assembly /// public class BamlFile : Component { private Uri _uri; private readonly Stream _stream; public BamlFile(Uri uri, Stream stream) { if (uri == null) new ArgumentNullException("uri"); if (stream == null) throw new ArgumentNullException("stream"); _uri = uri; _stream = stream; } /// /// Carica il Baml attraverso il motore di WPF con Application.LoadComponent /// /// public object LoadContent() { try { return Application.LoadComponent(this.Uri); } catch (Exception e) { throw new InvalidOperationException("Invalid baml file.", e); } } protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) this.Stream.Dispose(); } public override object InitializeLifetimeService() { return null; } /// /// Restituisce lo stream originale contenente il Baml /// public Stream Stream { get { return _stream; } } /// /// Restituisce l'indirizzo secondo lo schema pack:// /// public Uri Uri { get { return _uri; } } } }