应用程序设置+的DirectoryInfo / FileInfo的 [英] Application Settings + DirectoryInfo/FileInfo

查看:198
本文介绍了应用程序设置+的DirectoryInfo / FileInfo的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是新的C#...我建立一个WPF应用程序,我尝试应用一些用户的应用程序设置。这很容易插入标准的应用程序设置(INT,双,字符串等)。我甚至已经有了类似的WindowState插入。



我想有一个DirectoryInfo的和/或作为的FileInfo可保存设置,而不是字符串。




选择的类型:有System.IO.File给出错误信息抽象类型不支持。




这是有道理的,因为你怎么能实现一个抽象类型设置。




选择的类型:没有定义类型System.IO.FileInfo'。System.IO.FileInfo给出了一个错误信息




时的DirectoryInfo / FileInfo的不可设置为应用程序的设置?是否可以?值得花时间?你怎么能确定什么是可作为一个设定,什么是不?



我与用户设置的经验是有限的,我想在我的知识拓展,这有我难住了。



编辑:我想张贴一些截图,但显然我太新。 。我工作的Visual Studio,应用程序设置里面



进一步指出:



http://msdn.microsoft.com/en-us/library/a65txexh.a​​spx




应用程序设置可以存储为XML是序列化或具有实现的ToString / FromString的TypeConverter任何数据类型。最常见的类型为字符串,整数和布尔,但你也可以存储值的颜色,对象,或作为一个连接字符串。




  DirectoryInfo的DI =新的DirectoryInfo(@C:\); 
di.ToString();



我缺少的东西,因为它的ToString()...


解决方案

是的,这是不可能的。应用程序设置使用XML序列化序列化。一类是可序列化的一个硬的要求是,它需要有一个无参数的构造。无论是类有一个。



这是不是一个真正的问题,因为无论是类有一个构造函数的字符串。因此,请设置一个字符串,你可以得到总能获得一个FileInfo或DirectoryInfo的出来。尽管它必须引用一个真实存在的文件系统对象。如果这是一个问题,那么只是让自己的类。


I'm still new to C#... I'm building a WPF application and I'm trying to apply some User Application Settings. It's easy to insert standard App Settings (int, double, string, etc). I've even got something like WindowState inserted.

I'd like to have a DirectoryInfo and/or FileInfo as savable settings instead of Strings.

Selected type: System.IO.File gives an error message "Abstract types are not supported".

Which makes sense, since how can you implement an abstract type as a setting.

Selected type: System.IO.FileInfo gives an error message of "Type 'System.IO.FileInfo' is not defined.".

Is DirectoryInfo/FileInfo not settable as App Settings? Is it possible? Worth the time? How can you determine what is usable as a setting and what isn't?

My experience with user settings is limited and I'm trying to expand upon my knowledge and this has me stumped.

edit: I tried to post some screenshots, but apparently I'm too new. I'm working inside of Visual Studio, Application Settings.

further notes:

http://msdn.microsoft.com/en-us/library/a65txexh.aspx

Application settings can be stored as any data type that is XML serializable or has a TypeConverter that implements ToString/FromString. The most common types are String, Integer, and Boolean, but you can also store values as Color, Object, or as a connection string.

DirectoryInfo di = new DirectoryInfo(@"C:\");
di.ToString();

Am I missing something, as it has ToString()...

解决方案

Yes, this is not possible. Application settings are serialized using XML serialization. One hard requirement for a class to be serializable is that it needs to have a parameter-less constructor. Neither class has one.

This isn't a real problem because either class has a constructor that takes a string. So, make the setting a string and you can get always get a FileInfo or a DirectoryInfo out of it. Albeit that it must refer to a file system object that exists. If that's an issue then just make your own class.

这篇关于应用程序设置+的DirectoryInfo / FileInfo的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆