Ejemplo n.º 1
0
        public static void Init()
        {
            SerializeEnumAttribute.CacheSerializeEnum(typeof(EaseType));

            var assembly = typeof(EaseType).Assembly;
            var space    = typeof(EaseType).Namespace;
            var enumName = nameof(EaseType);
            var infos    = SerializeEnumAttribute.TypeInfosDic[enumName];

            foreach (var info in infos)
            {
                ValueNameDic.Add(info.Index, info.Name);
                ValueShowNameDic.Add(info.Index, info.DisplayName);
                NameValueDic.Add(info.DisplayName, info.Index);
            }

            foreach (var kv in ValueNameDic)
            {
                var typeName     = kv.Value;
                var fullTypeName = space + "." + typeName;
                var type         = assembly.GetType(fullTypeName);
                ValueTypeDic.Add(kv.Key, type);
                var function = Activator.CreateInstance(type) as EaseFunction;
                ValueFunctionDic.Add(kv.Key, function);
            }
        }
Ejemplo n.º 2
0
        static EaseType()
        {
            var assembly      = typeof(EaseType).Assembly;
            var space         = typeof(EaseType).Namespace;
            var fieldInfos    = typeof(EaseType).GetFields();
            var fieldsList    = new List <FieldInfo>();
            var attributeList = new List <EnumPropertyAttribute>();

            foreach (var fieldInfo in fieldInfos)
            {
                var attributes = fieldInfo.GetCustomAttributes(true);
                foreach (var attribute in attributes)
                {
                    if (attribute.GetType() == typeof(EnumPropertyAttribute))
                    {
                        var enumPropertyAttribute = attribute as EnumPropertyAttribute;
                        if (enumPropertyAttribute == null || !enumPropertyAttribute.Display)
                        {
                            continue;
                        }
                        fieldsList.Add(fieldInfo);
                        attributeList.Add(enumPropertyAttribute);
                    }
                }
            }

            for (var i = 0; i < fieldsList.Count; i++)
            {
                var fieldInfo   = fieldsList[i];
                var attribute   = attributeList[i];
                var indexValue  = (int)fieldInfo.GetValue(null);
                var displayName = string.IsNullOrEmpty(attribute.DisplayName) ? fieldInfo.Name : attribute.DisplayName;

                ValueNameDic.Add(indexValue, fieldInfo.Name);
                ValueShowNameDic.Add(indexValue, displayName);
                NameValueDic.Add(displayName, indexValue);
            }

            foreach (var kv in ValueNameDic)
            {
                var typeName     = kv.Value;
                var fullTypeName = space + "." + typeName;
                var type         = assembly.GetType(fullTypeName);
                ValueTypeDic.Add(kv.Key, type);
                var function = Activator.CreateInstance(type) as EaseFunction;
                ValueFunctionDic.Add(kv.Key, function);
            }
        }