Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 869803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:22:11+00:00 2026-05-15T10:22:11+00:00

I’m trying to iterate through an array of objects and recursively print out each

  • 0

I’m trying to iterate through an array of objects and recursively print out each objects properties.
Here is my object model:

type firmIdentifier = {
    firmId: int ;
    firmName: string ;
}
type authorIdentifier = {
    authorId: int ;
    authorName: string ;
    firm: firmIdentifier ;
}

type denormalizedSuggestedTradeRecommendations = {
    id: int ; 
    ticker: string ;
    direction: string ;
    author: authorIdentifier ;
}

Here is how I am instantiating my objects:

let getMyIdeasIdeas = [|
     {id=1; ticker="msfqt"; direction="buy"; 
        author={authorId=0; authorName="john Smith"; firm={firmId=12; firmName="Firm1"}};};

     {id=2; ticker="goog"; direction="sell"; 
        author={authorId=1; authorName="Bill Jones"; firm={firmId=13; firmName="ABC Financial"}};};

     {id=3; ticker="DFHF"; direction="buy"; 
        author={authorId=2; authorName="Ron James"; firm={firmId=2; firmName="DEFFirm"}};}|]

And here is my algorithm to iterate, recurse and print:

let rec recurseObj  (sb : StringBuilder) o=
            let props : PropertyInfo [] = o.GetType().GetProperties()
            sb.Append( o.GetType().ToString()) |> ignore
            for x in props do
                let getMethod = x.GetGetMethod()
                let value = getMethod.Invoke(o, Array.empty)
                ignore <|
                        match value with
                        | :? float  | :? int | :? string | :? bool as f -> sb.Append(x.Name + ": " + f.ToString() + "," ) |> ignore
                        | _ ->  recurseObj  sb value
 for x in getMyIdeas do
                recurseObj sb x
                sb.Append("\r\n") |> ignore

If you couldnt tell, I’m trying to create a csv file and am printing out the types for debugging purposes. The problem is, the first element comes through in the order you’d expect, but all subsequent elements come through with a slightly different (and confusing) ordering of the “child” properties like so:

RpcMethods+denormalizedSuggestedTradeRecommendationsid:
1,ticker: msfqt,direction:
buy,RpcMethods+authorIdentifierauthorId:
0,authorName: john
Smith,RpcMethods+firmIdentifierfirmId:
12,firmName: Firm1,

RpcMethods+denormalizedSuggestedTradeRecommendationsid:
2,ticker: goog,direction:
sell,RpcMethods+authorIdentifierauthorName:
Bill
Jones,RpcMethods+firmIdentifierfirmName:
ABC Financial,firmId: 13,authorId: 1,

RpcMethods+denormalizedSuggestedTradeRecommendationsid:
3,ticker: DFHF,direction:
buy,RpcMethods+authorIdentifierauthorName:
Ron
James,RpcMethods+firmIdentifierfirmName:
DEFFirm,firmId: 2,authorId: 2,

Any idea what is going on here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:22:11+00:00Added an answer on May 15, 2026 at 10:22 am

    This is a reflection thing. You can’t rely on the order of the properties using reflection. I need to sort using MetaTokens. I will post this solution when I get around to implementing it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.