2019年11月24日 星期日

.Net Core Console使用依賴注入

public static async Task Main(string[] args)
{

     // 取得設定檔
      IConfiguration config = new ConfigurationBuilder()
                             .AddJsonFile("appsettings.json", true, true)
                             .Build();
    // 建立容器
    var serviceCollection = new ServiceCollection();

    // 註冊服務
    serviceCollection.AddTransient();
    serviceCollection.AddTransient();

    // 加入SqlServer 連線字串
    serviceCollection.AddDbContext(options => options.UseSqlServer(config["ConnectionStrings:DefaultConnection"]));

    // 建立依賴服務提供者
    var serviceProvider = serviceCollection.BuildServiceProvider();

    // 執行
    await serviceProvider.GetRequiredService().Run();
}

C# 比較字串不分大小寫

除了把字串ToUpper() 或 ToLower() 以外

還可以用 String.Compare()
//最後一個參數改成true 就可以忽略大小寫
String.Compare(strSource, strTarget, true) 
回傳為0 即相等


而另外一種我最常用來做搜尋的方法是Contains()

sourceString.Contains("Search-Word", StringComparison.InvariantCultureIgnoreCase, 
new System.Globalization.CultureInfo("en-US")));

2019年3月4日 星期一

移除警告



當出現很多警告

如果要讓警告消失,用NotePad++ 開啟專案檔編輯,
加入 <DependsOnNETStandard>true</DependsOnNETStandard>






這樣一來 警告就不會再出現了

2018年12月4日 星期二

[SQL] 複製資料結構


複製資料結構
Select * into NewTable
From OldTable
Where 1=0

複製TABLE資料結構和資料

Select * into NewTable From OldTable

2018年3月15日 星期四

Emmet(一)

這是一款強大的前端開發工具,早期設計Html、CSS總是要手刻畫面,這套軟件大大幫助前端設計師提升開發速度
建議可搭配Sublime、Visual Studio Code等

前言

具有CSS和Html網頁基礎

為什麼要學習Emmet的三大理由

  1. 加快開發速率
  2. 簡單、好用、易學習
  3. 加強自己對Html和CSS的結構學習,讓前端程式不再凌亂

基本語法介紹

  • 凡要使用Emmet 下完語法 按TAB鍵

  • 用 ‘>’ 串接 html 的層級

  • 用 ‘+’ 串接同階層

  • 打Emmet不要Key空白鍵

  • html tag 直接輸入關鍵字,不用輸入’<‘ 和 ‘>’

進階語法與實例

  1. 新增html 5 的檔案: html:5 (按Tab)
    EMMET1

  2. 創建html 架構 範例

div>h1+div#main>div.site>nav>ul#Item>(li.item$>span{this is my item})*5

Emmet03

這一串看起來很複雜嗎?
不要緊張 很簡單的!
讓我們看下圖,顯示結果

EMMET03

語法 說明
# Tag 加入id
. Tag 加入class
$ 自動編碼 1,2,3 依序如下,如果想要二位數編碼01,02,03 可寫成‘$$’
*N 產生N個Tag
{} Tag加入描述內容
[] 加入屬性

補充說明:

如果想要預設起始值,可以使用’@‘

div.mydiv$@3*2

產生兩個div class各為mydiv3, mydiv4

EMMET05

若想要在Tag加入屬性,可以參考下圖

EMMET06