Beispiel #1
0
        private static void RenderSampleSelection(SampleSection section)
        {
            // Get all the samples exposed by the current assembly
            KeyValuePair <SampleAttribute, Type>[] samples = SamplesHelper
                                                             .GetSectionSamples(section)
                                                             .ToArray();

            // Calculate the selectable options
            string[] options = samples
                               .Select(x => x.Key.Name)
                               .Concat(new[] { "Cancel" })
                               .ToArray();

            // Read in the sample option
            Console.Clear();
            Console.WriteLine($"===== {section} Samples =====");
            SamplesHelper.RenderOptions(options);
            int index = SamplesHelper.ReadIntInRange(1, options.Length) - 1;

            // Resolve the action
            if (index < options.Length - 1)
            {
                RenderSample(samples[index].Key, samples[index].Value);
            }
        }
Beispiel #2
0
        private static bool RenderSectionSelection()
        {
            // Render the options
            Console.Clear();
            Console.WriteLine("===== System.Linq.Sql Samples =====");
            Console.WriteLine("These samples demonstrate some of the common usages of this library.");
            SamplesHelper.RenderOptions <SampleSection>();

            // Read the desired section
            SampleSection section = SamplesHelper.ReadInRange <SampleSection>();

            if (section == SampleSection.Exit)
            {
                return(true);
            }

            // Render the section
            RenderSampleSelection(section);

            return(false);
        }
Beispiel #3
0
 public static IOrderedEnumerable <KeyValuePair <SampleAttribute, Type> > GetSectionSamples(SampleSection section)
 {
     return(typeof(SampleSection).Assembly
            .GetTypes()
            .Where(x => typeof(ISample).IsAssignableFrom(x))
            .Select(x => new
     {
         Attribute = x.GetSampleAttribute(),
         Type = x
     })
            .Where(x => x.Attribute != null)
            .ToDictionary(x => x.Attribute, x => x.Type)
            .Where(x => x.Key?.Section == section)
            .OrderBy(x => x.Value.Name));
 }