/[RomCheater]/trunk/RomCheater.Core/ProcessorAssemblyArchitecture.cs
ViewVC logotype

Annotation of /trunk/RomCheater.Core/ProcessorAssemblyArchitecture.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 124 - (hide annotations) (download)
Fri May 11 10:58:42 2012 UTC (8 years, 5 months ago) by william
File size: 3352 byte(s)

1 william 117 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5    
6     namespace System.Reflection
7     {
8    
9    
10     [AttributeUsage(AttributeTargets.Assembly)]
11     public class ProcessorAssemblyArchitecture : Attribute
12     {
13 william 118 public ProcessorAssemblyArchitecture() { Architecture = Undefined; }
14 william 117 public ProcessorAssemblyArchitecture(string arch)
15     {
16     Type t = typeof(ProcessorAssemblyArchitecture);
17     FieldInfo[] fields = t.GetFields(BindingFlags.Public | BindingFlags.Static);
18    
19     bool found = false;
20     foreach (FieldInfo field in fields)
21     {
22     string o = field.GetValue(null).ToString();
23     if (arch == o)
24     {
25     found = true;
26     break;
27     }
28     }
29 william 118 if (!found) { Architecture = Undefined; }
30     else { Architecture = arch; }
31     }
32     string _Architecture;
33     public string Architecture { get { return _Architecture; } private set { _Architecture = value; } }
34 william 117 #region processor architecture
35 william 124 /// <summary>
36     /// Represents an undefined processor arcitecture
37     /// </summary>
38 william 117 public const string Undefined = "Undefined";
39 william 124 /// <summary>
40     /// Represents a 32-bit processor arcitecture
41     /// </summary>
42 william 117 public const string x86 = "x86";
43 william 124 /// <summary>
44     /// Represents a 64-bit processor arcitecture
45     /// </summary>
46 william 117 public const string x64 = "x64";
47 william 124 /// <summary>
48     /// Represents a 64-bit processor arcitecture (this is equivalent to x64, this is just Amd's nameing convention)
49     /// </summary>
50     public const string Amd64 = x64;
51     /// <summary>
52     /// Represents am Itanium 64-bit processor arcitecture
53     /// </summary>
54 william 117 public const string Ia64 = "Ia64";
55 william 124 /// <summary>
56     /// Represents a 32-bit and 64-bit processor arcitecture (it will run in 32-bit mode for 32-bit systems and 64-bit for non-32bit systems)
57     /// </summary>
58 william 117 public const string AnyCpu = "AnyCpu";
59 william 124 /// <summary>
60     /// Represents a 32-bit and 64-bit processor arcitecture (refered to as AnyCpu)
61     /// </summary>
62 william 119 public const string Msil = AnyCpu;
63 william 117 #endregion
64 william 118
65     public static string GetProcessorArchitecture(Assembly t)
66     {
67     string assembly_arch = Undefined;
68    
69     // get architecture
70     ProcessorArchitecture o = t.GetName().ProcessorArchitecture;
71     if (o == ProcessorArchitecture.None)
72     assembly_arch = Undefined;
73    
74     switch (o)
75     {
76     case ProcessorArchitecture.Amd64: assembly_arch = Amd64; break;
77     case ProcessorArchitecture.IA64: assembly_arch = Ia64; break;
78     case ProcessorArchitecture.MSIL: assembly_arch = AnyCpu; break;
79     case ProcessorArchitecture.X86: assembly_arch = x86; break;
80     case ProcessorArchitecture.None: break;
81     default: assembly_arch = Undefined; break;
82     }
83    
84     return assembly_arch;
85     }
86    
87 william 117 }
88     }
89    

  ViewVC Help
Powered by ViewVC 1.1.22