This is a migrated thread and some comments may be shown as answers.

Create extension method of Fiddler.Session

1 Answer 145 Views
Extensions and Customization
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 28 Dec 2015, 09:06 PM

I've made a method which interacts with Fiddler in C#. The code looks like this:

using Fiddler; 
namespace SmartMocks
{
    public class SmartMocks
    {
        public static void SmartMock(Session oSession, string directoryPath)
        { //etc...
After referencing the DLL in Fiddler > Options > Extensions, I add the following to the top of FiddlerScript:

import SmartMocks;

And then I can call the function in FiddlerScript like this:

SmartMocks.SmartMocks.SmartMock(oSession, "C:\\SomeFile.txt");

This works fine. However, I'd like to make SmartMock be an extension method of Fiddler.Session, so that I can use this nicer-looking syntax instead in FiddlerScript:

oSession.SmartMock("C:\\SomeFile.txt");

I'm not familiar with JScript.NET and how it handles references, so I've been having trouble adding this method to Fiddler.Session. I tried changing the code to an extension like this:

namespace SmartMocks
{
    public static class SmartMocks
    {
        public static void SmartMock(this Session oSession, string directoryPath)
        {

However, when compiling FiddlerScript, calling "oSession.SmartMock("C:\\SomeFile.txt")" gives the error "Objects of type 'Fiddler.Session' do not have such a member".

My question is:

  • How do you create an extension method to a class (like Fiddler.Session) in JScript.NET?

1 Answer, 1 is accepted

Sort by
0
Accepted
Eric Lawrence
Telerik team
answered on 29 Dec 2015, 08:52 PM
Hello, Peter--

As far as I know, extension methods are syntactic sugar supported by the compiler, and JScript.NET has no support for them. If you find out otherwise, please do let me know.

When I use Fiddler's extension methods for strings (e.g. OICEndsWithAny()) I have to use the basic syntax, e.g.

   StringExtensions.OICEndsWithAny(sMIMEtype, arrMIMEs);

Regards,
Eric Lawrence
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Extensions and Customization
Asked by
Peter
Top achievements
Rank 1
Answers by
Eric Lawrence
Telerik team
Share this question
or