0

In C# I am passing an object to a function. I need to add a property in object that contains dash "-" in it. How can I pass this dashed property in object?

SendPushNotificationByAPNS(
device.RegisterId,
new
{
    aps = new
    {
        badge = 0
        alert = new
        {
            title = notificationTitle,
            body = notificationBody,
            sound = "default"
        },
        mutable-content = 1 <-- I need to add this but C# doesn't allow
    },
    entityId = entityId,
    entityType = entityType
});
4
  • 2
    This feels like a XY Problem - meta.stackexchange.com/questions/66377/what-is-the-xy-problem Why do you need a - in a property name? Commented Jul 19, 2018 at 12:27
  • If you are using JSON.Net you can define a custom formatter. Commented Jul 19, 2018 at 12:29
  • A custom formatter is probably overkill. It's easy enough to just add an attribute. Commented Jul 19, 2018 at 12:30
  • @KevinAnderson That makes no sense for an identifier such as a variable's name. You don't pass the variable's name but its value. Commented Jul 19, 2018 at 12:30

1 Answer 1

2

You don't have to name properties in C# in the same way as in JSON format, you have to create a class with all properties that you need with regard to C# naming conventions.

Then you can add [JsonProperty("mutable-content")] attribute with name of the field that you expected to see in a JSON file.

After your applicaiton will make request to another source it will be automatically serialized.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.