| 1 |
/* |
| 2 |
Copyright (C) 2011 Jeroen Frijters |
| 3 |
|
| 4 |
This software is provided 'as-is', without any express or implied |
| 5 |
warranty. In no event will the authors be held liable for any damages |
| 6 |
arising from the use of this software. |
| 7 |
|
| 8 |
Permission is granted to anyone to use this software for any purpose, |
| 9 |
including commercial applications, and to alter it and redistribute it |
| 10 |
freely, subject to the following restrictions: |
| 11 |
|
| 12 |
1. The origin of this software must not be misrepresented; you must not |
| 13 |
claim that you wrote the original software. If you use this software |
| 14 |
in a product, an acknowledgment in the product documentation would be |
| 15 |
appreciated but is not required. |
| 16 |
2. Altered source versions must be plainly marked as such, and must not be |
| 17 |
misrepresented as being the original software. |
| 18 |
3. This notice may not be removed or altered from any source distribution. |
| 19 |
|
| 20 |
Jeroen Frijters |
| 21 |
[email protected] |
| 22 |
|
| 23 |
*/ |
| 24 |
using System; |
| 25 |
using System.Collections.Generic; |
| 26 |
using System.Text; |
| 27 |
|
| 28 |
namespace IKVM.Reflection.Emit |
| 29 |
{ |
| 30 |
public sealed class CustomModifiersBuilder |
| 31 |
{ |
| 32 |
private readonly List<Item> list = new List<Item>(); |
| 33 |
|
| 34 |
internal struct Item |
| 35 |
{ |
| 36 |
internal Type type; |
| 37 |
internal bool required; |
| 38 |
} |
| 39 |
|
| 40 |
public void AddRequired(Type type) |
| 41 |
{ |
| 42 |
Item item; |
| 43 |
item.type = type; |
| 44 |
item.required = true; |
| 45 |
list.Add(item); |
| 46 |
} |
| 47 |
|
| 48 |
public void AddOptional(Type type) |
| 49 |
{ |
| 50 |
Item item; |
| 51 |
item.type = type; |
| 52 |
item.required = false; |
| 53 |
list.Add(item); |
| 54 |
} |
| 55 |
|
| 56 |
// this adds the custom modifiers in the same order as the normal SRE APIs |
| 57 |
// (the advantage over using the SRE APIs is that a CustomModifiers object is slightly more efficient, |
| 58 |
// because unlike the Type arrays it doesn't need to be copied) |
| 59 |
public void Add(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers) |
| 60 |
{ |
| 61 |
foreach (CustomModifiers.Entry entry in CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers)) |
| 62 |
{ |
| 63 |
Item item; |
| 64 |
item.type = entry.Type; |
| 65 |
item.required = entry.IsRequired; |
| 66 |
list.Add(item); |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
public CustomModifiers Create() |
| 71 |
{ |
| 72 |
return new CustomModifiers(list); |
| 73 |
} |
| 74 |
} |
| 75 |
} |