public static Sample.Business.SalesPerson MapFromSalesPerson(this ReverseMapper mapper, SalesPerson source, Sample.Business.SalesPerson target) { // Null maps to null: if (source == null) { return(null); } // Check if object already mapped (as in circular reference scenarios): object mappedTarget = mapper.GetMappedTarget(source); if (Object.ReferenceEquals(mappedTarget, null) == false) { return((Sample.Business.SalesPerson)mappedTarget); } // Retrieve target object: if (target == null) { target = mapper.TryGetTarget <Sample.Business.SalesPerson>(source); } if (target == null) { throw new Max.Domain.Mapping.MappingException(String.Format("Cannot map {0} to an existing instance.", source.GetType().Name)); } // Register mapping: mapper.RegisterMapping(source, target); // Perform mapping: if (mapper.CanUpdate(target)) { mapper.UpdateSalesPerson(source, target); } // Return target: return(target); }
// Test Method public static void Test() { // Obtain type information using a SalesPerson instance. SalesPerson salesPerson = new SalesPerson("Moamen", "Soroor", 25); // Obtaining a Type Reference Using System.Object.GetType() - instance method Type type = salesPerson.GetType(); Console.WriteLine(type.Name); // Obtaining a Type Reference Using typeof() - operator takes Type type2 = typeof(SalesPerson); Console.WriteLine(type.Name); // Obtaining a Type Reference Using System.Type.GetType() - static method // ------------------------------------------------------------------------------------------ // The Type.GetType() method has been overloaded to allow you to specify two Boolean parameters, // one of which controls whether an exception should be thrown if the type cannot be found, and the other of // which establishes the case sensitivity of the string. // defaults are case sensitivity with no error thrown if // public static Type GetType(string typeName); // it Gets the System.Type with the specified name, performing a case-sensitive search, no error thrown. // if not a type, returns null Type type3 = Type.GetType("System.String"); Console.WriteLine(type3.Name); // public static Type GetType(string typeName, bool throwOnError); Type type5 = Type.GetType("System.String", false); Console.WriteLine(type5.Name); // public static Type GetType(string typeName, bool throwOnError, bool ignoreCase); Type type4 = Type.GetType("system.string", false, true); Console.WriteLine(type4.Name); // However, when you want to obtain metadata for a type within an external private // assembly, the string parameter is formatted using the type’s fully qualified name, followed by a comma, // followed by the friendly name(Assembly name without .dll or .exe) of the assembly containing the type. //"fullyQualifiedName, AssemblyFriendlyName" // Obtain type information for a type within an external assembly. Type type6 = Type.GetType("CarLibrary.Car, CarLibrary"); // "fullyQualifiedName, AssemblyFriendlyName" Console.WriteLine(type6.Name); // As well, do know that the string passed into Type.GetType() may specify a plus token(+) to denote a // nested type. // Obtain type information for a nested enumeration // within the current assembly. Type type7 = Type.GetType("CarLibrary.JamesBondCar+SpyOptions"); Console.WriteLine(type7.Name); }