I am using some code from the PayPal Net SDK (available on nuget). I lifted it from the samples, which are written in C#. Then I used an automatic translator (from Telerik) to convert it to VB.net. The translator is not perfect, and here is some code it cannot handle:
items = new List<PayoutItem>
{
new PayoutItem
{
recipient_type = PayoutRecipientType.EMAIL,
Amount = New Currency
{
value = "0.99",
Currency = "USD"
},
receiver = "[email protected]",
note = "Thank you.",
sender_item_id = "item_1"
},
}
};
On looking at this code fragment, I thought it was an object initializer for a named class, but when I do a search for the class named 'payoutitem', I don't find it, and when I right click and go to the definition, It tells me it is reconstructing it out of "metadata" and gives me code that starts with:
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
namespace PayPal.Api
{
public class PayoutItem : PayPalSerializableObject
{
public PayoutItem();
So I go ahead and use the translator to VB, and there too, I am told that the 'payoutItem' only exists as metadata. In addition, it gives me an error when I try to compile the result, which is:
Dim payout = New Payout() With { _
key .sender_batch_header = New PayoutSenderBatchHeader() With { _
Key .sender_batch_id = "batch_" + System.Guid.NewGuid().ToString().Substring(0, 8), _
Key .email_subject = "You have a payment" _
}, _
Key .items = New List(Of PayoutItem)() From { _
New PayoutItem() With { _
Key .recipient_type = PayoutRecipientType.EMAIL, _
Key .amount = New Currency() With { _
Key .value = "0.99", _
Key .currency = "USD" _
}, _
Key .receiver = "[email protected]", _
Key .note = "Thank you.", _
Key .sender_item_id = "item_1" _
}, _
New PayoutItem() With { _
Key .recipient_type = PayoutRecipientType.EMAIL, _
Key .amount = New Currency() With { _
Key .value = "0.90", _
Key .currency = "USD" _
}, _
Key .receiver = "[email protected]", _
Key .note = "Thank you.", _
Key .sender_item_id = "item_2" _
}, _
New PayoutItem() With { _
Key .recipient_type = PayoutRecipientType.EMAIL, _
Key .amount = New Currency() With { _
Key .value = "2.00", _
Key .currency = "USD" _
}, _
Key .receiver = "[email protected]", _
Key .note = "Thank you.", _
Key .sender_item_id = "item_3" _
} _
} _
}
Apparently having the first 'Key' here causes problems, and when I remove it, I get other compile problems.
Can anyone explain to me why a class exists only as MetaData, even though it has a name (PayoutItem), and secondly, why the VB version does not compile? Thanks. Gordon