Skip to content
yanggujun edited this page Dec 30, 2019 · 4 revisions

Commons.Utils

Basic common utility for .NET development.

Installation

Commons.Utils is delivered as a part of nuget package "Commons". You can dowlord the package from nuget.org

Or you can directly install from nuget console by typing following commands:

PM>Install-Package Commons

Commons.Reflect

A utility for creating objects and accessing object properties by reflection

  • Create a new object with default constructor
            var simpleType = typeof(Simple);
            var invoker = Reflector.GetInvoker(simpleType);
            var simple = (Simple)invoker.NewInstance();
  • Accessing object properties
            var simple = new Simple
            {
                FieldA = "ValueA",
                FieldB = 1912,
                FieldC = 1412.2,
                FieldD = true
            };

            var invoker = Reflector.GetInvoker(typeof(Simple));
            var fa = (string)invoker.GetProperty(simple, "FieldA");

            var fb = (int)invoker.GetProperty(simple, "FieldB");

            var fc = (double)invoker.GetProperty(simple, "FieldC");

            var fd = (bool)invoker.GetProperty(simple, "FieldD");

Supported utilities

  • Atomic Primitives

    The class libary provides the following atomic primitives for concurrent computing. Those .NET structures enable the compare and swap (CAS) or compare exchange capability.

    • AtomicBool

    • AtomicDouble

    • AtomicFloat

    • AtomicInt32

    • AtomicInt64

    • AtomicReference

    • AtomicMarkableReference, a reference type with a flag incidating the state of the reference. A C# counterpart of java.util.concurrent.atomic.AtomicMarkableReference

  • Supported hash functions

    Murmur hash 32bit

    Fnv hash

  • Functors

    • Equator

    • Closure

    • Transformer

    • Factory

  • Guarder, A common utility to check parameters

Clone this wiki locally