public static Compare ( |
||
x | ||
y | ||
Результат | int |
void CompareMemberLists(ComparisonNode parent, List <CompNamed> reference_list, List <CompNamed> target_list, bool isSealed) { int m = 0, a = 0; reference_list.Sort(CompNamed.Compare); target_list.Sort(CompNamed.Compare); while (m < reference_list.Count || a < target_list.Count) { if (m == reference_list.Count) { AddExtra(parent, target_list[a]); a++; continue; } else if (a == target_list.Count) { AddMissing(parent, reference_list[m]); m++; continue; } int c = CompNamed.Compare(reference_list[m], target_list[a]); comparisons_performed++; if (c == 0) { /* the names match, further investigation is required */ // Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name); ComparisonNode comparison = target_list[a].GetComparisonNode(); parent.AddChild(comparison); if (reference_list[m] is CompMember && target_list[a] is CompMember) { string reference_type = ((CompMember)reference_list[m]).GetMemberType(); string target_type = ((CompMember)target_list[a]).GetMemberType(); if (reference_type != target_type) { comparison.AddError(String.Format("reference type is <i>{0}</i>, target type is <i>{1}</i>", reference_type, target_type)); } string reference_access = ((CompMember)reference_list[m]).GetMemberAccess(); string target_access = ((CompMember)target_list[a]).GetMemberAccess(); if (reference_access != target_access) { // Try to give some hints to the developer, best we can do with // strings. string extra_msg = ""; if (reference_access.IndexOf("Private, Final, Virtual, HideBySig") != -1 && target_access.IndexOf("Public, HideBySig") != -1) { extra_msg = "\n\t\t<b>Hint:</b> reference uses an explicit interface implementation, target doesn't"; } comparison.AddError(String.Format("reference access is '<i>{0}</i>', target access is '<i>{1}</i>'{2}", reference_access, target_access, extra_msg)); comparison.Status = ComparisonStatus.Error; } } var r_method = reference_list[m] as CompMethod; if (r_method != null) { var t_method = (CompMethod)target_list[a]; if (t_method.ThrowsNotImplementedException() && !r_method.ThrowsNotImplementedException()) { comparison.ThrowsNIE = true; } CompareTypeParameters(comparison, r_method, t_method); CompareParameters(comparison, r_method, t_method); } else if (reference_list[m] is CompProperty) { var m1 = ((CompProperty)reference_list[m]).GetMethods(); var m2 = ((CompProperty)target_list[a]).GetMethods(); if (m1.Count != m2.Count) { comparison.AddError(String.Format("Expected {0} accessors but found {1}", m1.Count, m2.Count)); comparison.Status = ComparisonStatus.Error; } else { for (int i = 0; i < m1.Count; ++i) { string reference_access = ((CompMember)m1[i]).GetMemberAccess(); string target_access = ((CompMember)m2[i]).GetMemberAccess(); if (reference_access != target_access) { // Try to give some hints to the developer, best we can do with // strings. string extra_msg = ""; if (reference_access.IndexOf("Private, Final, Virtual, HideBySig") != -1 && target_access.IndexOf("Public, HideBySig") != -1) { extra_msg = "\n\t\t<b>Hint:</b> reference uses an explicit interface implementation, target doesn't"; } comparison.AddError(String.Format("reference access is '<i>{0}</i>', target access is '<i>{1}</i>'{2}", reference_access, target_access, extra_msg)); comparison.Status = ComparisonStatus.Error; break; } } if (m1[0].Name[0] == m2[0].Name[0]) { CompareAttributes(comparison, (ICompAttributeContainer)m1[0], (ICompAttributeContainer)m2[0]); if (m1.Count > 1) { CompareAttributes(comparison, (ICompAttributeContainer)m1[1], (ICompAttributeContainer)m2[1]); } } else { CompareAttributes(comparison, (ICompAttributeContainer)m1[0], (ICompAttributeContainer)m2[1]); if (m1.Count > 1) { CompareAttributes(comparison, (ICompAttributeContainer)m1[1], (ICompAttributeContainer)m2[0]); } } } // Compare indexer parameters if (m1.Count == m2.Count) { CompareParameters(comparison, (ICompParameters)m1[0], (ICompParameters)m2[0]); } } if (reference_list[m] is CompField) { var v_ref = ((CompField)reference_list[m]).GetLiteralValue(); var v_tar = ((CompField)target_list[a]).GetLiteralValue(); if (v_ref != v_tar) { comparison.AddError(String.Format("Expected field value {0} but found value {1}", v_ref, v_tar)); comparison.Status = ComparisonStatus.Error; } } if (reference_list[m] is ICompAttributeContainer) { //Console.WriteLine ("Comparing attributes for {0}", reference_list[m].Name); CompareAttributes(comparison, (ICompAttributeContainer)reference_list[m], (ICompAttributeContainer)target_list[a]); } if (reference_list[m] is ICompMemberContainer) { CompareMembers(comparison, (ICompMemberContainer)reference_list[m], (ICompMemberContainer)target_list[a]); } //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]); m++; a++; } else if (c < 0) { if (isSealed && reference_list[m].Name.Contains("~")) { // Ignore finalizer differences in sealed classes } else { /* reference name is before target name, reference name is missing from target */ AddMissing(parent, reference_list[m]); } m++; } else { if (isSealed && target_list[a].Name.Contains("~")) { // Ignore finalizer differences in sealed classes } else { /* reference name is after target name, target name is extra */ AddExtra(parent, target_list[a]); } a++; } } }
void CompareAttributes(ComparisonNode parent, ICompAttributeContainer reference_container, ICompAttributeContainer target_container) { int m = 0, a = 0; List <CompNamed> reference_attrs = reference_container.GetAttributes(); List <CompNamed> target_attrs = target_container.GetAttributes(); Comparison <CompNamed> comp = (x, y) => { var r = CompNamed.Compare(x, y); if (r != 0) { return(r); } var xa = ((CompAttribute)x).Properties.Values.ToList(); var ya = ((CompAttribute)y).Properties.Values.ToList(); for (int i = 0; i < Math.Min(xa.Count, ya.Count); ++i) { r = xa[i].CompareTo(ya[i]); if (r != 0) { return(r); } } return(0); }; reference_attrs.Sort(comp); target_attrs.Sort(comp); while (m < reference_attrs.Count || a < target_attrs.Count) { if (m == reference_attrs.Count) { switch (target_attrs[a].Name) { case "System.Diagnostics.DebuggerDisplayAttribute": case "System.Runtime.CompilerServices.AsyncStateMachineAttribute": case "System.Runtime.CompilerServices.IteratorStateMachineAttribute": case "System.Diagnostics.DebuggerBrowsableAttribute": // Ignore extra attributes in Mono source code break; default: AddExtra(parent, target_attrs[a]); break; } a++; continue; } else if (a == target_attrs.Count) { AddMissing(parent, reference_attrs[m]); m++; continue; } int c = String.Compare(reference_attrs[m].Name, target_attrs[a].Name); comparisons_performed++; if (c == 0) { /* the names match, further investigation is required */ ComparisonNode comparison = target_attrs[a].GetComparisonNode(); parent.AddChild(comparison); CompareAttributeArguments(comparison, (CompAttribute)reference_attrs[m], (CompAttribute)target_attrs[a]); m++; a++; } else if (c < 0) { /* reference name is before target name, reference name is missing from target */ AddMissing(parent, reference_attrs[m]); m++; } else { /* reference name is after target name, target name is extra */ AddExtra(parent, target_attrs[a]); a++; } } }