Mono.CSharp.Struct.CheckStructCycles C# (CSharp) Method

CheckStructCycles() private method

private CheckStructCycles ( Struct s ) : bool
s Struct
return bool
		bool CheckStructCycles (Struct s)
		{
			if (s.Fields == null)
				return true;

			if (s.InTransit)
				return false;

			s.InTransit = true;
			foreach (FieldBase field in s.Fields) {
				TypeSpec ftype = field.Spec.MemberType;
				if (!ftype.IsStruct)
					continue;

				if (ftype is BuildinTypeSpec)
					continue;

				foreach (var targ in ftype.TypeArguments) {
					if (!CheckFieldTypeCycle (targ)) {
						Report.Error (523, field.Location,
							"Struct member `{0}' of type `{1}' causes a cycle in the struct layout",
							field.GetSignatureForError (), ftype.GetSignatureForError ());
						break;
					}
				}

				if ((field.IsStatic && (!ftype.IsGeneric || ftype == CurrentType)))
					continue;

				if (!CheckFieldTypeCycle (ftype)) {
					Report.Error (523, field.Location,
						"Struct member `{0}' of type `{1}' causes a cycle in the struct layout",
						field.GetSignatureForError (), ftype.GetSignatureForError ());
					break;
				}
			}

			s.InTransit = false;
			return true;
		}