Object Mapping

Platformus has built-in object mapper that allows you to map the C# objects on the Platformus ones and vice versa. Using this feature you can, for example, create a comment object inside a custom form handler.

Let’s see how it works. First of all, we need to create a class in the Platformus backend. Create a simple Cat class with two properties: Name (localizable single line plain text) and Birthday (date):


It corresponds next C# class (create it inside the main web application project):

public class Cat
  public IDictionary<string, string> Name { get; set; }
  public DateTime Birthday { get; set; }

Now you can use the StronglyTypedObjectMapper class to work with the Cat objects. To select all the cats, use this code:

IEnumerable<Cat> cats = new StronglyTypedObjectMapper(this).All<Cat>();

To create a cat use the following code:

Cat cat = new Cat();

cat.Name = new Dictionary<string, string>() { { "en", "Cat #1" }, { "ru", "Кот №1" }, { "uk", "Кіт №1" } };
cat.Birthday = DateTime.Now;
new StronglyTypedObjectMapper(this).Create(cat);