Skip to content

Commit

Permalink
Finished adding XML comments on all publically visible types/members
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrianball committed Jan 30, 2019
1 parent 9e52e84 commit 89561ee
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 31 deletions.
7 changes: 4 additions & 3 deletions Args/Help/ResourceMemberHelpAttributeBase.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Args.Help
{
Expand All @@ -14,6 +11,10 @@ namespace Args.Help
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Class)]
public abstract class ResourceMemberHelpAttributeBase : Attribute
{
/// <summary>
/// Returns the helptext provided by the implementation of <see cref="ResourceMemberHelpAttributeBase"/>
/// </summary>
/// <returns></returns>
public abstract string GetHelpText();
}
}
18 changes: 12 additions & 6 deletions Args/IArgsConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Args
namespace Args
{
/// <summary>
/// An interface that will configure an IModelBindingDefinition based on a given initializer
/// </summary>
public interface IArgsConfiguration
{
/// <summary>
/// When implemented, this method will configure the model binder
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <returns></returns>
IModelBindingDefinition<TModel> Configure<TModel>();
/// <summary>
/// When implemented, this method will configure the model binder with the provided initializer
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <param name="initalizer"></param>
/// <returns></returns>
IModelBindingDefinition<TModel> Configure<TModel>(IModelBindingDefinitionInitializer initalizer);
}
}
12 changes: 6 additions & 6 deletions Args/IArgsTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Args
namespace Args
{
/// <summary>
/// A simple interface to impelment for type conversion from string. If a TypeConverter for the type does not already exist, this is the easiest way to do type conversion in Args
/// </summary>
public interface IArgsTypeConverter
{
/// <summary>
/// When implemented, this method will convert the provided value
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
object Convert(string value);
}
}
5 changes: 5 additions & 0 deletions Args/IInitializeModelBindingDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace Args
/// </summary>
public interface IModelBindingDefinitionInitializer
{
/// <summary>
/// When implemented, this method will initialize the provided <see cref="IModelBindingDefinition{TModel}"/>
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <param name="init"></param>
void Initialize<TModel>(IModelBindingDefinition<TModel> init);
}
}
37 changes: 36 additions & 1 deletion Args/IMemberBindingDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel;
using System.Reflection;

namespace Args
{
Expand All @@ -10,18 +10,53 @@ namespace Args
/// <typeparam name="TModel">Type of the model to bind</typeparam>
public interface IMemberBindingDefinition<TModel>
{
/// <summary>
/// Returns the parent that the current member belongs to
/// </summary>
IModelBindingDefinition<TModel> Parent { get; }
/// <summary>
/// Returns the <see cref="MemberInfo"/> of the current member binding definition
/// </summary>
MemberInfo MemberInfo { get; }
/// <summary>
/// Gets or sets the type converter that will be used to parse the value for the current member
/// </summary>
TypeConverter TypeConverter { get; set; }
/// <summary>
/// Holds the collection of switch value(s) that will bind to the current member binding definition
/// </summary>
ICollection<string> SwitchValues { get; }
/// <summary>
/// Gets or sets the default value to use if no value is provided
/// </summary>
object DefaultValue { get; set; }
/// <summary>
/// When implemented, returns a value that indicates if the provided witch is handled by the current member
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
bool CanHandleSwitch(string s);
/// <summary>
/// Gets or sets the help text value for the current member
/// </summary>
string HelpText { get; set; }
/// <summary>
/// Indicates if the current member is reuired
/// </summary>
bool Required { get; set; }
}

/// <summary>
/// Extension methods that applies to all instances of the <see cref="IMemberBindingDefinition{TModel} "/> interface
/// </summary>
public static class MemberBindingDefinitionExtensions
{
/// <summary>
/// Returns an object that will allow the member binding to be fluently configured
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public static FluentMemberBindingConfiguration<TModel> AsFluent<TModel>(this IMemberBindingDefinition<TModel> source)
{
return new FluentMemberBindingConfiguration<TModel>(source);
Expand Down
65 changes: 65 additions & 0 deletions Args/IModelBindingDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,90 @@ namespace Args
/// <typeparam name="TModel">Type of the model to bind</typeparam>
public interface IModelBindingDefinition<TModel>
{
/// <summary>
/// A dictionary of type converters to use for the specified types
/// </summary>
IDictionary<Type, TypeConverter> TypeConverters { get; }
/// <summary>
/// The string value that indicates the start of a command switch
/// </summary>
string SwitchDelimiter { get; set; }
/// <summary>
/// The <see cref="System.StringComparer"/> to use when comparing swtich values
/// </summary>
StringComparer StringComparer { get; set; }
/// <summary>
/// The collection of configured members for the model
/// </summary>
IEnumerable<IMemberBindingDefinition<TModel>> Members { get; }
/// <summary>
/// The description for the model; for use when help text is requested
/// </summary>
string CommandModelDescription { get; set; }

/// <summary>
/// Gets or creates an <see cref="IMemberBindingDefinition{TModel}"/> for the provided member
/// </summary>
/// <param name="member"></param>
/// <returns></returns>
IMemberBindingDefinition<TModel> GetOrCreateMemberBindingDefinition(MemberInfo member);
/// <summary>
/// Gets an <see cref="IMemberBindingDefinition{TModel}"/> for the provided member
/// </summary>
/// <param name="member"></param>
/// <returns></returns>
IMemberBindingDefinition<TModel> GetMemberBindingDefinition(MemberInfo member);
/// <summary>
/// Creates an instance of <typeparamref name="TModel"/> and binds members based on the provided args
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
TModel CreateAndBind(IEnumerable<string> args);
/// <summary>
/// Binds the provided <paramref name="args"/> to the provided <paramref name="model"/>
/// </summary>
/// <param name="model"></param>
/// <param name="args"></param>
void BindModel(TModel model, IEnumerable<string> args);
/// <summary>
/// Adds the provided <paramref name="member"/> as an ordinal argument
/// </summary>
/// <param name="member"></param>
void AddOrdinalArgument(MemberInfo member);
/// <summary>
/// Sets the provided <paramref name="members"/> as the ordinal arguments
/// </summary>
/// <param name="members"></param>
void SetOrdinalArguments(IEnumerable<MemberInfo> members);
/// <summary>
/// Gets the configured ordinal arguments
/// </summary>
/// <returns></returns>
IEnumerable<MemberInfo> GetOrdinalArguments();
/// <summary>
/// Removes a previously configured <paramref name="member"/>
/// </summary>
/// <param name="member"></param>
void RemoveMember(MemberInfo member);
/// <summary>
/// Retrives the ordinal index of the provided <paramref name="member"/>; Returns <see langword="null"/> if the provided <paramref name="member"/> is not an ordinal member
/// </summary>
/// <param name="member"></param>
/// <returns></returns>
int? OrdinalIndexOf(MemberInfo member);
}

/// <summary>
/// Helpful extension methods for <see cref="IModelBindingDefinition{TModel}"/>
/// </summary>
public static class ModelBindingDefinitionExtensions
{
/// <summary>
/// Returns an object that allows the model to be configured fluently
/// </summary>
/// <typeparam name="TModel"></typeparam>
/// <param name="source"></param>
/// <returns></returns>
public static FluentModelBindingConfiguration<TModel> AsFluent<TModel>(this IModelBindingDefinition<TModel> source)
{
return new FluentModelBindingConfiguration<TModel>(source);
Expand Down
22 changes: 21 additions & 1 deletion Args/InvalidArgsFormatException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,34 @@

namespace Args
{
[Serializable]
/// <summary>
/// An exception thrown if the provided args are not in a format that can be parsed
/// </summary>
[Serializable]
public class InvalidArgsFormatException : Exception
{
/// <summary>
///
/// </summary>
public InvalidArgsFormatException() { }
/// <summary>
///
/// </summary>
/// <param name="message"></param>
public InvalidArgsFormatException(string message) : base(message) { }
/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="inner"></param>
public InvalidArgsFormatException(string message, Exception inner) : base(message, inner) { }

#if !NETSTANDARD_1_3
/// <summary>
///
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
protected InvalidArgsFormatException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
Expand Down
12 changes: 9 additions & 3 deletions Args/LambdaArgsTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Args
{
Expand All @@ -12,11 +9,20 @@ public class LambdaArgsTypeConverter : IArgsTypeConverter
{
private readonly Func<string, object> converter;

/// <summary>
///
/// </summary>
/// <param name="converter"></param>
public LambdaArgsTypeConverter(Func<string, object> converter)
{
this.converter = converter;
}

/// <summary>
/// Converts the provided <paramref name="value"/>
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public object Convert(string value)
{
return converter(value);
Expand Down
Loading

0 comments on commit 89561ee

Please sign in to comment.