This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / tools / corcompare / MissingField.cs
1 // Mono.Util.CorCompare.MissingField
2 //
3 // Author(s):
4 //   Nick Drochak (ndrochak@gol.com)
5 //
6 // (C) 2001-2002 Nick Drochak
7
8 using System;
9 using System.Reflection;
10
11 namespace Mono.Util.CorCompare {
12
13         /// <summary>
14         ///     Represents a class event that is completely missing
15         /// </summary>
16         /// <remarks>
17         ///     created by - Nick
18         ///     created on - 2/24/2002 10:43:57 PM
19         /// </remarks>
20         class MissingField : MissingMember {
21                 // e.g. <method name="Equals" status="missing"/>
22                 public MissingField (MemberInfo infoMono, MemberInfo infoMS) : base (infoMono, infoMS) {}
23
24                 public override string Type {
25                         get {
26                                 return "field";
27                         }
28                 }
29
30                 public override NodeStatus Analyze ()
31                 {
32                         base.Analyze ();
33
34                         if (mInfoMono != null && mInfoMS != null)
35                         {
36                                 FieldInfo fiMono = (FieldInfo) mInfoMono;
37                                 FieldInfo fiMS   = (FieldInfo) mInfoMS;
38
39                                 AddFakeAttribute (fiMono.IsNotSerialized, fiMS.IsNotSerialized, "System.NonSerializedAttribute");
40                                 AddFakeAttribute (fiMono.IsPinvokeImpl, fiMS.IsPinvokeImpl, "System.PInvokeImplAttribute");
41
42                                 AddFlagWarning (fiMono.IsStatic, fiMS.IsStatic, "static");
43                                 AddFlagWarning (fiMono.IsLiteral, fiMS.IsLiteral, "const");
44                                 AddFlagWarning (fiMono.IsInitOnly, fiMS.IsInitOnly, "readonly");
45
46                                 string strTypeMono = fiMono.FieldType.FullName;
47                                 string strTypeMS   =   fiMS.FieldType.FullName;
48                                 if (strTypeMono != strTypeMS)
49                                 {
50                                         Status.AddWarning ("Invalid type: is '"+strTypeMono+"', should be '"+strTypeMS+"'");
51                                 }
52
53                                 try
54                                 {
55                                         if (fiMono.IsStatic && fiMS.IsStatic &&
56                                                 fiMono.IsLiteral && fiMS.IsLiteral)
57                                         {
58                                                 object objMono = fiMono.GetValue (null);
59                                                 object objMS = fiMS.GetValue (null);
60                                                 long lMono = Convert.ToInt64 (objMono);
61                                                 long lMS = Convert.ToInt64 (objMS);
62
63                                                 if (lMono != lMS)
64                                                 {
65                                                         string strValMono = ((lMono < 0) ? "-0x" : "0x") + lMono.ToString ("x");
66                                                         string strValMS   = ((lMS   < 0) ? "-0x" : "0x") +   lMS.ToString ("x");
67                                                         Status.AddWarning ("Invalid value: is '"+strValMono+"', should be '"+strValMS+"'");
68                                                 }
69                                         }
70                                 }
71                                 catch (Exception) {}
72                         }
73                         return m_nodeStatus;
74                 }
75         }
76 }