.Net Automapper an object to object mapper

Here’s a quick demo of Automapper a library to assist with mapping object items between objects.

using System;
using AutoMapper;

namespace CsharpAutoMapperDemo
{
    class CsharpAutoMapperExample
    {
        static void Main()
        {
            Mapper.CreateMap<User, Person>();

            var userWithAutoMap = new User()
                           {
                               FirstName = "FirstName",
                               LastName = "LastName",
                               UserId = "My user id",
                               Password = "My password",
                               EmailAddress = "My email",
                           };

            var personWithAutoMap = Mapper.Map<User, Person>(userWithAutoMap);

            Console.WriteLine(personWithAutoMap.FirstName);
            Console.WriteLine(personWithAutoMap.LastName);
            Console.WriteLine(personWithAutoMap.EmailAddress);
            Console.WriteLine();
            
            Mapper.Reset();

            Mapper.CreateMap<User, Person>()
                  .ForMember(x => x.EmailAddress,
                             y => y.MapFrom(src => src.FirstName + "" + src.LastName + "@email.com"));

            var userWithManualMap = new User()
            {
                FirstName = "FirstName",
                LastName = "LastName",
                UserId = "My user id",
                Password = "My password",
                EmailAddress = "My email",
            };

            var personWithManualMap = Mapper.Map<User, Person>(userWithManualMap);

            Console.WriteLine(personWithManualMap.FirstName);
            Console.WriteLine(personWithManualMap.LastName);
            Console.WriteLine(personWithManualMap.EmailAddress);

            Console.ReadKey();
        }
    }
}

The mapping classes:

namespace CsharpAutoMapperDemo
{
    class User
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string UserId { get; set; }
        public string Password { get; set; }
        public string EmailAddress { get; set; }
     
    }
}

namespace CsharpAutoMapperDemo
{
    class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmailAddress { get; set; }
        public string HomeAddress { get; set; }
        public string BuildingLocation { get; set; }
        
    }
}

The resultant output:


FirstName
LastName
My email

FirstName
LastName
[email protected]

Gator.js a micro event handling framework

I’ve had a look at gator.js, it’s useful because it’s very a lightweight way of handling events on page elements. Quick demo below:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Gator demo</title>
      <script type="text/javascript" src="gator.min.js"></script>
</head>
<body>
     <table id="mytable">
        <tr>
            <td>A</td>
            <td>1</td>
        </tr>
        <tr>
            <td>B</td>
            <td>2</td>
        </tr>
        <tr>
            <td>C</td>
            <td>3</td>
        </tr>
        <tr>
            <td>D</td>
            <td>4</td>
        </tr>
        <tr>
            <td>E</td>
            <td>5</td>
        </tr>
    </table>
    <script type="text/javascript">
        var table = document.getElementById("mytable");
     
        Gator(table).on('click', 'tr', function (e) {
            alert("clicked on table row");
        });
    </script>
</body>
</html>