Beispiel #1
0
		// <summary>
		//   A struct's constructor must always assign all fields.
		//   This method checks whether it actually does so.
		// </summary>
		public bool IsFullyInitialized (FlowBranching branching, VariableInfo vi, Location loc)
		{
			if (struct_info == null)
				return true;

			bool ok = true;
			for (int i = 0; i < struct_info.Count; i++) {
				FieldInfo field = struct_info.Fields [i];

				if (!branching.IsFieldAssigned (vi, field.Name)) {
					FieldBase fb = TypeManager.GetField (field);
					if (fb != null && (fb.ModFlags & Modifiers.BACKING_FIELD) != 0) {
						Report.Error (843, loc,
							"An automatically implemented property `{0}' must be fully assigned before control leaves the constructor. Consider calling default contructor",
							fb.GetSignatureForError ());
					} else {
						Report.Error (171, loc,
							"Field `{0}' must be fully assigned before control leaves the constructor",
							TypeManager.GetFullNameSignature (field));
					}
					ok = false;
				}
			}

			return ok;
		}