English 中文(简体)
我是否应该加上一个习俗部分来评估。 如果是,如何?
原标题:Should I add a custom section to app.config? If so, how?

我有一个方案,定期对某个文件夹进行投票。 当它找到一个记录档案时,它读到它,是它所必须做的,并且是移动的。 记录档案的书写方案保持了备份,而不是重写,因此,我储存了一个经过修改的最后日期和一个书记栏,在我阅读档案时,这些字眼一直到此为止。 迄今为止,一切都很好。

现在,我要坚持我的书记专册,以便如果我关闭选票并重新开始投票,那么每张记录一开始就不再开始。 我不想听说在非行中储存胎儿;一个简单的XML文件就是这样做的。 因此,我想到的是,在app.config文档中储存该信息。

第一个问题是,这是否错了呢? <代码>app.config的意思只是读出,而不是写到操作时间? 在哪一种情况下,合乎逻辑的答案是只写一个单独的xml文档?

第二,如果是科索沃这样做的话:我发现一个冰 b员额,涉及,但似乎将试图用<代码”阅读组合文档的其他部分改写成:ConfigurationManager.AppSettings.Get(key), 电文=“Configuration system does not originalize”。 如何做到这一点?

最佳回答
问题回答

ConfigurationManager是这样做的最容易的方法。 我正在使用这个词,但这里是一个问题。 你们必须知道什么类型的价值:

<configuration>
  <appSettings>
    <add key="MyPropertyOne" value="Hello" />
    <add key="MyPropertyTwo" value="2" />
  </appSettings> 
</configuration>

string propertyOne = (string)ConfigurationManager.AppSettings["MyPropertyOne"];
int propertyTwo = (int)ConfigurationManager.AppSettings["MyPropertyTwo"];

但是,你自己写了

习俗科是一种可贵的工具。 用于严重 app料的护料。

Here is code for custom section IN WEB.CONFIG

<configuration> 
  <configSections>
    <section name="Misc" type="Config"/>    <<-- this registers a custom section called Misc
    <Misc configSource="config_misc.config"/> <<-- this says to look for for it in file "config_misc.config"
    (...)

之后又创建了CONFIG_MISC。 CONFIG 贵国网站的根基,并将其列入

<Misc 
    MySetting1="true" 
 />

TheN in You webapp, in App_CODE rafter, Creat a section such:

using System;
using System.Collections;
using System.Configuration;
using System.Xml;
using System.Collections.Specialized; 


public class Config : ConfigurationSection
{
    private static string _CONFIG_SECTION = "Misc";

    #region singleton implementation
    private static Config _config;
    static Config()
    {
        _config = (Config)ConfigurationSettings.GetConfig(_CONFIG_SECTION);
    }
    #endregion 

    public static bool MySetting1
    {
        get
        {
            return _config._MySetting1;
        }
    }

    #region public properties the define the config items we are looking for
    [ConfigurationProperty("MySetting1", IsRequired = false)]
    public bool _MySetting1
    {
        get
        {
            return (bool)this["MySetting1"];
        }
    }        
    #endregion
} 

这部法典是我的法典的复印件,同时予以废除,即可能犯错,但应该开始。

现在,你只是通过“儒瓦”来达到你的环境,是一种非常简单的方式。 MySetting1

没收档案也有许多好处,特别是在维护和组合方面。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签