ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/ObjectBinder.cs
Revision: 313
Committed: Tue Jun 5 15:03:03 2012 UTC (11 years, 6 months ago) by william
File size: 1256 byte(s)
Log Message:

File Contents

# User Rev Content
1 william 313 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5    
6     namespace RomCheater
7     {
8     /// <summary>
9     /// A class that allows the binding of an object to another type
10     /// </summary>
11     public class ObjectBinder
12     {
13     /// <summary>
14     /// Binds an object to a specific type
15     /// </summary>
16     /// <typeparam name="T">The destination object type</typeparam>
17     /// <param name="source">The source object type (object)</param>
18     /// <returns>A bound type</returns>
19     public static void Bind<T>(object source, out T destination) where T : class { Bind<object, T>(source, out destination); }
20     /// <summary>
21     /// Bind an object of a specific type to another specific type
22     /// </summary>
23     /// <typeparam name="S">The source object type</typeparam>
24     /// <typeparam name="T">The destination object type</typeparam>
25     /// <param name="source">An instance of the source type</param>
26     /// <returns>A bound typ</returns>
27     public static void Bind<S, T>(S source, out T destination) where T : class { destination= (source as T) == null ? (T)Convert.ChangeType(source, typeof(T)) : (source as T); }
28     }
29     }