English 中文(简体)
C# Project and Config files
原标题:C# Projects and Config Files
  • 时间:2012-01-16 06:11:30
  •  标签:
  • c#

I m trying to pull some key/values in my class. This is a C# Class Library Project (not web project) so it s got an App.Config.

在我的C#项目(图书馆)中:

1 D-1, 1 D-1, 1 P-5, 1 P-4, 1 P-3, 1 P-2, 1 GS, 1 NS, 1 UNV a. 从汇件中提取关键/价值的实用方法:

public class ConfigUtil
{
    /// <summary>
    ///  Utility method to retrieve configuration setting values.
    /// </summary>
    /// <param name="configKey">Configuration Settings key to retrieve.</param>
    /// <returns>empty string if key is null</returns>
    public static string GetAppConfigSetting(string configKey)
    {
        return ConfigurationManager.AppSettings[configKey] ?? string.Empty;
    }
}

这一实用方法被用于一个网络项目,我刚刚将这个冰箱复制成我的C#项目,因为我在C#项目中,需要这些 au点和终点站,在我的C#项目中以一些代码与第三方APIC联系。

2)A Config.cs to hold my lookups

class Config
{
    public static string SomeThirdPartyApiEndpoint
    {
        get { return ConfigUtil.GetAppConfigSetting("SomeThirdPartyApiEndpoint"); }
    }

    public static string SomeThirdPartyApiAuthUsername
    {
        get { return ConfigUtil.GetAppConfigSetting("SomeThirdPartyApiAuthUsername"); }
    }

    public static string SomeThirdPartyApiAuthPassword
    {
        get { return ConfigUtil.GetAppConfigSetting("SomeThirdPartyApiAuthPassword"); }
    }
}

页: 1

  <appSettings>
    <add key="SomeThirdPartyApiEndPoint" value="http://someEndPointUrl.com/XMLAPI" />
    <add key="SomeThirdPartyApiAuthUsername" value="someUserNameHere" />
    <add key="SomeThirdPartyApiAuthPassword" value="5233s54" />
  </appSettings>

4) Some example code in one of my classes in this project trying to pull one of the key values:

string password = Config.SomeThirdPartyApiAuthUsername;

这条路线是我的班级方法之一。

www.un.org/Depts/DGACM/index_spanish.htm 问题:没有发现我的任何关键/价值。 当我 de笑时,我听到一个空洞的密码。

我假定我会这样做,因为需要把这些关键/价值列入我的申请书。 因为我没有网络。 因为这不是一个网络项目。 这是我为向第三方APIC索要的包裹项目。

www.un.org/Depts/DGACM/index_spanish.htm 另一个问题涉及:因此,然后将配置管理分类。 AppSettings look for a App.Config if a Web.config is not present? 我很想知道这种组合式的曼纳格是如何拉开的......它只看网。 紧接项目可提供的经费吗?

最佳回答

我认为配置管理小组。 申请人看管方案的配置文件。 如果这是一个图书馆项目,你需要把你希望的环境添加到东道国的议事档案中。

问题回答

某些第三方名称应为:


public static string SomeThirdPartyApiAuthUsername 
{ 
    get { return ConfigUtil.GetAppConfigSetting("SomeThirdPartyApiAuthUsername"); } 
} 

但你的关键是:

"SomeThirdPartyApiUsername"




相关问题
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. ...

热门标签