/// <summary> /// Creates a new AssemblyResourceReader object /// </summary> public AssemblyResourceReader(Type targetType) { m_targetType = targetType; TypeInfo targetTypeInfo = m_targetType.GetTypeInfo(); m_targetAssembly = targetTypeInfo.Assembly; m_resources = new List <AssemblyResourceInfo>(); m_resourcesDict = new Dictionary <string, AssemblyResourceInfo>(); foreach (AssemblyResourceFileAttribute actAttrib in targetTypeInfo.GetCustomAttributes <AssemblyResourceFileAttribute>()) { ManifestResourceInfo resInfo = m_targetAssembly.GetManifestResourceInfo(actAttrib.ResourcePath); if (resInfo != null) { AssemblyResourceInfo fileInfo = new AssemblyResourceInfo(m_targetAssembly, actAttrib.ResourcePath, actAttrib.Key); m_resources.Add(fileInfo); if ((actAttrib.Key != null) && (!m_resourcesDict.ContainsKey(actAttrib.Key))) { m_resourcesDict.Add(actAttrib.Key, fileInfo); } } else { throw new SeeingSharpException("Resource " + actAttrib.ResourcePath + " not found!"); } } m_publicResources = new ResourceInfoCollection(this); }
/// <summary> /// Opens the resource with the given key for reading /// </summary> public Stream OpenRead(string key) { AssemblyResourceInfo info = m_resourcesDict[key]; return(info.OpenRead()); }
/// <summary> /// Opens the resource at the given index for reading /// </summary> public Stream OpenRead(int index) { AssemblyResourceInfo info = m_resources[index]; return(info.OpenRead()); }