I have the following class that suppose to create iterate through a string array to check if a code exists. However the .value always returns null when using Lazy Initialization.
public class LazyInclusionList
{
private string docCopyCode;
private Lazy<LazyInclusionList> _docCopyCodeList = null;
public LazyInclusionList()
{ }
public bool GetDocCodes(string docCopyNumber)
{
docCopyCode = new string(docCopyNumber.Where(Char.IsLetter).ToArray());
_docCopyCodeList = new Lazy<LazyInclusionList>();
bool docCopyCheck = false;
int last = _docCopyCodeList.Value.GetDocCodesDB.Count();
int i = 0;
foreach (string code in _docCopyCodeList.Value.GetDocCodesDB)
{
if(docCopyCode == code)
{
docCopyCheck = true;
}
else if (docCopyCode != code && ++i == last)
{
docCopyCheck = false;
}
}
return docCopyCheck;
}
private string[] codes;
public string[] GetDocCodesDB
{
set
{
codes = value;
}
get { return codes; }
}
}
I have the following test method that I use to check this code.
[TestMethod]
public void CheckURLList()
{
var list = new LazyInclusionList();
string[] array = new string [3] { "CB", "DB", "T" };
list.GetDocCodesDB = array;
string myTest = "CB10/00/1";
Assert.IsTrue(list.GetDocCodes(myTest));
}
This is the first time I use this method and dont understand it fully.