Skip to content

Commit 78d8abb

Browse files
committed
New extensions added, Fix digital storage measurements, Update readme.
1 parent 7ac02c0 commit 78d8abb

File tree

4 files changed

+351
-23
lines changed

4 files changed

+351
-23
lines changed

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<br/>
77

88
# FluentExtensions
9-
Fluent Extensions is a set of more than 80 .NET extensions, it especially made for helping developers to focus on the main tasks rather than get distracted by writing the same code again and again.
9+
Fluent Extensions is a set of more than 100 .NET extensions, it especially made for helping developers to focus on the main tasks rather than get distracted by writing the same code again and again for simple actions, FluentExtensions akso increases readability.
1010

1111
### Install FluentExtensions via NuGet
1212

@@ -16,6 +16,7 @@ To install FluentExtensions, run the following command in the Package Manager Co
1616

1717
```
1818
PM> Install-Package FluentExtensions.NET
19+
1920
```
2021

2122
### Documentations
@@ -104,6 +105,18 @@ double ToGB(this int number, DigitalStorage from = DigitalStorage.GB);
104105
// Converts the given number to terabytes.
105106
double ToTB(this int number, DigitalStorage from = DigitalStorage.TB)
106107

108+
// Converts given number to kilobytes.
109+
double ToKB(this long number, DigitalStorage from = DigitalStorage.KB);
110+
111+
// Converts given number to megabytes.
112+
double ToMB(this long number, DigitalStorage from = DigitalStorage.MB);
113+
114+
// Converts the given number to gigabytes.
115+
double ToGB(this long number, DigitalStorage from = DigitalStorage.GB);
116+
117+
// Converts the given number to terabytes.
118+
double ToTB(this long number, DigitalStorage from = DigitalStorage.TB)
119+
107120

108121
```
109122

@@ -192,6 +205,44 @@ string Take(this string source, int characters, Position from = Position.Start);
192205
// Replaces multiple values inside a string with one value.
193206
string ReplaceMultipleWithOne(this string source, string[] values, string value);
194207

208+
// Gets the free space of the given drive in gigabytes.
209+
public static string DriveFreeSpace(this string driveLetter);
210+
211+
// Gets the total size of the given drive in gigabytes.
212+
public static string DriveTotalSize(this string driveLetter);
213+
214+
// Gets the total size of the given drive in gigabytes.
215+
public static string DriveTotalSize(this string driveLetter);
216+
217+
// Gets the format of the given drive.
218+
public static string DriveFormat(this string driveLetter);
219+
220+
// Gets the type of the given drive.
221+
public static DriveType DriveType(this string driveLetter);
222+
223+
// Delete the given file from disk.
224+
public static void DeleteFile(this string filePath);
225+
226+
// Hides the given file from disk.
227+
public static void HideFile(this string filePath);
228+
229+
// Shows the given file from disk (if it's already hidden).
230+
public static void ShowFile(this string filePath);
231+
232+
// Gets the date and time when this given file created.
233+
public static DateTime CreatedDate(this string filePath);
234+
235+
// Copies the file to the given destination (overwrites it if it's already exist).
236+
public static void CopyFile(this string filePath, string destination);
237+
238+
// Moves the file to the given destination (overwrites it if it's already exist).
239+
public static void MoveFile(this string filePath, string destination);
240+
241+
// Gets the file size in kilobytes.
242+
public static double FileSizeInKB(this string filePath);
243+
244+
// Gets the file size in megabytes.
245+
public static double FileSizeInMB(this string filePath);
195246

196247

197248
```

src/FluentExtensions/FluentExtensions.csproj

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,24 @@
1111
<PackageTags>extension, datetime, date, dotnet, extension-methods, fluent, string-matching, stringextensions, fluentextension, fluentextensions, numericxtensions</PackageTags>
1212
<PackageReleaseNotes>
1313
New Extensions Added:
14-
- string AddToEnd(this string text, string textToAdd, bool addSpaceBeforeAddition = true);
15-
- string AddToStart(this string text, string textToAdd, bool addSpaceafterAddition = true);
16-
- string ReplaceMultipleWithOne(this string source, string[] values, string value)
17-
- string Take(this string source, int characters, Position from = Position.Start);
18-
- double ToKB(this int number, DigitalStorage from = DigitalStorage.KB);
19-
- double ToMB(this int number, DigitalStorage from = DigitalStorage.MB);
20-
- double ToGB(this int number, DigitalStorage from = DigitalStorage.GB);
21-
- double ToTB(this int number, DigitalStorage from = DigitalStorage.TB);
22-
</PackageReleaseNotes>
14+
- public static string DriveFreeSpace(this string driveLetter);
15+
- public static string DriveTotalSize(this string driveLetter);
16+
- public static string DriveFormat(this string driveLetter);
17+
- public static DriveType DriveType(this string driveLetter);
18+
- public static void DeleteFile(this string filePath);
19+
- public static void HideFile(this string filePath);
20+
- public static void ShowFile(this string filePath);
21+
- public static DateTime CreatedDate(this string filePath);
22+
- public static void CopyFile(this string filePath, string destination);
23+
- public static void MoveFile(this string filePath, string destination);
24+
- public static double FileSizeInKB(this string filePath);
25+
- public static double FileSizeInMB(this string filePath);
26+
27+
Fixes
28+
- Fix digital storage measurements.
29+
</PackageReleaseNotes>
2330
<PackageProjectUrl>https://github.com/D-Diyare/FluentExtensions</PackageProjectUrl>
24-
<Version>1.2</Version>
31+
<Version>1.3</Version>
2532
<Copyright>Copyright © Diyare Abdulla 2021</Copyright>
2633
<Title>FluentExtensions</Title>
2734
<PackageLicenseExpression>MIT</PackageLicenseExpression>

src/FluentExtensions/NumberEx.cs

Lines changed: 99 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,11 @@ public static double ToKB(this int number, DigitalStorage from = DigitalStorage.
273273
switch (from)
274274
{
275275
case DigitalStorage.MB:
276-
return number * 1000;
276+
return number * 1024;
277277
case DigitalStorage.GB:
278-
return number * 1000000;
278+
return number * 1048576;
279279
case DigitalStorage.TB:
280-
return number * 1000000000;
280+
return number.ToGB(DigitalStorage.TB) * 1048576;
281281
case DigitalStorage.KB:
282282
default:
283283
return number;
@@ -295,11 +295,11 @@ public static double ToMB(this int number, DigitalStorage from = DigitalStorage.
295295
switch (from)
296296
{
297297
case DigitalStorage.KB:
298-
return number * 0.001;
298+
return number / 1024;
299299
case DigitalStorage.GB:
300-
return number * 1000;
300+
return number * 1024;
301301
case DigitalStorage.TB:
302-
return number * 1000000;
302+
return number * 1048576;
303303
case DigitalStorage.MB:
304304
default:
305305
return number;
@@ -317,11 +317,11 @@ public static double ToGB(this int number, DigitalStorage from = DigitalStorage.
317317
switch (from)
318318
{
319319
case DigitalStorage.KB:
320-
return number.ToMB(DigitalStorage.KB) * 0.001;
320+
return number.ToMB(DigitalStorage.KB) / 1024;
321321
case DigitalStorage.MB:
322-
return number * 0.001;
322+
return number / 1024;
323323
case DigitalStorage.TB:
324-
return number * 1000;
324+
return number * 1024;
325325
case DigitalStorage.GB:
326326
default:
327327
return number;
@@ -339,11 +339,98 @@ public static double ToTB(this int number, DigitalStorage from = DigitalStorage.
339339
switch (from)
340340
{
341341
case DigitalStorage.KB:
342-
return number.ToGB(DigitalStorage.KB) * 0.001;
342+
return number.ToGB(DigitalStorage.KB) / 1024;
343343
case DigitalStorage.MB:
344-
return number.ToGB(DigitalStorage.MB) * 0.001;
344+
return number.ToGB(DigitalStorage.MB) / 1024;
345345
case DigitalStorage.GB:
346-
return number * 0.001;
346+
return number / 1024;
347+
case DigitalStorage.TB:
348+
default:
349+
return number;
350+
}
351+
}
352+
353+
/// <summary>
354+
/// Converts the given number to kilobytes.
355+
/// </summary>
356+
/// <param name="number">Number to convert.</param>
357+
/// <returns>Kilobytes based on given number.</returns>
358+
public static double ToKB(this long number, DigitalStorage from = DigitalStorage.KB)
359+
{
360+
switch (from)
361+
{
362+
case DigitalStorage.MB:
363+
return number * 1024;
364+
case DigitalStorage.GB:
365+
return number * 1048576;
366+
case DigitalStorage.TB:
367+
return number.ToGB(DigitalStorage.TB) * 1048576;
368+
case DigitalStorage.KB:
369+
default:
370+
return number;
371+
}
372+
}
373+
374+
/// <summary>
375+
/// Converts the given number to megabytes.
376+
/// </summary>
377+
/// <param name="number">Number to convert.</param>
378+
/// <param name="from">From type.</param>
379+
/// <returns>Megabytes based on given number and given type to convert from.</returns>
380+
public static double ToMB(this long number, DigitalStorage from = DigitalStorage.MB)
381+
{
382+
switch (from)
383+
{
384+
case DigitalStorage.KB:
385+
return number / 1024;
386+
case DigitalStorage.GB:
387+
return number * 1024;
388+
case DigitalStorage.TB:
389+
return number * 1048576;
390+
case DigitalStorage.MB:
391+
default:
392+
return number;
393+
}
394+
}
395+
396+
/// <summary>
397+
/// Converts the given number to gigabytes.
398+
/// </summary>
399+
/// <param name="number">Number to convert.</param>
400+
/// <param name="from">From type.</param>
401+
/// <returns>Gigabytes based on given number and given type to convert from.</returns>
402+
public static double ToGB(this long number, DigitalStorage from = DigitalStorage.GB)
403+
{
404+
switch (from)
405+
{
406+
case DigitalStorage.KB:
407+
return number.ToMB(DigitalStorage.KB) / 1024;
408+
case DigitalStorage.MB:
409+
return number / 1024;
410+
case DigitalStorage.TB:
411+
return number * 1024;
412+
case DigitalStorage.GB:
413+
default:
414+
return number;
415+
}
416+
}
417+
418+
/// <summary>
419+
/// Converts the given number to terabytes.
420+
/// </summary>
421+
/// <param name="number">Number to convert.</param>
422+
/// <param name="from">From type.</param>
423+
/// <returns>Gigabytes based on given number and given type to convert from.</returns>
424+
public static double ToTB(this long number, DigitalStorage from = DigitalStorage.TB)
425+
{
426+
switch (from)
427+
{
428+
case DigitalStorage.KB:
429+
return number.ToGB(DigitalStorage.KB) / 1024;
430+
case DigitalStorage.MB:
431+
return number.ToGB(DigitalStorage.MB) / 1024;
432+
case DigitalStorage.GB:
433+
return number / 1024;
347434
case DigitalStorage.TB:
348435
default:
349436
return number;

0 commit comments

Comments
 (0)