Example #1
0
        /// <summary>
        /// Creates a dictionary of all properties and their values on a parameter set.
        /// </summary>
        /// <typeparam name="T">The parameter value type.</typeparam>
        /// <param name="parameterSet">The parameter set.</param>
        /// <param name="givenOnly">If <c>true</c>, only parameters that were set/given are returned and parameters that are left to their default/nonsense value are skipped. <c>true</c> by default.</param>
        /// <returns>
        /// A read-only dictionary for all members and their values.
        /// </returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="parameterSet"/> is <c>null</c>.</exception>
        public static IReadOnlyDictionary <MemberDescription, T> ParameterValues <T>(this IParameterSet parameterSet, bool givenOnly = true)
        {
            parameterSet.ThrowIfNull(nameof(parameterSet));
            var result = new Dictionary <MemberDescription, T>();

            foreach (var member in Parameters(parameterSet.GetType()))
            {
                if (member.Names == null || member.Names.Count == 0)
                {
                    continue;
                }
                if (givenOnly)
                {
                    if (member.TryGet <GivenParameter <T> >(parameterSet, out var gp))
                    {
                        if (gp.Given)
                        {
                            result.Add(member, gp.Value);
                        }
                        continue;
                    }
                }
                if (parameterSet.TryGetProperty <T>(member.Names.First(), out var value))
                {
                    result.Add(member, value);
                }
            }
            return(new ReadOnlyDictionary <MemberDescription, T>(result));
        }
Example #2
0
 public static RenderPackage? LoadFromXml(ComputeContext computeContext, KernelXmlFile kernelXml, IParameterSet oldParameterSetCache)
 {
     var kernel = RenderKernel.Create(computeContext, kernelXml.Files.Select(File.ReadAllText).ToArray());
     if (kernel == null)
         return null;
     var controls = kernelXml.ControlsFunc();
     if (oldParameterSetCache != null && controls.GetType() == oldParameterSetCache.GetType())
         controls = oldParameterSetCache;
     return new RenderPackage(kernel, controls);
 }
Example #3
0
 /// <summary>
 /// Enumerates all the named parameters and properties of an <see cref="IParameterSet"/>.
 /// </summary>
 /// <param name="parameters">The parameter set.</param>
 /// <returns>
 /// All the named parameters.
 /// </returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="parameters"/> is <c>null</c>.</exception>
 public static IEnumerable <MemberDocumentation> Parameters(this IParameterSet parameters)
 => GetMembers(parameters?.GetType());