Mono.CSharp.TypeContainer.CheckPairedOperators C# (CSharp) Method

CheckPairedOperators() public method

public CheckPairedOperators ( ) : void
return void
		void CheckPairedOperators ()
		{
			bool has_equality_or_inequality = false;
			var operators = this.operators.ToArray ();
			bool[] has_pair = new bool[operators.Length];

			for (int i = 0; i < operators.Length; ++i) {
				if (operators[i] == null)
					continue;

				Operator o_a = (Operator) operators[i];
				Operator.OpType o_type = o_a.OperatorType;
				if (o_type == Operator.OpType.Equality || o_type == Operator.OpType.Inequality)
					has_equality_or_inequality = true;

				Operator.OpType matching_type = o_a.GetMatchingOperator ();
				if (matching_type == Operator.OpType.TOP) {
					operators[i] = null;
					continue;
				}

				for (int ii = 0; ii < operators.Length; ++ii) {
					Operator o_b = (Operator) operators[ii];
					if (o_b == null || o_b.OperatorType != matching_type)
						continue;

					if (!TypeSpecComparer.IsEqual (o_a.ReturnType, o_b.ReturnType))
						continue;

					if (!TypeSpecComparer.Equals (o_a.ParameterTypes, o_b.ParameterTypes))
						continue;

					operators[i] = null;

					//
					// Used to ignore duplicate user conversions
					//
					has_pair[ii] = true;
				}
			}

			for (int i = 0; i < operators.Length; ++i) {
				if (operators[i] == null || has_pair[i])
					continue;

				Operator o = (Operator) operators [i];
				Report.Error (216, o.Location,
					"The operator `{0}' requires a matching operator `{1}' to also be defined",
					o.GetSignatureForError (), Operator.GetName (o.GetMatchingOperator ()));
			}

			if (has_equality_or_inequality) {
				if (Methods == null || !HasEquals)
					Report.Warning (660, 2, Location, "`{0}' defines operator == or operator != but does not override Object.Equals(object o)",
						GetSignatureForError ());

				if (Methods == null || !HasGetHashCode)
					Report.Warning (661, 2, Location, "`{0}' defines operator == or operator != but does not override Object.GetHashCode()",
						GetSignatureForError ());
			}
		}