-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ConsiderForCodeGenerationAttribute.cs
60 lines (54 loc) · 2.63 KB
/
ConsiderForCodeGenerationAttribute.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
52
53
54
55
56
57
58
59
60
namespace Orleans.CodeGeneration
{
using System;
/// <summary>
/// The attribute which informs the code generator that code should be generated for this type.
/// </summary>
public class ConsiderForCodeGenerationAttribute : Attribute
{
/// <summary>Initializes a new instance of <see cref="ConsiderForCodeGenerationAttribute"/>.</summary>
/// <param name="type">The type that the generator should generate code for</param>
/// <param name="throwOnFailure">When <see langword="true"/>, it will throw an exception if code cannot be generated for this type.</param>
protected ConsiderForCodeGenerationAttribute(Type type, bool throwOnFailure = false)
{
this.Type = type;
this.ThrowOnFailure = throwOnFailure;
}
/// <summary>
/// Gets the type which should be considered for code generation.
/// </summary>
public Type Type { get; private set; }
/// <summary>
/// Gets a value indicating whether or not to throw if code was not generated for the specified type.
/// </summary>
public bool ThrowOnFailure { get; private set; }
}
/// <summary>
/// The attribute which informs the code generator that code should be generated for this type.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class KnownTypeAttribute : ConsiderForCodeGenerationAttribute
{
/// <summary>Initializes a new instance of <see cref="KnownTypeAttribute"/>.</summary>
/// <param name="type">The type that the generator should generate code for</param>
public KnownTypeAttribute(Type type) : base(type){}
}
/// <summary>
/// The attribute which informs the code generator that code should be generated for this type.
/// Forces generation of type serializer, throwing if a serializer could not be generated.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
public sealed class GenerateSerializerAttribute : ConsiderForCodeGenerationAttribute
{
/// <summary>Initializes a new instance of <see cref="GenerateSerializerAttribute"/>.</summary>
/// <param name="type">The type that the generator should generate code for</param>
public GenerateSerializerAttribute(Type type) : base(type, true){ }
}
/// <summary>
/// Indicates that this type and all subtypes are to be considered as [Serializable].
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface)]
public sealed class KnownBaseTypeAttribute : Attribute
{
}
}