/// <summary> /// Verifies that two constructors are equivalent. /// </summary> /// <param name="actual">The actual constructor information.</param> /// <param name="expected">The expected constructor information.</param> public static void AreEquivalent(ConstructorInfo actual, ConstructorInfo expected) { // Check member properties. AreMembersEquivalent(actual, expected); // Check method attributes. Assert.That(actual.Attributes & MethodAttributes.ReservedMask, Is.EqualTo(expected.Attributes & MethodAttributes.ReservedMask)); Assert.That(actual.Attributes & MethodAttributes.SpecialName, Is.EqualTo(expected.Attributes & MethodAttributes.SpecialName)); Assert.That(actual.Attributes & MethodAttributes.VtableLayoutMask, Is.EqualTo(expected.Attributes & MethodAttributes.VtableLayoutMask)); // Check calling convention. Assert.That(actual.CallingConvention, Is.EqualTo(expected.CallingConvention)); // Check generic parameters. Assert.That(actual.ContainsGenericParameters, Is.EqualTo(expected.ContainsGenericParameters)); if (actual.ContainsGenericParameters) AreTypesEquivalent(actual.GetGenericArguments(), expected.GetGenericArguments()); }
static private void AppendConstructorInfo(ConstructorInfo constructor, StringBuilder sb) { sb.Append(".method"); foreach (var attribute in constructor.GetCustomAttributesData()) { sb.Append(" "); AppendCustomAttributeData(attribute, sb); } sb.Append(" "); AppendMethodAttributes(sb, constructor.Attributes); sb.Append(" "); sb.Append("void "); sb.Append(constructor.Name); if (constructor.IsGenericMethod) { sb.Append("<"); foreach (var typeParameter in constructor.GetGenericArguments()) { AppendType(typeParameter, sb, true); AppendComma(sb); } RemoveTrailingComma(sb); sb.Append(">"); } sb.Append("("); foreach (var parameter in constructor.GetParameters()) { AppendParameterInfo(parameter, sb); AppendComma(sb); } RemoveTrailingComma(sb); sb.Append(")"); var implFlags = constructor.GetMethodImplementationFlags(); if (implFlags.HasFlag(MethodImplAttributes.IL)) sb.Append(" cil"); if (implFlags.HasFlag(MethodImplAttributes.ForwardRef)) sb.Append(" forwardref"); if (implFlags.HasFlag(MethodImplAttributes.InternalCall)) sb.Append(" internalcall"); if (implFlags.HasFlag(MethodImplAttributes.Managed)) sb.Append(" managed"); if (implFlags.HasFlag(MethodImplAttributes.Native)) sb.Append(" native"); if (implFlags.HasFlag(MethodImplAttributes.NoInlining)) sb.Append(" noinlining"); if (implFlags.HasFlag(MethodImplAttributes.NoOptimization)) sb.Append(" nooptimization"); if (implFlags.HasFlag(MethodImplAttributes.OPTIL)) sb.Append(" optil"); if (implFlags.HasFlag(MethodImplAttributes.PreserveSig)) sb.Append(" preservesig"); if (implFlags.HasFlag(MethodImplAttributes.Runtime)) sb.Append(" runtime"); if (implFlags.HasFlag(MethodImplAttributes.Synchronized)) sb.Append(" synchronized"); if (implFlags.HasFlag(MethodImplAttributes.Unmanaged)) sb.Append(" unmanaged"); }