dimanche 18 janvier 2015

Get property name and the type it expects from an object

How can I get all the property names and the value type it expects from an object?


Suppose I have these 2 entity classes:



public class Blog
{
public int Id { get; set; }
public string Title { get; set; }
public string BloggerName { get; set;}
public Post Post { get; set; }
}

public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public DateTime DateCreated { get; set; }
public string Content { get; set; }
public int BlogId { get; set; }
public Comment Comment { get; set; }
}


How can I get this as the result:



  • "Blog.Id expects an int"

  • "Blog.Title expects a string"

  • "Blog.BloggerName expects a string"

  • "Post.Id expects an int"

  • "Post.Title expects a string"

  • "Post.DateCreated expects a string"

  • etc...


I know this can be done one property at a time, but is there a more elegant way of doing this as the entity class has many properties (and they change from type as it is still in development) and has complex objects for which I want to do the same?






Aucun commentaire:

Enregistrer un commentaire