Nov 20, 2017

JSON support to ignore property at run time of null value

Nowadays, NuGet packages make developer life easy. Today going to talk more about Newtonsoft.Json NuGet package one of the feature.

Many times developer, don't want all fields to be serialize and part of that string which fields value as Null.

Because of nowadays developer playing JSON string to object and object to JSON string and its common.

Some time such requirement like only those fields need to save in JSON string which have values.

JSON property support to ignore the fields run time. which value has Null.
 
class Client
{
    public int Id { get; set; }
    public string Name { get; set; }
    [JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
    public string NickName { get; set; }    
}

How to use JsonProperty(NullValueHandling = NullValueHanding.Ignore)
 
Client client = new Client
{
    Id = 1,
    Name = "Kalpesh",
    NickName = null,   
};

string json = JsonConvert.SerializeObject(client );
JSON output string look like
 
{Id:1,Name:"Kalpesh"}
Check the output JSON string and get better idea about the NickName field.

Json string only produced the Id and Name fields as output JSON string and ignore NickName field.

Nov 18, 2017

SSRS display date format with st nd rd th

How to do we achieve date format in SSRS.
- Using inbuilt format method to achieve date format in SSRS.
 
=format(cdate(Parameter!ReportingDate.Value),"dd.MM.yyyy")

Using above format method to achieving 21.10.2016 date.
If you want to date format like 21st October 2016 then there is no inbuilt method support to SSRS.
So for the need to write a custom code on the report (.rdl file).

Right click and goto report property and select code section and write to following code.
 
Public Function ConvertDate(ByVal mydate As DateTime) as string
  Dim myday as integer
  Dim strsuff As String
  Dim mynewdate As String
  'Default to th
  strsuff = "th" 
  myday = DatePart("d", mydate)
  If myday = 1 Or myday = 21 Or myday = 31 Then strsuff = "st"
  If myday = 2 Or myday = 22 Then strsuff = "nd"
  If myday = 3 Or myday = 23 Then strsuff = "rd"
  mynewdate = CStr(DatePart("d", mydate)) + strsuff + " " +      CStr(MonthName(DatePart("m", mydate))) + " " + CStr(DatePart("yyyy", mydate))
 return mynewdate
End function

Call above function =Code.ConvertDate(Parameter!ReportingDate.Value), will get the output result as a date format 21st October 2016.

Reference link - https://stackoverflow.com/questions/32712572/format-datetime-day-with-st-nd-rd-th