Skip to content

Nullables treated as non-nullable at runtime #33

Closed
@farlee2121

Description

@farlee2121

My model includes a DateTime? property

public class CampaignDesignerRequest
{
     //...
     public DateTime? CampaignStartDate { get; set; }
     //...
}

My view inherits the model

@inherits RazorEngineCore.RazorEngineTemplateBase<Fourstarzz.Accessors.ReportTemplates.Models.DesignedCampaign_RenderModel>

At write time, the intellisense recognizes CampaignStartDate as a nullable and shows an error hint if I try to run date string formatting without specifying .Value

Model.CampaignStartDate.Value.ToShortDateString()

However when I run the code, it gives me the error

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : 'System.DateTime' does not contain a definition for 'Value'

I've tested the same on other value types, like int and double, and get the same kind of error.

Versions

  • RazoreEngineCore 2020.9.1
  • .NET framework 4.8.

Any thoughts on potential causes?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions