コード例 #1
0
ファイル: ReflectionHelper.cs プロジェクト: mmvlad/ecs
        public static System.Reflection.MemberInfo[] GetCachedFields(this System.Type type,
                                                                     System.Reflection.BindingFlags flags =
                                                                     System.Reflection.BindingFlags.Instance |
                                                                     System.Reflection.BindingFlags.Public |
                                                                     System.Reflection.BindingFlags.NonPublic)
        {
            if (ReflectionHelper.fieldInfoCache.TryGetValue(type, out var fieldInfos) == false)
            {
                var fieldInfosArr = Enumerable.Cast <System.Reflection.MemberInfo>(Enumerable.Where(type.GetAllFields(flags), f =>
                                                                                                    f.IsPublic == true ||
                                                                                                    Enumerable.Any(f.CustomAttributes, a => a.AttributeType == typeof(ME.ECS.Serializer.SerializeFieldAttribute)) == true));
                fieldInfosArr = Enumerable.Union(fieldInfosArr, Enumerable.Where(type.GetAllProperties(flags), f =>
                                                                                 f.CanRead == true &&
                                                                                 f.CanWrite == true &&
                                                                                 Enumerable.Any(f.CustomAttributes, a => a.AttributeType == typeof(ME.ECS.Serializer.SerializeFieldAttribute))
                                                                                 )
                                                 );

                fieldInfos = Enumerable.ToArray(Enumerable.OrderBy(fieldInfosArr, x => x.Name));
                ReflectionHelper.fieldInfoCache.Add(type, fieldInfos);
            }

            return(fieldInfos);
        }