예제 #1
0
        Dictionary <string, object> GetResources(string fileName)
        {
            Stream s = null;

            WorkbenchSingleton.SafeThreadCall(
                delegate {
                OpenedFile file = FileService.GetOpenedFile(fileName);
                if (file != null)
                {
                    s = file.OpenRead();
                }
            });
            if (s == null)
            {
                s = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            using (s) {
                using (IResourceReader reader = ResourceStore.CreateResourceReader(s, ResourceStore.GetResourceType(fileName))) {
                    ResXResourceReader resXReader = reader as ResXResourceReader;
                    if (resXReader != null)
                    {
                        resXReader.BasePath = Path.GetDirectoryName(fileName);
                    }

                    var resources = new Dictionary <string, object>();
                    foreach (System.Collections.DictionaryEntry entry in reader)
                    {
                        if (entry.Value == null)
                        {
                            continue;
                        }
                        if (this.requiredResourceType.IsAssignableFrom(entry.Value.GetType()))
                        {
                            resources.Add((string)entry.Key, entry.Value);
                        }
                    }
                    return(resources);
                }
            }
        }