Is there a specific term in C# to define the ‘method.method’ type of invocation?

wu sheng 20 Reputation points
2023-11-19T12:22:15.6066667+00:00

In C#, we can use:

objectName.method

className.method

this.method

Please look at the following code, GetManager is a method, IsValid is also a method. Of course, GetManager will return an object. Ultimately, GetManager().IsValid(fileName) is actually an invocation of the ‘objectName.method’ type. But in form, GetManager().IsValid(fileName) is still a ‘method.method’ type of invocation.

My question is: Is there a specific term to define this ‘method.method’ syntax in C#? I want to search for this syntax knowledge based on the specific term.

public class LogAnalyzerUsingFactoryMethod
 {   
   public bool IsValidLogFileName(string fileName) 
     { 
         return GetManager().IsValid(fileName); 
     } 
   protected virtual IExtensionManager GetManager() 
     { 
         return new FileExtensionManager(); 
     }
 }

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,843 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,918 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 65,206 Reputation points
    2023-11-19T17:23:56.4166667+00:00

    Method chaining is the name:

    https://en.wikipedia.org/wiki/Method_chaining

    api’s that use are often called fluent. It’s also used in the builder pattern.

    0 comments No comments

  2. Philip Stuyck 1 Reputation point
    2023-11-20T14:12:00.6733333+00:00

    Fluent api's are methods that are generally returning this. So you can continue to call methods on the object you started with like for instance is done in builders. Your api is far from fluent.

    What you are doing is just plain method call chaining. method1.method2 is confusing because that is not what you do. the result of method1 is an object, in your case a different one than where you began, and method2 is a method on the result object of method 1.

    I don 't even think there is a specific name for it. But if your so called 'chain' is too deep, they call it a train wreck and it is a design smell.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.