PowerUpは、.NET Coreの拡張メソッドライブラリであり、フレームワークに有用な機能を追加します。
PowerUpCore Nuget
PowerUpCore Azure Nuget
⏩軽量:目標は5Kメソッドを含むことではなく、日常の有用な方法のみを持っていることです(私の意見では)
.NETコア互換
ユニットテスト
100%文書化
すべての拡張方法が説明されており、次のドキュメントで存在不要を記載しています。
wehatherを確認するために必要な構文を簡素化しますが、文字列コンテンツはinterであるかどうかです。
なぜ?
繰り返しコードを削除します
if ( "42" . IsInteger ( ) )
Foo ( ) ;文字列からパラメーター文字列のコンテンツを削除します。
なぜ?
繰り返しコードを削除します
"My text" . Remove ( "My" ) // result: " text"
// instead of
"My text" . Replace ( "My" , string . Empty ) ; // result: " text"
Foo ( ) ;文字列のメソッド形式のより短い構文を提供します。
なぜ?
コードを短くするため
// .net syntax
string . Format ( "Debug Level: {0} " {1} " {3}" , DebugLevel . Info , "Everything is awesome!" , DateTime . Now ) ;
// PowerUp syntax
"Debug Level: {0} " {1} " {3}" . Format ( DebugLevel . Info , "Everything is awesome!" , DateTime . Now ) ;トリングを列挙に簡単に変換できます。
なぜ?
繰り返しコードを削除します
private enum TestEnum
{
Val1 ,
Val2 ,
Val3
}
var enumVar = "Val1" . ToEnum < TestEnum > ( ) ; 列挙値の読み取り可能な説明を取得できます。
private enum TestEnum
{
[ Description ( "Value with description" ) ]
ValWithDesc = 1 ,
ValNoDesc = 2 ,
AnotherNoDesc = 3
}
var testObject = TestEnum . ValWithDesc ;
string description = testObject . GetDescription ( ) ; コレクションから一度に多くの要素を削除するのに役立ちます。
なぜ?
コレクションに有用な追加機能を提供する
sourceList . RemoveRange ( deleteList ) ;深いコピーフリムを実行します。
var testList = _fixture . Create < List < clonableObj > > ( ) ;
var clone = testList . Clone ( ) ;
clone . First ( ) != testList . First ( )コレクションの最後のインデックスを取得します。
なぜ?
繰り返しコードを削除します
sourceList . GetLastIndex ( ) == ( sourceList . Count - 1 ) 与えられた引数がnullの場合、argumpernullexceptionをスローします。
なぜ?
.NET CoreのGuard.ArgumentNotNullを交換します
objectShouldNotBeNUll . ThrowIfNull ( nameof ( objectShouldNotBeNUll ) ) ;
// Inspired on Microsoft.Practices.EnterpriseLibrary.Common.Utility
Guard . ArgumentNotNull ( objectShouldNotBeNUll , nameof ( objectShouldNotBeNUll ) ) ;オブジェクトがnullかnullであるかを確認します。
なぜ?
構文を作成して、ヌルクリーナーとより人間の読み取り可能なことを確認します
var someObject = new object ( ) ;
//Before
if ( someObject != null )
Foo ( ) ;
//PowerUp
if ( someObject . isNull ( ) )
Foo ( ) ;オブジェクト値が下限と上限の間にあることを確認します。
なぜ?
構文を簡素化して、オンブレクションの値が特定の範囲の間にあることを確認するには
if ( 5 . Between ( 2 , 8 ) )
Foo ( ) ;
if ( 7 . Between ( 7 , 12 , BetweenOptions . Inclusive ) )
Foo ( ) ; 呼び出し方法に関する情報を単純に記録できます。
なぜ?
退屈なコードを避け、貼り付けの問題をコピーするために、次のようなコントローラーメソッドの先頭にあります。
[ HttpPut ]
[ Route ( "[action]" ) ]
[ Produces ( "application/json" ) ]
[ ProducesResponseType ( typeof ( Product ) , StatusCodes . Status201Created ) ]
[ ProducesResponseType ( typeof ( string ) , StatusCodes . Status400BadRequest ) ]
public async Task < IActionResult > AddProduct ( [ FromBody ] NewProduct newProduct )
{
_logger . LogDebug ( $ " { DateTime . UtcNow : dd/MMM/yyyy } | 32: CatalogController.AddProduct()}" ) ;
if ( ! ModelState . IsValid )
return BadRequest ( ModelState ) ;
....ロギング方法は、単純にできるようになりました。
.. .
public async Task < IActionResult > AddProduct ( [ FromBody ] NewProduct newProduct )
{
_logger . LogThisMethod ( ) ;
.. .例から簡単に、コードの拡大とエラーの可能性をどの程度減らすことができるかを確認するのは簡単です
Azureのストレージアクセスキーは、ストレージアカウントにアクセスするための認証に使用されます。
ストレージアカウントを作成すると、2つのストレージアクセスキー、つまりプライマリおよびセカンダリアクセスキーが提供されます。
詳細https://blogs.msdn.microsoft.com/mast/2013/11/06/why-does-an-azure-storage-account-have-two-access-keys/
なぜ?
RedundantParseを使用すると、プライマリキーを使用して冗長に接続するか、Secondに自動的に切り替えます。
< add key = " QueueConnectionString1 " value = " DefaultEndpointsProtocol=https;AccountName=weu########## " />
< add key = " QueueConnectionString2 " value = " DefaultEndpointsProtocol=https;AccountName=weu########## " />
< add key = " QueueReference " value = " myQueueReference " /> var storageAccount = CloudStorageAccountHelper . RedundantParse (
CloudConfigurationManager . GetSetting ( "QueueConnectionString1" ) ,
CloudConfigurationManager . GetSetting ( "QueueConnectionString2" ) ) ;
var queueClient = storageAccount . CreateCloudQueueClient ( ) ;
var myQueue = queueClient . GetQueueReference ( ConfigurationManager . AppSettings [ "QueueReference" ] ) ;