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

  • Home
  • SEARCH
  • 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 427317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:34:00+00:00 2026-05-12T19:34:00+00:00

For context – read this . Problem: class Program { static void Main() {

  • 0

For context – read this.

Problem:

 class Program
    {
        static void Main()
        {
            var b = new bar();

            b.buzz().fizz().buzz().fizz(); //cool
            //              ^FAIL!!!...<------------------------------------
            Console.ReadLine();
        }
    }

    public class foo
    {
        public foo fizz() { return this; }
    }

    public class bar : foo
    {
        public bar buzz()
        {
            return this;
        }
    }

Solution:

 class Program
    {
        static void Main()
        {
            var b = new bar();

            b.buzz().fizz().buzz().fizz(); //cool stuff
            Console.ReadKey();
        }
    }

    public static class fooExtensions
    {
        public static T fizz<T>(this T t) where T : foo
        { return t; } 
    }

    public class foo{}

    public class bar : foo
    {
        public bar buzz()
        {
            return this;
        }
    }

This is a technique how to ‘mimic’ method of base class which is able to return back derived type (otherwise my b couldn’t call buzz() again).

Going further and making foo/bar generic (this will still work fine):

  class Program
    {
        static void Main()
        {
            var b = new bar<buzz>();

            b.buzz().fizz().buzz().fizz(); //cool
            Console.ReadLine();
        }
    }

    public static class fooExtensions
    {
        public static T fizz<T>(this T t) where T : foo<buzz>
        { return t; }
    }

    public class buzz { public string name { get; set;} }

    public class foo<T> where T : buzz
    {}

    public class bar<T> : foo<T> where T : buzz
    {
        public bar<T> buzz()
        {
            return this;
        }
    }

And the question is –
how to pass lambda to fizz method that knows about tbuzz and it’s properties without passing type parameter/s explicitly.

Broken code that might reflect what i’m looking for:

class Program
    {
        static void Main()
        {
            var b = new bar<buzz>();

            b.buzz().fizz(x=>x.name).buzz().fizz(); //not cool anymore
            //               ^FAIL!!!<---------------------------------
            Console.ReadLine();
        }
    }

    public static class fooExtensions
    {
        //NO IDEAS WHAT TO WRITE BELOW!!!
        public static T fizz<T, Tbuzz>(this T t, 
            Func<Tbuzz, object> superlambda)
            where T : foo<buzz>
            where Tbuzz : buzz 
        {
            return t;
        }
    }

    public class buzz { public string name { get; set;} }

    public class foo<T> where T : buzz
    {}

    public class bar<T> : foo<T> where T : buzz
    {
        public bar<T> buzz()
        {
            return this;
        }
    }

Wondering if that’s possible. And if not – why?

Theoretically – foo<T> knows that there’s a buzz underneath.

Are there any other approach how to create base method or mimic it that supports chaining for such a classes?

  • 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-12T19:34:00+00:00Added an answer on May 12, 2026 at 7:34 pm

    I don’t think what you’re trying to accomplish is possible. Theoretically what you would need is some kind of constraint like:

    where TBuzz : T<inner> 
    

    meaning TBuzz needs to be the type that’s the inner generic type of T. This isn’t possible as far as I know.

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

Sidebar

Related Questions

Context: This is an abstract class whose implementation is provided by the Android system
Context: Suppose one has the following class structure: public static class SomeStaticClass { public
Context This is a question mainly about Lucene (or possibly Solr) internals. The main
Context: .NET 3.5, VS2008. I'm not sure about the title of this question, so
Context: We are building a framework for rapid delivery of WPF applications. This framework
Context: static ThreadLocal<MyType> threadLocalMyType = ... What i'd like is to say something like:
Context: I'm trying to improve the values returned by the iPhone CLLocationManager, although this
Context: I can create a shared object library which is linked to a static
Context I want to make this call via reflection instanceOfEventPublisher.Publish<T>(T eventInst); When I call
Context : This is for a software develop internally and used only by company's

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.