public Writer(Type writerType, Type resourceType = null) { if (writerType == null) { throw new ArgumentNullException("writerType"); } if (writerType.IsOpenGeneric()) { if (resourceType == null) { throw new ArgumentNullException("resourceType", "resourceType is required if the writerType is an open generic"); } _resourceType = resourceType; _writerType = writerType.MakeGenericType(resourceType); } else { var @interface = writerType.FindInterfaceThatCloses(typeof (IMediaWriter<>)); if (@interface == null) { throw new ArgumentOutOfRangeException("writerType", "writerType must be assignable to IMediaWriter<>"); } _writerType = writerType; _resourceType = @interface.GetGenericArguments().First(); } }
public WebFormViewToken(Type viewType) { _viewType = viewType; Type closedType = _viewType.FindInterfaceThatCloses(typeof (IFubuPage<>)); _modelType = closedType == null ? null : closedType.GetGenericArguments()[0]; }
public UsageGraph(string appName, Type commandType) { _appName = appName; _commandType = commandType; _inputType = commandType.FindInterfaceThatCloses(typeof (IFubuCommand<>)).GetGenericArguments().First(); _commandName = CommandFactory.CommandNameFor(commandType); _commandType.ForAttribute<CommandDescriptionAttribute>(att => { _description = att.Description; }); if (_description == null) _description = _commandType.Name; _handlers = InputParser.GetHandlers(_inputType); _commandType.ForAttribute<UsageAttribute>(att => { _usages.Add(buildUsage(att)); }); if (!_usages.Any()) { var usage = new CommandUsage() { AppName = _appName, CommandName = _commandName, UsageKey = "default", Description = _description, Arguments = _handlers.OfType<Argument>(), ValidFlags = _handlers.Where(x => !(x is Argument)) }; _usages.Add(usage); } }
public void Process(Type type, PluginGraph graph) { Type interfaceType = type.FindInterfaceThatCloses(typeof(IHbmWriter<>)); if (interfaceType != null) { graph.AddType(interfaceType, type); } }
public static Type DetermineLoaderType(Type type) { if (type.CanBeCastTo<IApplicationLoader>()) return type; if (type.CanBeCastTo<IBootstrapper>()) { return typeof (BootstrapperApplicationLoader<>).MakeGenericType(type); } var @interface = type.FindInterfaceThatCloses(typeof (IApplicationSource<,>)); if (@interface == null) throw new ArgumentOutOfRangeException("type must implement either IBootstrapper, IApplicationLoader, or IApplicationSource<TApplication,TRuntime> (FubuMVC's IApplicationSource)"); var genericArguments = @interface.GetGenericArguments(); return typeof (ApplicationLoader<,,>) .MakeGenericType(type, genericArguments.First(), genericArguments.Last()); }
// TODO -- make this strategy of resolving views swappable! public WebFormView(Type viewType) : this(viewType.ToVirtualPath()) { var pageInterface = viewType.FindInterfaceThatCloses(typeof (IFubuPage<>)); if (pageInterface != null) InputType = pageInterface.GetGenericArguments().Single(); }
public HtmlDocumentViewToken(Type documentType) { _viewModel = documentType.FindInterfaceThatCloses(typeof (IFubuPage<>)).GetGenericArguments().Single(); _documentType = documentType; }