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

Help on porting JScript.NET snippet to C#

1 Answer 125 Views
Extensions and Customization
This is a migrated thread and some comments may be shown as answers.
Rohit
Top achievements
Rank 1
Rohit asked on 07 Aug 2019, 02:03 PM

Hi,

My apologies to post it here, as the question isn't very much specific to Fiddler, rather for the programming languages in use for Fiddler, like JScript.NET and C# in general.

I've below snippet written in the FiddlerScript (using JScript.NET) to match the hostname against a set of RegEx patterns, and I'm trying to port into C#, but it doesn't seem to work. Any help is appreciated.

var sHostname = oSession.hostname;
 
switch(sHostname) {
    case /example1.com/i.test(sHostname) && sHostname:
    case /example2.com/i.test(sHostname) && sHostname:
    case /example3.com/i.test(sHostname) && sHostname:
        MessageBox.Show("Matched: " + sHostname);
    default:
        FiddlerApplication.Log.LogString("No match for hostname.");
}

 

Cheers,

1 Answer, 1 is accepted

Sort by
0
Eric R | Senior Technical Support Engineer
Telerik team
answered on 12 Aug 2019, 01:50 PM
Hi Rohit,

The case element would need to switch on the actual value of the reference variable. It would look something like the below, where HostNameValue1 and HostNameValue2 is the actual value of the sHostname variable. 

var sHostname = oSession.hostname;
switch (sHostname)
{
    case HostNameValue1:
        Debug.WriteLine("Matched: " + sHostname);
        break;
    case HostNameValue2:
        Debug.WriteLine("Matched: " + sHostname);
        break;
    default:
        Debug.WriteLine("No Match for HostName);
        break;
}

For your reference, the C# Switch documentation provides a great example. 

Please let me know if you need any additional information. Thank you for using the Fiddler Forums.

Regards,

Eric R | Technical Support Engineer
Progress 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
Rohit
Top achievements
Rank 1
Answers by
Eric R | Senior Technical Support Engineer
Telerik team
Share this question
or