Click or drag to resize

CollectionHelperConvertItemTSource, TDestination Method

Converts the item from one type to another.

Note: Any properties that do not exist in the source but not the destination will be ignored.

Namespace:  Xcalibur.Helpers
Assembly:  Xcalibur.Helpers (in Xcalibur.Helpers.dll) Version: 1.0.1.0 (1.0.1.0)
Syntax
public static TDestination ConvertItem<TSource, TDestination>(
	this TSource item
)
where TDestination : new()

Parameters

item
Type: TSource
The source item.

Type Parameters

TSource
The type of the source.
TDestination
The type of the destination.

Return Value

Type: TDestination

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Examples
C#
 1// A person model
 2public class Person
 3{
 4    public string Name { get; set; }
 5    public string Address { get; set; }
 6    public string City { get; set; }
 7    public string State { get; set; }
 8    public int ZipCode { get; set; }
 9}
10
11// A shorter person model
12public class PersonShort
13{
14    public string Name { get; set; }
15    public string Address { get; set; }
16    public int ZipCode { get; set; }
17}
18
19// Main
20static void Main(string[] args)
21{
22    // Create a new 
23    var person = new Person
24    {
25        Name = "Steve The Machine",
26        Address = "123 Some Street",
27        City = "Someplace",
28        State = "AL",
29        ZipCode = 11111
30    };
31
32    // Get a new PersonShort from Person
33    var personShort = person.ConvertItem<Person, PersonShort>();
34    Console.WriteLine(personShort.Name);
35    Console.WriteLine(personShort.Address);
36    Console.WriteLine(personShort.ZipCode);
37
38    // Hold
39    Console.Read();
40}
41
42/* Result:
43 *
44 * Steve The Machine
45 * 123 Some Street
46 * 11111
47 */
See Also