Mono.CSharp.TypeInfo.IsFullyInitialized C# (CSharp) Method

IsFullyInitialized() public method

A struct's constructor must always assign all fields. This method checks whether it actually does so.
public IsFullyInitialized ( Mono.CSharp.FlowAnalysisContext fc, VariableInfo vi, Mono.CSharp.Location loc ) : bool
fc Mono.CSharp.FlowAnalysisContext
vi VariableInfo
loc Mono.CSharp.Location
return bool
		public bool IsFullyInitialized (FlowAnalysisContext fc, VariableInfo vi, Location loc)
		{
			if (struct_info == null)
				return true;

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

				if (!fc.IsStructFieldDefinitelyAssigned (vi, field.Name)) {
					var bf = field.MemberDefinition as Property.BackingFieldDeclaration;
					if (bf != null) {
						if (bf.Initializer != null)
							continue;

						fc.Report.Error (843, loc,
							"An automatically implemented property `{0}' must be fully assigned before control leaves the constructor. Consider calling the default struct contructor from a constructor initializer",
							field.GetSignatureForError ());

						ok = false;
						continue;
					}

					fc.Report.Error (171, loc,
						"Field `{0}' must be fully assigned before control leaves the constructor",
						field.GetSignatureForError ());
					ok = false;
				}
			}

			return ok;
		}

Usage Example

Example #1
0
 public bool IsFullyInitialized(FlowAnalysisContext fc, Location loc)
 {
     return(TypeInfo.IsFullyInitialized(fc, this, loc));
 }