public void GetRuntimeFields()
        {
            var types = GetTypes();

            Assert.Throws <ArgumentNullException>(() =>
            {
                RuntimeReflectionExtensions.GetRuntimeFields(null);
            });

            List <string> fields = new List <string>();

            foreach (TypeInfo type in types)
            {
                if (!type.Namespace.Equals("FieldDefinitions", StringComparison.Ordinal))
                {
                    continue;
                }

                fields.Clear();
                fields.AddRange((IEnumerable <string>)type.GetDeclaredField("DeclaredFieldNames").GetValue(null));
                fields.AddRange((IEnumerable <string>)type.GetDeclaredField("InheritedFieldNames").GetValue(null));
                if (type.GetDeclaredField("NewFieldNames") != null)
                {
                    fields.AddRange((IEnumerable <string>)type.GetDeclaredField("NewFieldNames").GetValue(null));
                }

                Assert.All(type.AsType().GetRuntimeFields(), f => Assert.True(fields.Remove(f.Name)));
                Assert.Empty(fields);
            }
        }
Ejemplo n.º 2
0
        public static IEnumerable <FieldInfo> GetRuntimeFields(this Type type)
        {
#if UNITY_METRO && !UNITY_EDITOR
            return(RuntimeReflectionExtensions.GetRuntimeFields(type));
#else
            return(type.GetFields());
#endif
        }
 public static IEnumerable <MemberInfo> GetMembersInHierarchy(this Type type)
 {
     do
     {
         foreach (PropertyInfo item in from pi in RuntimeReflectionExtensions.GetRuntimeProperties(type)
                  where !(pi.GetMethod ?? pi.SetMethod).IsStatic
                  select pi)
         {
             yield return(item);
         }
         foreach (FieldInfo item2 in from f in RuntimeReflectionExtensions.GetRuntimeFields(type)
                  where !f.IsStatic
                  select f)
         {
             yield return(item2);
         }
         type = type.BaseType;
     }while (type != null);
 }
Ejemplo n.º 4
0
        public void GetRuntimeFields()
        {
            var types = GetTypes();

            Assert.Throws <ArgumentNullException>(() =>
            {
                RuntimeReflectionExtensions.GetRuntimeFields(null);
            });

            List <String> fields = new List <String>();

            foreach (TypeInfo type in types)
            {
                if (!type.Namespace.Equals("FieldDefinitions", StringComparison.Ordinal))
                {
                    continue;
                }

                fields.Clear();
                fields.AddRange((IEnumerable <String>)type.GetDeclaredField("DeclaredFieldNames").GetValue(null));
                fields.AddRange((IEnumerable <String>)type.GetDeclaredField("InheritedFieldNames").GetValue(null));
                if (type.GetDeclaredField("NewFieldNames") != null)
                {
                    fields.AddRange((IEnumerable <String>)type.GetDeclaredField("NewFieldNames").GetValue(null));
                }

                foreach (FieldInfo fi in type.AsType().GetRuntimeFields())
                {
                    if (fields.Remove(fi.Name))
                    {
                        continue;
                    }

                    Assert.False(true, String.Format("Type: {0}, Field: {1} is not expected", type, fi));
                }

                foreach (String fieldName in fields)
                {
                    Assert.False(true, String.Format("Field: {0} cannot be found", fieldName));
                }
            }
        }
Ejemplo n.º 5
0
 static FieldInfo[] GetFields(Type type)
 {
     return(Enumerable.ToArray <FieldInfo>(RuntimeReflectionExtensions.GetRuntimeFields(type)));
 }