summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs
blob: 4fb2059b85dd07656160368d084412ea102a38c4 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Reflection;

namespace ProtoBuf.Meta
{
	internal abstract class AttributeMap
	{
		public abstract Type AttributeType { get; }

		public abstract object Target { get; }

		private sealed class ReflectionAttributeMap : AttributeMap
		{
			public override object Target
			{
				get
				{
					return this.attribute;
				}
			}

			public override Type AttributeType
			{
				get
				{
					return this.attribute.GetType();
				}
			}

			private readonly Attribute attribute;

			public override bool TryGet(string key, bool publicOnly, out object value)
			{
				foreach (MemberInfo memberInfo in Helpers.GetInstanceFieldsAndProperties(this.attribute.GetType(), publicOnly))
				{
					bool flag = string.Equals(memberInfo.Name, key, StringComparison.OrdinalIgnoreCase);
					if (flag)
					{
						PropertyInfo propertyInfo = memberInfo as PropertyInfo;
						bool flag2 = propertyInfo != null;
						bool result;
						if (flag2)
						{
							value = propertyInfo.GetValue(this.attribute, null);
							result = true;
						}
						else
						{
							FieldInfo fieldInfo = memberInfo as FieldInfo;
							bool flag3 = fieldInfo != null;
							if (!flag3)
							{
								throw new NotSupportedException(memberInfo.GetType().Name);
							}
							value = fieldInfo.GetValue(this.attribute);
							result = true;
						}
						return result;
					}
				}
				value = null;
				return false;
			}

			public ReflectionAttributeMap(Attribute attribute)
			{
				this.attribute = attribute;
			}
		}

		[Obsolete("Please use AttributeType instead")]
		public new Type GetType()
		{
			return this.AttributeType;
		}

		public abstract bool TryGet(string key, bool publicOnly, out object value);

		public bool TryGet(string key, out object value)
		{
			return this.TryGet(key, true, out value);
		}

		public static AttributeMap[] Create(TypeModel model, Type type, bool inherit)
		{
			object[] customAttributes = type.GetCustomAttributes(inherit);
			AttributeMap[] array = new AttributeMap[customAttributes.Length];
			for (int i = 0; i < customAttributes.Length; i++)
			{
				array[i] = new AttributeMap.ReflectionAttributeMap((Attribute)customAttributes[i]);
			}
			return array;
		}

		public static AttributeMap[] Create(TypeModel model, MemberInfo member, bool inherit)
		{
			object[] customAttributes = member.GetCustomAttributes(inherit);
			AttributeMap[] array = new AttributeMap[customAttributes.Length];
			for (int i = 0; i < customAttributes.Length; i++)
			{
				array[i] = new AttributeMap.ReflectionAttributeMap((Attribute)customAttributes[i]);
			}
			return array;
		}

		public static AttributeMap[] Create(TypeModel model, Assembly assembly)
		{
			object[] customAttributes = assembly.GetCustomAttributes(false);
			AttributeMap[] array = new AttributeMap[customAttributes.Length];
			for (int i = 0; i < customAttributes.Length; i++)
			{
				array[i] = new AttributeMap.ReflectionAttributeMap((Attribute)customAttributes[i]);
			}
			return array;
		}
	}
}