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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:41:53+00:00 2026-05-30T04:41:53+00:00

Given a MethodDeclarationSyntax object how can I find out the method’s declaring type? My

  • 0

Given a MethodDeclarationSyntax object how can I find out the method’s declaring type?

My actual problem is that I need to figure it out whether the referenced method is implementing an interface method or not.

For instance, given the code bellow, if I have a MethodDeclarationSyntax for the Dispose() method, how can conclude it is the implementation of the IDisposable.Dispose()?

using System;
abstract class InterfaceImplementation : IDisposable
{
    public abstract void Dispose();
}

I’ve tried to get the method’s declaring type (and check the type) with no success (Parent property gives me back InterfaceImplementation class).

I also have tried to grab the semantic symbol for the method:

var methodSymbol = (MethodSymbol) semanticModel.GetDeclaredSymbol(methodDeclaration);

but could not spot anything that could help me.

Ideas?

  • 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-30T04:41:55+00:00Added an answer on May 30, 2026 at 4:41 am

    Once you have the method symbol, you can ask if a given method is implementing an interface method within a given type. The code is fairly simple:

    MethodSymbol method = ...;
    TypeSymbol type = method.ContainingType;
    MethodSymbol disposeMethod = (MethodSymbol)c.GetSpecialType(SpecialType.System_IDisposable).GetMembers("Dispose").Single();
    bool isDisposeMethod = method.Equals(type.FindImplementationForInterfaceMember(disposeMethod));
    

    It’s important to note this assumes the type that contains the Dispose method is the type that states it implements IDisposable. In C#, it’s possible for a method to implement an interface method that’s only stated on a derived type. More concretely, if you ommtted the “: IDisposable” on your code above, and had a derived type of InterfaceImplementation that was IDisposable, that Dispose() method can still implement it.

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

Sidebar

Related Questions

Given a tree, how to find the centre node in the tree so that
Given a class that keeps a registry of its Objects: class Person(object): __registry =
Given long long int x, y; , I want a function that can compare
Given a Python object of any kind, is there an easy way to get
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given a latitude and longitude, what is the easiest way to find the name
Given a abstract factory implementation: public class FooFactory : IFooFactory { public IFoo Create(object
Given the following string: s = 'abcdefg*' How can I match it or any
Given this: $ids = ''; I just realized that this: $single = $ids ==
Given a storyboard-based application, how can any one view controller invoke the methods of

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.