using System.Collections.Generic;
public static void Main()
Console.WriteLine("Hello World");
FormModel myObj1 = new FormModel();
FormModel myObj2 = new FormModel();
myObj1.AccessToken = "TokigToken";
myObj1.FormModelBuyer.Name = "JD";
TypeMappingHelper.Map(myObj1,myObj2);
myObj1.AcroFieldNames.Add("X","Y");
var isEqual = TypeMappingHelper.Equals2(myObj1,myObj2);
Console.WriteLine("Lika som bär!");
Console.WriteLine("Diffar");
public string AccessToken { get; set; }
public string Template { get; set; }
public string SignDate { get; set; }
public FormModelBuyer FormModelBuyer { get; set; }
public Dictionary<string,string> AcroFieldNames { get; set; }
FormModelBuyer = new FormModelBuyer();
AcroFieldNames = new Dictionary<string, string>();
public class FormModelBuyer
public string Name { get; set; }
public string Adress { get; set; }
public string PostalAdress { get; set; }
public string Phone { get; set; }
public string SSN { get; set; }
public string Driver { get; set; }
public class TypeMappingHelper
public static bool Equals2(object source, object target, bool builtInTypesOnly = false, bool withOutGuid = false)
string targetPropertyName = "Unknown";
var sourceProperties = source.GetType().GetProperties();
var targetProperties = target.GetType().GetProperties();
Console.WriteLine("Antal properties: "+ sourceProperties.Count());
if (sourceProperties.Count() != targetProperties.Count())
Console.WriteLine("Olika antal properties!");
foreach (PropertyInfo targetProperty in targetProperties)
property = sourceProperties.FirstOrDefault(pi => pi.Name == targetProperty.Name);
Console.WriteLine("Olika Properties!");
if (targetProperty.GetSetMethod() != null)
Console.WriteLine("----"+targetProperty.Name+"-----");
Console.WriteLine("T prop: "+targetProperty.GetValue(source,null));
Console.WriteLine("S prop: "+property.GetValue(target,null));
if (targetProperty.GetValue(target,null) != property.GetValue(source,null))
Console.WriteLine("Olika Property value!");
Console.WriteLine("T prop: "+targetProperty.GetValue(source,null));
Console.WriteLine("S prop: "+property.GetValue(target,null));
string message = string.Format("Unexpected error in TypeMappingHelper.Map on targetProperty [{0}]", targetPropertyName);
throw new Exception(message, ex);
public static int Map(object source, object target, bool builtInTypesOnly = false, bool withOutGuid = false)
string targetPropertyName = "Unknown";
var sourceProperties = source.GetType().GetProperties();
var targetProperties = target.GetType().GetProperties();
foreach (PropertyInfo targetProperty in targetProperties)
targetPropertyName = targetProperty.Name;
property = sourceProperties.FirstOrDefault(pi => pi.Name == targetProperty.Name);
if (targetProperty.GetSetMethod() != null)
targetProperty.SetValue(target, property.GetValue(source, null), null);
Console.WriteLine("Hello World");
string message = string.Format("Unexpected error in TypeMappingHelper.Map on targetProperty [{0}]", targetPropertyName);
throw new Exception(message, ex);