Announcement

Collapse
No announcement yet.

Analyze object structure at runtime

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Analyze object structure at runtime

    Hi

    In order to write a dynamic databinding library using Bridge, I'm wondering if it's possible to analyze the structure of a DTO object at runtime. I'm not a JS expert, but from what I understand, almost anything inJS is an array/JSON. So if I have an object with two properties Name and FirstName, I could access those properties using an array syntax:

    var x = person['firstName']

    And even better, I could iterate through its properties dynamically:

    for (var property in person)
    {
    ... //analyze the type of person[property] and do something with its value
    }
    How could such a property loop be implemented in Bridge?
    Thanks!

    Marco

    #2
    Basically like you would in JS:
    foreach (var propertyName in Object.GetOwnPropertyNames(obj))
    {
        object value = obj[propertyName];
    }
    On a side note, as far as i know, with the upcomming Bridge v1.15 they'll publish the rewrite based on roslyn with C# 6 and reflection support. Not sure how much changes and if you would rather use the reflection API.
    Last edited by Suchiman; 2016-06-14 @ 01:24 PM.

    Comment


      #3
      Ah thanks Suchiman. Sometimes we don't see the obvious... I did notice that method in code completion but didn't think it was what I was looking for.

      Comment

      Working...
      X