Updating Common Library

I have had a project I call "CommonLib" that I have been using with my .Net projects since before .Net 1.0 was released.  It started out as a collection of helper functions for algorithms and functions that were missing from the .Net system.

With new long term support version of .Net, I try to upgrade the library by removing any outdated functions and any functions now supported by the new .Net release.  I update any existing functions with new or improved methods from the .Net system, like pattern matching.  I will add any new features from the new .Net release that meet the requirements to be included in the common library.


Changes made for this Release

Changes made with this latest release

1. Upgrade to .Net 6
2. Switch to Global Using
3. Turned Nullable support on
4. Removed outdated and duplicate functions
5. Increment the version
6. Updated the assembly properties


Common Lib Requirements

The requirement to have a function placed in the common lib is:

    "The function must be generic to be able to be used across any application domain"

A good example would be a string method extension that checks to see if the string is null or empty.  An example of a function that would not be a good common lib function would be any dB related function.  Each application can use a different database and thus the function would not be generic.  

Additional Requirements

1. Must have standard comments for the end user to see what the function does
2. Must have unit test suites.  These are still in work for the latest changes
3. Must build with no errors or warnings

Since the common lib can be used in a wide range of solutions, the code must be clean and tested.

What's in the Common Lib

The common lib is broke out into 3 sections:
1. Helpers => contains simple helper functions
2. Method Extensions
3. Utility => Stand alone functions that provide a service

Helper

  • Emal
    • Send Email
    • Validate Emails
  • EnumParse
    • Get Description
    • Enum to int
    • Int to Enum
  • FileFolder
    • Read
    • Move
    • Copy
    • Folders
    • Encrypt / Decrypt
  • Json
    • Serialize
    • Deserialize
  • Password
    • Checks if password is complex
  • PhoneNumber
    • Cleans a phone number string
  • RecordSorter
    • Sorts a generic collection of objects
  • String
    • Zip / Unzip
    • Split
    • Get String Parts
  • TextFile
    • Load
    • Load to List

Method Extensions

There are 34 different method extensions.  Most of which are the variety of "To" or "Is".  For example:

        ToDate(), ToFloat(), IsEmpty(), IsNotEmpty()

Even though many of these could be reduced to a single line and placed in the actual class, having tehm as a method extension, I like using the extensions for readability.

        string.IsNullOrEmpty(myStr)  VS  myStr.IsEmpty()

There are a few formatting extensions as well, like SingleQuote and DoubleQuote that will add the specified number of quotes to a string.

Utility

The third group are utilities.  These are functions that are stand alone methods that provide a service.  These methods are:

  • AlphanumCompartorFast
    • Fast object comparer
  • DateUtility
    • OldEnough => Greater than some cut off date
    • IsValidDate
    • IsUSDate
  • RandomPassword
    • Generates a complex password
  • ReadWriteCsv
  • Stream
    • StreamToString
    • FileToByteArray
    • Stream Reader till end

Deployment

There are several ways to deploy the common lib into your projects for use.  Each method has its own pros and cons.  Here is a short list:

  1. Nuget Package
    1. Create a local Nuget package and include it with your solution
    2. In a production environment, I would recommend this, especially if you are already using a local Nuget Library
    3. Pros
      • Everyone is using the same package
      • You can version the packages
      • Easy to maintain the code
      • Provides a read only version
    4. Cons
      • Hard to debug with
  2. GitHub Subproject
    1. For this deployment you create a subproject in each of your GitHub repositories where you want to use the common lib.
    2. Pros
      • Can be debug
      • Can make code changes
    3. Cons
      • A lot more overhead maintaining the subprojects.
      • More work for the team checking out code
      • Code can be edited
  3. Local Project
    1. Include the common lib as another project in your solution and make a project reference to it.
    2. Pros
      • Allows user to view and debug with the code
      • Allows the entire solution to be delivered as a single entity
      • Good for blog and demo code
    3. Cons
      • Multiple copies can exist making it harder to maintain
      • Code can be changed
You can see there are several deployment options.  This allows you to choose the one that best fits the objective of the solution you are delivering.

Summary

This library is just a collection of functions I find useful when I am building applications.  I am planning on continuing to add and improve them over time and as I learn more solutions to common problems.






Comments

Popular posts from this blog

Yes, Blazor Server can scale!

Blazor - Cool Blur Loading Page

Blazor new and improved Search Box