public static void ConfigureFrom(this Command command, IOptionBuilder optionBuilder) { foreach (var option in optionBuilder.BuildOptions()) { command.AddOption(option); } }
/// <summary> /// Populates this instance from scratch using a provided selection provider. /// </summary> /// <remarks>This instance will be cleared, and all constraints on it will be reset. /// The builder inspects the first <see cref="IPropertyItemDescriptor{T}"/> from /// <paramref name="selectionProvider"/> and creates an <see cref="IOptionBuilder"/> instance /// that will <see cref="IOptionBuilder.AddItems"/> to this instance via the builder. /// </remarks> /// <param name="selectionProvider"></param> /// <param name="contextLookup">The lookup tunnel through to the created /// <see cref="IOptionBuilderContext"/> that will be used to query the <see cref="IOptionBuilder"/> /// instances for recursive sets of properties.</param> public virtual void BuildFromSelection <T>(ISelectionProvider <T> selectionProvider, IContextLookup contextLookup) { StartContentChange(); try { Clear(); DefaultOptionBuilderContext <T> context; context = new DefaultOptionBuilderContext <T>(selectionProvider, this); context.ContextLookup = contextLookup; ConstraintManager constraintManager = this.Lookup <ConstraintManager>(); if (constraintManager == null) { constraintManager = new ConstraintManager(this); this.SetLookup(typeof(ConstraintManager), constraintManager); } constraintManager.Clear(); IEnumerator <IPropertyItemDescriptor <T> > enumerator = selectionProvider.Selection.GetEnumerator(); if (enumerator.MoveNext()) { IPropertyItemDescriptor <T> descriptor = enumerator.Current; T item; item = descriptor.Item; IOptionBuilder builder = context.GetOptionBuilder(item); if (builder != null) { builder.AddItems(context, item.GetType(), item); } } } finally { EndContentChange(); } }
/// <summary> /// Adds <see cref="IOptionItem"/>s that are bound to the label's <see cref="ILabel.LayoutParameter"/> /// and the associated <see cref="ILabelModelParameter.Model"/>. /// property to the builder. /// </summary> /// <param name="context">The context to use for building.</param> /// <param name="label">The current label instance.</param> protected virtual void AddLabelLayoutParameterItems(IOptionBuilderContext context, ILabel label) { if (label.LayoutParameter != null) { IOptionBuilder modelBuilder = GetLabelModelOptionBuilder(context, label.LayoutParameter.Model); if (modelBuilder != null) { modelBuilder.AddItems(context.CreateChildContext("Model"), label.LayoutParameter.Model.GetType(), label.LayoutParameter.Model); } } }
/// <summary> /// Builds the options for the first label of the node instance. /// </summary> /// <param name="context">The context to use for building.</param> /// <param name="subject">The current node instance.</param> protected virtual void BuildLabelOptions(IOptionBuilderContext context, ILabelOwner subject) { if (subject.Labels.Count > 0) { context = context.CreateChildContext(DefaultNodePropertyMapBuilder.LabelPropertyName); ILabel label = subject.Labels[0]; if (label != null) { IOptionBuilder builder = GetLabelOptionBuilder(context, label); if (builder != null) { builder.AddItems(context, typeof(ILabel), label); } } } }
/// <summary> /// Adds a <see cref="IOptionItem"/>s that are bound to the port's <see cref="IPort.Style"/> /// to the builder. /// </summary> /// <param name="context">The context to use for building.</param> /// <param name="port"></param> protected virtual void AddStyleItems(IOptionBuilderContext context, IPort port) { //style group... //retrieve current style... IPortStyle style = port.Style; if (style != null) { //retrieve OptionBuilder from style IOptionBuilder styleBuilder = GetStyleOptionBuilder(context, style); if (styleBuilder != null) { styleBuilder.AddItems(context.CreateChildContext(DefaultPortPropertyMapBuilder.StyleProperty), style.GetType(), style); } } }
private IOptionBuilder GetBuilder(PropertyInfo info, IOptionBuilderContext context, object subject, Type type) { IOptionBuilder builder = null; OptionBuilderAttribute builderAttribute = (OptionBuilderAttribute)Attribute.GetCustomAttribute(info, typeof(OptionBuilderAttribute)); if (builderAttribute != null) { builder = Activator.CreateInstance(builderAttribute.OptionBuilderType) as IOptionBuilder; } else { object value = info.GetGetMethod().Invoke(subject, null); builder = context.GetOptionBuilder(type, value); } return(builder); }
/// <summary> /// Builds the options for the style of the edge instance. /// </summary> /// <param name="context">The context to use for building.</param> /// <param name="edge">The current edge instance.</param> protected virtual void BuildStyleOptions(IOptionBuilderContext context, IEdge edge) { context = context.CreateChildContext(StylePropertyName); //style group... //retrieve current style... IEdgeStyle style = edge.Style; if (style != null) { //retrieve OptionBuilder from style IOptionBuilder builder = GetStyleOptionBuilder(context, style); if (builder != null) { builder.AddItems(context, style.GetType(), style); } } }
public virtual IOptionBuilder GetOptionBuilder(object subject) { IOptionBuilder builder = contextLookup.Lookup(subject, typeof(IOptionBuilder)) as IOptionBuilder; if (builder != null) { return(builder); } if (subject != null) { builder = GetBuilder(subject.GetType()); if (builder != null) { return(builder); } } return(subject != null?ReflectionHelper.GetOptionBuilderFromAttribute(subject.GetType()) : null); }
/// <summary> /// Builds the options for the style of the node instance. /// </summary> /// <param name="context">The context to use for building.</param> /// <param name="node">The current node instance.</param> protected virtual void BuildStyleOptions(IOptionBuilderContext context, INode node) { context = context.CreateChildContext(DefaultNodePropertyMapBuilder.StylePropertyName); context.BindItem(new BoolOptionItem("Shadow"), "Shadow"); //style group... //retrieve current style... INodeStyle style = node.Style; if (style != null) { //retrieve OptionBuilder from style IOptionBuilder builder = GetStyleOptionBuilder(context, style); if (builder != null) { builder.AddItems(context, style.GetType(), style); } } }
/// <inheritdoc/> public void AddItems(IOptionBuilderContext context, Type subjectType, object subject) { Type type1 = subject == null?subjectType:subject.GetType(); PropertyInfo[] propertyInfos = SortProperties(FilterProperties( type1.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy), context), context); foreach (PropertyInfo descriptor in propertyInfos) { DisplayNameAttribute displayNameAttribute = GetAttribute <DisplayNameAttribute>(descriptor); string propertyName; if (displayNameAttribute == null || displayNameAttribute.DisplayName.Length < 1) { propertyName = descriptor.Name; } else { propertyName = displayNameAttribute.DisplayName; } Type type = descriptor.PropertyType; object value = descriptor.GetGetMethod().Invoke(subject, null); IOptionBuilder builder = GetBuilder(descriptor, context, subject, type); if (builder != null) { IOptionBuilderContext childContext = context.CreateChildContext(propertyName); builder.AddItems(childContext, type, value); ConfigureItem(childContext.Lookup <IOptionGroup>(), descriptor); } else { IOptionItem item = CreateItem(context, descriptor, type, propertyName, value); if (item != null) { context.BindItem(item, propertyName); ConfigureItem(item, descriptor); } } } }
public virtual IOptionBuilder GetOptionBuilder(Type type, object subject) { if (subject != null) { return(GetOptionBuilder(subject)); } else { IOptionBuilder builder = contextLookup.Lookup(type, typeof(IOptionBuilder)) as IOptionBuilder; if (builder == null) { builder = GetBuilder(type); return(builder != null ? builder : ReflectionHelper.GetOptionBuilderFromAttribute(type)); } else { return(builder); } } }
public async Task SetBuilder(IOptionBuilder builder) { _builder = builder; if (string.IsNullOrEmpty(_builder.Option.FolderID) && string.IsNullOrEmpty(_builder.Option.FolderName)) { throw new ArgumentNullException("Either folderID or folder name is not supplied."); } if (!string.IsNullOrEmpty(_builder.Option.FolderID) && !string.IsNullOrEmpty(_builder.Option.FolderName)) { throw new ArgumentNullException("FolderID and folder name cannot be supplied at the same time."); } _credential = GoogleCredential.FromJson(_builder.Option.CredentialString).CreateScoped(Scopes); service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = _credential }); if (!string.IsNullOrEmpty(_builder.Option.Domain)) { allAccess = new Permission() { Type = "domain", Domain = _builder.Option.Domain, Role = "reader" }; } else { allAccess = new Permission() { Type = "anyone", Role = "reader" }; } folderID = await ProvisionDirectory(); }
/// <inheritdoc/> public void AddItems(IOptionBuilderContext context, Type subjectType, object subject) { PropertyInfo[] propertyInfos = SortProperties(context, FilterProperties(context, subjectType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy))); foreach (PropertyInfo info in propertyInfos) { DisplayAttribute descriptionAttribute = GetAttribute <DisplayAttribute>(info); #if UseDataAnnotations string description = descriptionAttribute == null ? info.Name : descriptionAttribute.GetName(); #else string description = descriptionAttribute == null ? info.Name : descriptionAttribute.DisplayName; #endif object value = subject == null ? null : info.GetValue(subject, null); Type type = value == null ? info.PropertyType : value.GetType(); IOptionBuilder builder = GetBuilder(context, info, subject, type); if (builder != null) { IOptionBuilderContext childContext = context.CreateChildContext(description); builder.AddItems(childContext, type, value); ConfigureItem((IOptionItem)childContext.Lookup(typeof(IOptionGroup)), info); } else { IOptionItem item = CreateItem(context, info, type, description, value); if (item != null) { context.BindItem(item, description); ConfigureItem(item, info); } } } }
public static string RenderOptions(this IOptionBuilder options) { var result = string.Join(", \n", options.Attributes.Select(p => p.Key + ": " + p.Value)); return("{\n" + result + "\n}"); }
/// <summary> /// A constructor of helper class for provider part which handle document management and consent ask. /// </summary> /// <param name="privateKey">User's private key</param> /// <param name="network">NBitcoin-compatible blockchain network</param> /// <param name="builder">Option builder for IStorageManager</param> /// <param name="api">Insight-based block explorer (>0.4)</param> public ProviderHelper(string privateKey, IInsightAPI api, IOptionBuilder builder, Network network = null) : base(privateKey, network, api) { storageManager = new GDriveStorageManager(); storageManager.SetBuilder(builder); }