Skip to content

Instantly share code, notes, and snippets.

@dbremner
Last active July 9, 2017 22:15
Show Gist options
  • Save dbremner/3d8c90375730888c53d5df3308937e74 to your computer and use it in GitHub Desktop.
Save dbremner/3d8c90375730888c53d5df3308937e74 to your computer and use it in GitHub Desktop.
using ReSharper annotations for a TryParse workalike
//taken from https://resharper-support.jetbrains.com/hc/en-us/community/posts/206650785-Can-I-handle-not-initialized-warnings-with-Jetbrains-Annotations-
[ContractAnnotation("=> false, target:null; => true, target:notnull")]
private bool TryFindWorkbook([NotNull] Excel.Workbooks workbooks, [CanBeNull] out Excel.Workbook target)
{
Requires.NotNull(workbooks, nameof(workbooks));
foreach (Excel.Workbook workbook in workbooks)
{
if (workbook.Name == cellLocation.WorkBookName)
{
target = workbook;
return true;
}
}
target = null;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment