示例#1
0
文件: Main.cs 项目: austhomp/resgenEx
        static IResourceReader GetReader(Stream stream, string name, bool useSourcePath, Options options)
        {
            string format = Path.GetExtension(name);
            switch (format.ToLower(System.Globalization.CultureInfo.InvariantCulture)) {
                case ".po":
                case ".pot":
                    return new PoResourceReader(stream, options);
                case ".isl":
                    return new IslResourceReader(stream, options);
                /* this version has been specialized for use converting between '.resx' 
                 * and '.po' files, other formats will now fail!
                case ".txt":
                case ".text":
                    return new TxtResourceReader (stream);
                case ".resources":
                    return new ResourceReader (stream);*/
                case ".resx":
                    IResourceReader reader = new ResXResourceReader(stream);

                    if (useSourcePath) { // only possible on 2.0 profile, or higher
                        PropertyInfo p = reader.GetType().GetProperty("BasePath",
                            BindingFlags.Public | BindingFlags.Instance);
                        if (p != null && p.CanWrite) {
                            p.SetValue(reader, Path.GetDirectoryName(name), null);
                        }
                    }
                    ((ResXResourceReader)reader).UseResXDataNodes = true;
                    return reader;
                default:
                    throw new Exception("Unknown format in file " + name);
            }
        }