summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs')
-rw-r--r--Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs117
1 files changed, 117 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs
new file mode 100644
index 00000000..4fb2059b
--- /dev/null
+++ b/Client/Assets/Scripts/XMainClient/ProtoBuf/Meta/AttributeMap.cs
@@ -0,0 +1,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;
+ }
+ }
+}