Kartverket.MetadataEditor.Areas.HelpPage.HelpPageSampleGenerator.GetActionSample C# (CSharp) Method

GetActionSample() public method

Search for samples that are provided directly through ActionSamples.
public GetActionSample ( string controllerName, string actionName, IEnumerable parameterNames, Type type, System.Net.Http.Formatting.MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType, SampleDirection sampleDirection ) : object
controllerName string Name of the controller.
actionName string Name of the action.
parameterNames IEnumerable The parameter names.
type System.Type The CLR type.
formatter System.Net.Http.Formatting.MediaTypeFormatter The formatter.
mediaType System.Net.Http.Headers.MediaTypeHeaderValue The media type.
sampleDirection SampleDirection The value indicating whether the sample is for a request or for a response.
return object
        public virtual object GetActionSample(string controllerName, string actionName, IEnumerable<string> parameterNames, Type type, MediaTypeFormatter formatter, MediaTypeHeaderValue mediaType, SampleDirection sampleDirection)
        {
            object sample;

            // First, try to get the sample provided for the specified mediaType, sampleDirection, controllerName, actionName and parameterNames.
            // If not found, try to get the sample provided for the specified mediaType, sampleDirection, controllerName and actionName regardless of the parameterNames.
            // If still not found, try to get the sample provided for the specified mediaType and type.
            // Finally, try to get the sample provided for the specified mediaType.
            if (ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, sampleDirection, controllerName, actionName, parameterNames), out sample) ||
                ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, sampleDirection, controllerName, actionName, new[] { "*" }), out sample) ||
                ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType, type), out sample) ||
                ActionSamples.TryGetValue(new HelpPageSampleKey(mediaType), out sample))
            {
                return sample;
            }

            return null;
        }