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 8830417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:04:56+00:00 2026-06-14T08:04:56+00:00

i have a class similar to this: public class Channel { public string Title

  • 0

i have a class similar to this:

public class Channel
{
   public string Title {get;set;}
   public Guid Guid {get;set;}
   public List<Channel> Children {get;set;}
   // a lot more properties here
}

i need to convert this class tree to a the same tree structure,
but with less properties (and different names for the properties)
i.e:

public class miniChannel
{
    public string title {get;set;}
    public string key {get;set;}
    public List<miniChannel> children {get;set;}
    // ALL THE OTHER PROPERTIES ARE NOT NEEDED
}

i was thinking it would be easy traversing the tree with the following function:

public IEnumerable<MyCms.Content.Channels.Channel> Traverse(MyCms.Content.Channels.Channel channel)
{
    yield return channel;
    foreach (MyCms.Content.Channels.Channel aLocalRoot in channel.Children)
    {
        foreach (MyCms.Content.Channels.Channel aNode in Traverse(aLocalRoot))
        {
            yield return aNode;
        }
    }
}

how should i change the function so i could return a IEnumerable<miniChannel>
or, alternatively, is there some other way to do it?
Please notice that i cannot change the source class Channel

  • 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-06-14T08:04:58+00:00Added an answer on June 14, 2026 at 8:04 am

    I’d just recursively convert the tree to the new type:

    miniChannel Convert(Channel ch)
    {
        return new miniChannel
        {
            title = ch.Title,
            key = ch.Guid.ToString(),
            children = ch.Children.Select(Convert).ToList()
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class public class Item { public Coordinate coordinate { get; set;
ok, so i have a class similar to this: public class Channel { public
I have a class Similar to this public class Model { public TimeSpan Time1
I have a model similar to this: public class myModel { public ClassA ObjectA
I have a constructor method similar to this: public class Foo { public Foo
I have documents similar to this in RavenDB: public class MyClass { ... public
I have a structure similar to this: class OuterClass{ AnimatorListener sth; public OuterClass(){ sth
I have a similar code snippet like this class Search { public function search($for,
I have a class like this: public class Data { public string Name {
OK some background. I have something similar to this: class ConnectionFactory { public IConnection

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.