Table of Contents

Class Config

Namespace
ZapLib.Utility
Assembly
ZapLib.dll

取得應用程式 Config 設定的輔助工具

public static class Config
Inheritance
Config
Inherited Members

Methods

Delete(string)

刪除指定參數名稱的 Config 參數 (如果不存在還是會回 true)

public static bool Delete(string key)

Parameters

key string

參數名稱

Returns

bool

是否刪除成功

DeleteConnectionString(string)

刪除指定連線字串名稱的資料庫連線字串 (不存在仍會回 true)

public static bool DeleteConnectionString(string key)

Parameters

key string

連線字串名稱

Returns

bool

是否執行成功

Get()

取得 App.config 或 Web.config 的 appSetting 中的所有設定

public static NameValueCollection Get()

Returns

NameValueCollection

所有設定 NameValueCollection

Get(string)

取得 App.config 或 Web.config 的 appSetting 中指定名稱的數值,取不到時將回傳 NULL

public static string Get(string key)

Parameters

key string

指定名稱

Returns

string

數值

GetConnectionString(string)

取得 App.config 或 Web.config 的 ConnectionStrings 中指定名稱的數值,取不到時將回傳 NULL

public static string GetConnectionString(string key)

Parameters

key string

指定名稱

Returns

string

數值

GetConnectionStrings()

取得所有資料庫連線字串設定,如果無法取得則回傳 null

public static ConnectionStringSettingsCollection GetConnectionStrings()

Returns

ConnectionStringSettingsCollection

所有資料庫連線字串設定集合

Refresh(string)

刷新 .config 設定檔到記憶體中,預設刷新 appSettings 與 DriveConnectionString 兩個區域

public static void Refresh(string section = null)

Parameters

section string

指定區域,可以不給

SetOrAdd(string, string)

設定既有的或新增全新的 Config 參數 (已存在則會修改,不存在則會新增)

public static bool SetOrAdd(string key, string val)

Parameters

key string

參數名稱

val string

參數數值

Returns

bool

回傳是否執行成功

SetOrAddConnectionString(string, string, string)

設定既有的或新增全新的資料庫連線字串 (已存在則會修改,不存在則會新增)

public static bool SetOrAddConnectionString(string key, string val, string providerName = "System.Data.SqlClient")

Parameters

key string

連線字串名稱

val string

連線字串

providerName string

資料提供者的名稱

Returns

bool

是否執行成功