Common tool classes 7-Configuration classes

Source: Internet
Author: User

public static Class Customerconfighelper
{
public static Object _lockobject = new Object ();

private static string Getcustomconfigvalue (String key)
{
String ConfigFilePath = "~/config/customconfig.config";
String configelementsname = "Add";
String configattributekeyname = "Key";
String configattributevaluename = "Value";

Return GetValue (Key,configfilepath, Configelementsname, configattributekeyname,configattributevaluename);
}

private static string GetValue (String key,string configfilepath)
{
String configelementsname = "Add";
String configattributekeyname = "Key";
String configattributevaluename = "Value";

Return GetValue (Key,configfilepath, Configelementsname, configattributekeyname,configattributevaluename);
}

private static string GetValue (string key, String ConfigFilePath, String configelementsname, String Configattributekeyname,string configattributevaluename)
{
String _value = String. Empty;

String _path = HttpContext.Current.Server.MapPath (ConfigFilePath);

XElement _element = Xelement.load (_path);
var _config = from config in _element. Elements (configelementsname) select Config;

dictionary<string, string> _dic = _config. ToDictionary (k = K.attribute (configattributekeyname). Value, k = K.attribute (configattributevaluename). Value);

_dic. TryGetValue (key, out _value);
return _value;
}

//<summary>
//Get custom file Configuration node values: Shaping
//</summary>
//<param name= "key" > Configuration node key</ Param>
//<returns></returns>
public static int Getcustomconfigint (string key)
{
Return Typehelper.toint (Getcustomconfigvalue (key));
}
///<summary>
//Get custom file Configuration node values: Reshape
///</summary>
//<param name= "key" ></ Param>
//<param name= "ConfigFilePath" ></PARAM>
//<returns></returns>
public static int Getcustomconfigint (string key, String ConfigFilePath)
{
return Typehelper.toint (GetValue (Key, ConfigFilePath));
}

//<summary>
//Get custom file Configuration node values: Long shaping
//</summary>
//<param name= "key" > Configuration node key</ Param>
//<returns></returns>
public static long Getcustomconfiglong (string key)
{
Return Typehelper.toint64 (Getcustomconfigvalue (key));
}
///<summary>
//Get custom file Configuration node values: Long reshape
///</summary>
//<param name= "key" ></ Param>
//<param name= "ConfigFilePath" ></PARAM>
//<returns></returns>
public static long Getcustomconfiglong (string key, String ConfigFilePath)
{
return Typehelper.toint64 (GetValue ( Key, ConfigFilePath));
}

<summary>
Gets the custom file configuration node value: string
</summary>
<param name= "key" > Configuration node key</param>
<returns></returns>
public static string getcustomconfigstring (String key)
{
return Getcustomconfigvalue (key);
}
<summary>
Gets the custom file configuration node value: string
</summary>
<param name= "Key" ></param>
<param name= "ConfigFilePath" ></param>
<returns></returns>
public static string Getcustomconfigstring (string key, String ConfigFilePath)
{
Return GetValue (key, ConfigFilePath);
}

}

Common tool classes 7-Configuration classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.