I am developing a library that initializes old type objects from data obtained from SQL Server stored procedures. One of his methods is as follows:
public static T RetrieveCompound<T, U>(string cmdText, params Parameter[] parameters)
where T : Header<U>, new()
where U : class, new() {
Box<T> headerBox = new Box<T>();
List<U> details;
Execute(cmdText, parameters, new Action<Row>[] {
SetReferenceAction<T>(headerBox) +
delegate(Row row) { details = headerBox.Value.Details; },
delegate(Row row) { details.Add(row.ToObject<U>()); }
});
return headerBox.Value;
}
The third parameter Executeis an array of Action<Row>s. Although the static analyzer cannot programmatically prove this, since the method has Executebeen programmed, the delegate cannot be run before those that precede it in the array. This means that the delegate
delegate(Row row) { details.Add(row.ToObject<U>()); }
must be run after the delegate
delegate(Row row) { details = headerBox.Value.Details; }
And, thus, the variable detailswill be necessarily initialized before its use.
But C # still complains: "Using information about an unassigned variable."
# , ?
, # .