comparison Tools/CodeGenerator/Convert.Declare.cs @ 0:f990fcb411a9

Копия текущей версии из github
author cin
date Thu, 27 Mar 2014 21:46:09 +0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f990fcb411a9
1 using System;
2
3 [assembly: CLSCompliant(true)]
4
5 namespace BLToolkit.Common
6 {
7 public class TypeHelper
8 {
9 public static bool IsSameOrParent(Type type,Type type1)
10 {
11 return true;
12 }
13 }
14
15 public interface IConvertible<T,P>
16 {
17 T From(P p);
18 }
19
20 public static partial class Convert<T,P>
21 {
22 public static IConvertible<T,P> Instance = GetConverter();
23
24 private static IConvertible<T,P> GetConverter()
25 {
26 if (TypeHelper.IsSameOrParent(typeof(T), typeof(P)))
27 {
28 return (IConvertible<T,P>)(object)(new ConvertAssignable<P,P>());
29 }
30
31 return new ConvertExplicit<T,P>();
32 }
33 }
34
35 internal class ConvertAssignable<T,P>: IConvertible<T,P> where P: T
36 {
37 T IConvertible<T,P>.From(P p) { return p; }
38 }
39
40 internal class ConvertDefault<T,P>: IConvertible<T,P>
41 {
42 T IConvertible<T,P>.From(P p) { return (T)System.Convert.ChangeType(p, typeof(T)); }
43 }
44
45 internal partial class ConvertPartial<T,P>: ConvertDefault<T,P>
46 {
47 }
48
49 internal partial class ConvertExplicit<T,P>: ConvertPartial<T,P>
50 {
51 }
52 }
53
54 namespace BLToolkit.Properties
55 {
56 public class Resources
57 {
58 public const string Convert_InvalidCast = "{0} {1}";
59 }
60 }