Пример #1
0
        public IResource PromptGetNestedProperty(
            IResource resource,
            ResourcePropertyInfo <NestedResourceProperty> prop
            )
        {
            var resourceTypeMap  = prop.Property.Types.ToDictionary(t => t.Name, t => t);
            var resourceTypeHelp = prop.Property.Types.Select(t =>
            {
                var r = Activator.CreateInstance(t) as IResource;
                return(r?.Help ?? "");
            }).ToList();

            Type?resourceType = null;

            while (resourceType == null)
            {
                var selection = "";
                if (resourceTypeMap.Count == 1)
                {
                    selection = resourceTypeMap.Keys.First();
                }
                else
                {
                    selection = PromptMultipleChoice(resourceTypeMap.Keys.ToList(), resourceTypeHelp, prop.Property.Help);
                }
                resourceTypeMap.TryGetValue(selection, out resourceType);
            }

            var nestedResource = PrompSetResourceProperties(resourceType);

            return(nestedResource);
        }
Пример #2
0
        public void PromptSetOptionalProperty(IResource resource, ResourcePropertyInfo <OptionalResourceProperty> prop)
        {
            var set = "";

            while (set != "y" && set != "n")
            {
                set = Prompt <string>($"Set a value for optional property {prop.Info.Name}? (y/n): ");
            }
            if (set == "y")
            {
                PromptSetProperty(resource, prop.Info, prop.Property.Help);
            }
        }
Пример #3
0
        public void PromptSetOptionalNestedProperty(
            IResource resource,
            ResourcePropertyInfo <OptionalNestedResourceProperty> prop
            )
        {
            var set = "";

            while (set != "y" && set != "n")
            {
                set = Prompt <string>($"Set a value for optional property {prop.Info.Name}? (y/n): ");
            }
            if (set == "y")
            {
                var nestedProp = new ResourcePropertyInfo <NestedResourceProperty>(
                    prop.Info, prop.Property.AsNestedResourceProperty());
                PromptSetNestedProperties(resource, nestedProp);
            }
        }
Пример #4
0
 public void PromptSetNestedProperties(
     IResource resource,
     ResourcePropertyInfo <NestedResourceProperty> prop
     )
 {
     if (prop.Info.PropertyType.IsAssignableTo(typeof(IList <IResource>)))
     {
         var    nestedList = new List <IResource>();
         Action action     = () => nestedList.Add(PromptGetNestedProperty(resource, prop));
         PromptMultiple(action, "Enter another resource?");
         resource.SetProperty(prop.Info, nestedList);
     }
     else
     {
         var nested = PromptGetNestedProperty(resource, prop);
         resource.SetProperty(prop.Info, nested);
     }
 }