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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:02:48+00:00 2026-06-05T07:02:48+00:00

I’m facing a requirement to create a static method on my base class, but

  • 0

I’m facing a requirement to create a static method on my base class, but don’t like that I have to declare type arguments, so I’m wondering if I’m going about this the right way.

Basically, I’m assigning delegates that I’ll associate with properties on the class. I could easily put the method on the inherited classes, like so:

public class Foo 
{
   public string Property1 { get; set; }
}

public class InheritsFoo : Foo 
{
    public void AssignDel<TVal>(
        Expression<Func<InheritsFoo, TVal>> expr, 
        Action<InheritsFoo, TVal> action) 
    {
    }
}

Or, in an extension class, I could do this:

public static void AssignDel<T, TVal>(
    this T source, 
    Expression<T, TVal>> expression, 
    Action<T, TVal> action) 
    where T : Foo 
{
}

Both of these would enable me to use AssignDel in an instantiated class:

var foo = new InheritsFoo();
foo.AssignDel(x => x.Property1, handler);

But I have a requirement to make AssignDel static. This makes the extension way of doing it useless. It still works in InheritsFoo, but I really want to move this to the base class. If I try, the generics argument can’t be inferred, and I have to change the usage of the method:

InheritsFoo.AssignDel<InheritsFoo, string>(x => x.Property1, handler);

Is there a way out here, another way of doing this I haven’t thought of?

EDIT: to address the issue in the comments about whether or not the extension method would/should work… I went to the url referenced by @Mark M. Turns out that if I write it as such…

InheritsFoo foo = null;
foo.AssignDel(x => x.Property1, handler);

That compiles (don’t know if it will run, though). Still, don’t think that qualifies as using a static method, since ‘foo’ is still considered an instance; A null instance, but an instance nonetheless.

  • 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-05T07:02:51+00:00Added an answer on June 5, 2026 at 7:02 am

    I managed to do what I needed by just implementing another level in the inheritance chain.

    public class Foo  
    {    
       public string Property1 { get; set; } 
    } 
    
    public class Foo<T> : Foo
    {
       public static void AssignDel<TVal>(Expression<Func<T, TVal>> expr, Action<T, TVal> action)
       {   }
    }
    
    public class InheritsFoo : Foo<InheritsFoo>
    {     } 
    

    I can treat InheritsFoo just as I need it.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites 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.