0

I want Name of Datamember to be displayed dynamically

public class SampleDTO
{

      [DataMember]
      public int Time1 { get; set; }
    
      [DataMember]
      public int Time2 { get; set; }
}

For example,

Time1 value entered by user = 20, Name of Time1 property should be displayed like “Case > 20 (mins)”

If Time1 value entered by user = 15, Name of Time1 property should be displayed like “Case > 15 (mins)”

How can I do this? Can anyone help me on this.

  • 9
    Displayed *where*? Frankly, this seems like a UI problem, which should be as simple as updating the displayed text on some UI element, but which has *nothing whatsoever* to do with the DTO – Marc Gravell Oct 14 '20 at 09:42
  • `DataMember` says that the property is used for data binding. It says *nothing* about how it should be displayed. That's the job of the `Display` attribute. Attributes are *static8 though. If you want value comparisons and dynamic labels, you'll have to modify the UI. Even the `Display` attribute doesn't work by itself. The UI controls inspect this and use its (static) value as a label – Panagiotis Kanavos Oct 14 '20 at 09:44
  • 3
    @PanagiotisKanavos I'd argue that `DataMember` says that it is used for *serialization*, i.e. storage/persistence - not data binding in the UI sense (it is, after all, `System.Runtime.Serialization.DataMemberAttribute`) – Marc Gravell Oct 14 '20 at 09:44

0 Answers0