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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:01:37+00:00 2026-05-11T18:01:37+00:00

I am writing a custom ConfigurationElementCollection for a custom ConfigurationHandler in C#.NET 3.5 and

  • 0

I am writing a custom ConfigurationElementCollection for a custom ConfigurationHandler in C#.NET 3.5 and I am wanting to expose the IEnumerator as a generic IEnumerator.

What would be the best way to achieve this?

I am currently using the code:

public new IEnumerator<GenericObject> GetEnumerator()
{
  var list = new List();
  var baseEnum = base.GetEnumerator();
  while(baseEnum.MoveNext())
  {
    var obj = baseEnum.Current as GenericObject;
    if (obj != null)
      list.Add(obj);
  }
  return list.GetEnumerator();
}

Cheers

  • 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-11T18:01:37+00:00Added an answer on May 11, 2026 at 6:01 pm

    I don’t believe there’s anything in the framework, but you could easily write one:

    IEnumerator<T> Cast<T>(IEnumerator iterator)
    {
        while (iterator.MoveNext())
        {
            yield return (T) iterator.Current;
        }
    }
    

    It’s tempting to just call Enumerable.Cast<T> from LINQ and then call GetEnumerator() on the result – but if your class already implements IEnumerable<T> and T is a value type, that acts as a no-op, so the GetEnumerator() call recurses and throws a StackOverflowException. It’s safe to use return foo.Cast<T>.GetEnumerator(); when foo is definitely a different object (which doesn’t delegate back to this one) but otherwise, you’re probably best off using the code above.

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

Sidebar

Related Questions

I'm writing custom JSF 2.0 components. Is there way to step through each of
Aside from writing custom code are there any existing features in .NET which allows
I need help writing custom functions for my casio fx-9860g I have done this
I know I can do this by writing custom type descriptors etc., however given
.NET 2.0 added the EventHandler<TArgs> generic delegate type to simplify the process of writing
I'm new to writing custom ASP.NET server controls, and I'm encountering the following issue:
I created custom django-admin command. I use this tutorial Writing custom django-admin commands For
I am writing a custom .pac script for use with Firefox. Following numerous examples
I'm writing a custom deserializer that will deserialize a list by deserializing each of
I am writing a custom wrapper for open_flash_chart plugin. It's placed in /lib and

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.