This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
ProvideApplicationPartFactoryAttribute.cs
51 lines (45 loc) · 1.95 KB
/
ProvideApplicationPartFactoryAttribute.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNetCore.Mvc.Core;
namespace Microsoft.AspNetCore.Mvc.ApplicationParts
{
/// <summary>
/// Provides a <see cref="ApplicationPartFactory"/> type.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
public sealed class ProvideApplicationPartFactoryAttribute : Attribute
{
private readonly Type _applicationPartFactoryType;
private readonly string _applicationPartFactoryTypeName;
/// <summary>
/// Creates a new instance of <see cref="ProvideApplicationPartFactoryAttribute"/> with the specified type.
/// </summary>
/// <param name="factoryType">The factory type.</param>
public ProvideApplicationPartFactoryAttribute(Type factoryType)
{
_applicationPartFactoryType = factoryType ?? throw new ArgumentNullException(nameof(factoryType));
}
/// <summary>
/// Creates a new instance of <see cref="ProvideApplicationPartFactoryAttribute"/> with the specified type name.
/// </summary>
/// <param name="factoryTypeName">The assembly qualified type name.</param>
public ProvideApplicationPartFactoryAttribute(string factoryTypeName)
{
if (string.IsNullOrEmpty(factoryTypeName))
{
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(factoryTypeName));
}
_applicationPartFactoryTypeName = factoryTypeName;
}
/// <summary>
/// Gets the factory type.
/// </summary>
/// <returns></returns>
public Type GetFactoryType()
{
return _applicationPartFactoryType ??
Type.GetType(_applicationPartFactoryTypeName, throwOnError: true);
}
}
}