forked from JeremyDurnell/locbaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultAttributes.cs
More file actions
92 lines (83 loc) · 3.99 KB
/
DefaultAttributes.cs
File metadata and controls
92 lines (83 loc) · 3.99 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//---------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Description: LocBaml command line tool.
//
//---------------------------------------------------------------------------
using System;
using System.Windows;
using System.Collections.Generic;
namespace BamlLocalization
{
/// <summary>
/// Defines all the static localizability attributes
/// </summary>
internal static class DefaultAttributes
{
static DefaultAttributes()
{
// predefined localizability attributes
DefinedAttributes = new Dictionary<object, LocalizabilityAttribute>(32);
// nonlocalizable attribute
LocalizabilityAttribute notReadable = new LocalizabilityAttribute(LocalizationCategory.None);
notReadable.Readability = Readability.Unreadable;
LocalizabilityAttribute notModifiable = new LocalizabilityAttribute(LocalizationCategory.None);
notModifiable.Modifiability = Modifiability.Unmodifiable;
// not localizable CLR types
DefinedAttributes.Add(typeof(Boolean), notReadable);
DefinedAttributes.Add(typeof(Byte), notReadable);
DefinedAttributes.Add(typeof(SByte), notReadable);
DefinedAttributes.Add(typeof(Char), notReadable);
DefinedAttributes.Add(typeof(Decimal), notReadable);
DefinedAttributes.Add(typeof(Double), notReadable);
DefinedAttributes.Add(typeof(Single), notReadable);
DefinedAttributes.Add(typeof(Int32), notReadable);
DefinedAttributes.Add(typeof(UInt32), notReadable);
DefinedAttributes.Add(typeof(Int64), notReadable);
DefinedAttributes.Add(typeof(UInt64), notReadable);
DefinedAttributes.Add(typeof(Int16), notReadable);
DefinedAttributes.Add(typeof(UInt16), notReadable);
DefinedAttributes.Add(typeof(Uri), notModifiable);
}
/// <summary>
/// Get the localizability attribute for a type
/// </summary>
internal static LocalizabilityAttribute GetDefaultAttribute(object type)
{
if (DefinedAttributes.ContainsKey(type))
{
LocalizabilityAttribute predefinedAttribute = DefinedAttributes[type];
// create a copy of the predefined attribute and return the copy
LocalizabilityAttribute result = new LocalizabilityAttribute(predefinedAttribute.Category);
result.Readability = predefinedAttribute.Readability;
result.Modifiability = predefinedAttribute.Modifiability;
return result;
}
else
{
Type targetType = type as Type;
if ( targetType != null && targetType.IsValueType)
{
// It is looking for the default value of a value type (i.e. struct and enum)
// we use this default.
LocalizabilityAttribute attribute = new LocalizabilityAttribute(LocalizationCategory.Inherit);
attribute.Modifiability = Modifiability.Unmodifiable;
return attribute;
}
else
{
return DefaultAttribute;
}
}
}
internal static LocalizabilityAttribute DefaultAttribute
{
get
{
return new LocalizabilityAttribute(LocalizationCategory.Inherit);
}
}
private static Dictionary<object, LocalizabilityAttribute> DefinedAttributes; // stores pre-defined attribute for types
}
}