The code-line looks like this:
ActiveEndDate = item[BuiltInFieldId.ActiveEndDate] != null ?
DateTime.Parse(item[BuiltInFieldId.ActiveEndDate].ToString()) : (DateTime?)null
How can I make sure that if item[BuiltInFieldId.ActiveEndDate]
is not null
declare it else dont declare anything to the ActiveEndDate
variable, not even null
.
It has to be during a object initialization
This is the surrounding code that was requested:
var result = new Xannounce
{
MyX = (
from item in items.Cast<SPListItem>()
from ta in (item[FieldId.x] as string ?? "").Replace(";", string.Empty).Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
where audienceIds.Select(x => x.xID).Contains(ta)
select new Xannounce
{
Xid = item.ID,
Xpub = item[BuiltInFieldId.ResponsiblePublisher] as string ?? string.Empty,
XformUrl = item.ParentList.DefaultEditFormUrl,
ActiveEndDate = item[BuiltInFieldId.ActiveEndDate] != null ? DateTime.Parse(item[BuiltInFieldId.ActiveEndDate].ToString()) : (DateTime?)null,
ActiveStartDate = item[BuiltInFieldId.ActiveStartDate] != null ? DateTime.Parse(item[BuiltInFieldId.ActiveStartDate].ToString()) : (DateTime?)null,
XEndDate = item[BuiltInFieldId.EndDate] != null ? DateTime.Parse(item[BuiltInFieldId.EndDate].ToString()) : (DateTime?)null,
XStartDate = item[BuiltInFieldId.StartDate] != null ? DateTime.Parse(item[BuiltInFieldId.StartDate].ToString()) : (DateTime?)null,
XTitle = item[SPBuiltInFieldId.Title].ToString(),
XMessage = item[SPBuiltInFieldId.Body] != null ? item[SPBuiltInFieldId.Body].ToString() : string.Empty,
Xtype = new SPFieldLookupValue(item[BuiltInFieldId.AnnouncementType].ToString()).LookupId,
XAuthor = item[SPBuiltInFieldId.Author].ToString(),
XAudienceNames = AudienceUtility.FindAudiences(item[FieldId.AudienceTargeting].ToString(), SPServiceContext.Current).Select(y => ' ' + y.AudienceName).ToArray()
}),
// Code continues...
Any kind of help or tips is appreciated alot