ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/TypeBinder.cs
Revision: 315
Committed: Tue Jun 5 15:24:43 2012 UTC (11 years, 3 months ago) by william
File size: 1268 byte(s)
Log Message:

File Contents

# Content
1 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 TypeBinder
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 }