public ObjectModel(string cmdName, IRootObjectModel parentModel, string cmdDescription = null) { if (string.IsNullOrEmpty(cmdName)) { throw new ArgumentException($"You must specify a {nameof(cmdName)}"); } if (parentModel == null) { throw new ArgumentException( $"You must specify a parent {nameof(IObjectModel)}"); } var genericType = typeof(ObjectBinder <>); var objBinderType = genericType.MakeGenericType(GetType()); ObjectBinder = (IObjectBinder)Activator.CreateInstance( objBinderType, this, cmdName, parentModel, cmdDescription); parentModel.Command.AddCommand(ObjectBinder.Command); }
public ObjectBinder( TModel target, string cmdName, IRootObjectModel parentModel = null, string cmdDescription = null ) { if (string.IsNullOrEmpty(cmdName) && parentModel != null) { throw new ArgumentException( $"If you specify an {nameof(IObjectModel)} you must also specify a {nameof(cmdName)}"); } if (target == null) { throw new NullReferenceException(nameof(target)); } Command = parentModel == null ? new RootCommand(cmdDescription) : new Command(cmdName, cmdDescription); Target = target; ModelBinder = new ModelBinder <TModel>(); }