//FIXME: .net doesnt instantiate encoding at this stage ResXFileRef BuildFileRef(string dataString, string basePath) { ResXFileRef fr; string[] parts = ResXFileRef.Parse(dataString); if (parts.Length < 2) { throw new ArgumentException("ResXFileRef cannot be generated"); } string fileName = parts[0]; if (basePath != null) { fileName = Path.Combine(basePath, parts[0]); } string typeName = parts[1]; if (parts.Length == 3) { Encoding encoding = Encoding.GetEncoding(parts[2]); fr = new ResXFileRef(fileName, typeName, encoding); } else { fr = new ResXFileRef(fileName, typeName); } return(fr); }
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { byte[] buffer; if (!(value is String)) { return(null); } string [] parts = ResXFileRef.Parse((string)value); if (parts.Length == 1) { throw new ArgumentException("value"); } string filename = parts [0]; if (Path.DirectorySeparatorChar == '/') { filename = filename.Replace("\\", "/"); } Type type = Type.GetType(parts [1]); if (type == typeof(string)) { Encoding encoding; if (parts.Length > 2) { encoding = Encoding.GetEncoding(parts [2]); } else { encoding = Encoding.Default; } using (TextReader reader = new StreamReader(filename, encoding)) { return(reader.ReadToEnd()); } } using (FileStream file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { buffer = new byte [file.Length]; file.Read(buffer, 0, (int)file.Length); } if (type == typeof(System.Byte[])) { return(buffer); } //if (type == typeof (Bitmap) && Path.GetExtension (filename) == ".ico") { // MemoryStream ms = new MemoryStream (buffer); // return new Icon (ms).ToBitmap (); //} if (type == typeof(MemoryStream)) { return(new MemoryStream(buffer)); } return(Activator.CreateInstance(type, BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.Instance, null, new object[] { new MemoryStream(buffer) }, culture)); }