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