Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace csclt
- {
- using System;
- using System.Collections.Generic;
- using Newtonsoft.Json;
- using Contentstack.Core;
- using Contentstack.Core.Configuration;
- using Contentstack.Core.Models;
- public class Program
- {
- static void Main(string[] args)
- {
- ContentstackClient stack = new ContentstackClient(new ContentstackOptions()
- {
- ApiKey = "blt94519f01d8f92c86",
- AccessToken = "cs99af6674ef2a7a53770da6b7",
- Environment = "contentdelivery",
- });
- Entry entry = stack.ContentType("fieldtypes").Entry(
- "blt63b6985324826b78").Fetch<Entry>().GetAwaiter().GetResult();
- Console.WriteLine("Title Property: " + entry.Title);
- Console.WriteLine("Title Field from JSON: " + entry.Object["title"]);
- JsonSerializer serializer = JsonSerializer.Create(stack.SerializerSettings);
- FieldTypesEntry entryModel = entry.As<FieldTypesEntry>(serializer);
- entryModel.Render();
- }
- }
- public static class EntryExtensions
- {
- public static TEntryModel As<TEntryModel>(this Entry entry, JsonSerializer serializer)
- {
- return entry.ToJson().ToObject<TEntryModel>(serializer);
- }
- }
- public class AssetMetadata
- {
- public string Url { get; set; }
- }
- public class FieldTypesEntry
- {
- public List<string> StringField { get; set; }
- [JsonProperty(propertyName: "datefield")]
- public List<DateTime> DateTimeField { get; set; }
- public List<string> RichTextField { get; set; }
- [JsonProperty(propertyName: "asssetfield")]
- public List<AssetMetadata> AssetField { get; set; }
- [JsonProperty(propertyName: "numberfiel")]
- public List<double?> NumberField { get; set; }
- public void Render()
- {
- Console.WriteLine(GetType());
- foreach (double? number in NumberField)
- {
- Console.WriteLine("NumberField: " + number);
- }
- foreach (string value in StringField)
- {
- Console.WriteLine("StringField: " + value);
- }
- foreach (DateTime dt in DateTimeField)
- {
- Console.WriteLine("DateTimeField: " + dt);
- }
- foreach (string richText in RichTextField)
- {
- Console.WriteLine("RichTextField: " + richText);
- }
- foreach (AssetMetadata asset in AssetField)
- {
- Console.WriteLine("AssetField: " + asset.Url);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement