Пример #1
0
        private static void GetChildPrivateFields(IList <MemberInfo> initialFields, Type targetType, BindingFlags bindingAttr)
        {
            // fix weirdness with private FieldInfos only being returned for the current Type
            // find base type fields and add them to result
            if ((bindingAttr & BindingFlags.NonPublic) != 0)
            {
                // modify flags to not search for public fields
                BindingFlags nonPublicBindingAttr = bindingAttr.RemoveFlag(BindingFlags.Public);

                while ((targetType = targetType.BaseType()) != null)
                {
                    // filter out protected fields
                    IEnumerable <FieldInfo> childPrivateFields =
                        targetType.GetFields(nonPublicBindingAttr).Where(f => f.IsPrivate);

                    initialFields.AddRange(childPrivateFields);
                }
            }
        }
Пример #2
0
        private static void GetChildPrivateFields(
            IList <MemberInfo> initialFields,
            Type targetType,
            BindingFlags bindingAttr)
        {
            if ((bindingAttr & BindingFlags.NonPublic) == BindingFlags.Default)
            {
                return;
            }
            BindingFlags bindingAttr1 = bindingAttr.RemoveFlag(BindingFlags.Public);

            while ((targetType = targetType.BaseType()) != null)
            {
                IEnumerable <FieldInfo> fieldInfos =
                    ((IEnumerable <FieldInfo>)targetType.GetFields(bindingAttr1)).Where <FieldInfo>(
                        (Func <FieldInfo, bool>)(f => f.IsPrivate));
                initialFields.AddRange <MemberInfo>((IEnumerable)fieldInfos);
            }
        }
Пример #3
0
 private static void GetChildPrivateFields(IList <MemberInfo> initialFields, Type targetType, BindingFlags bindingAttr)
 {
     if ((bindingAttr & BindingFlags.NonPublic) != BindingFlags.Default)
     {
         BindingFlags bindingFlag = bindingAttr.RemoveFlag(BindingFlags.Public);
         while (true)
         {
             Type type = targetType.BaseType();
             targetType = type;
             if (type == null)
             {
                 break;
             }
             IEnumerable <FieldInfo> fields =
                 from f in (IEnumerable <FieldInfo>)targetType.GetFields(bindingFlag)
                 where f.IsPrivate
                 select f;
             initialFields.AddRange <MemberInfo>(fields);
         }
     }
 }
Пример #4
0
 private static void GetChildPrivateProperties(IList <PropertyInfo> initialProperties, Type targetType, BindingFlags bindingAttr)
 {
     if ((bindingAttr & BindingFlags.NonPublic) != 0)
     {
         BindingFlags bindingAttr2 = bindingAttr.RemoveFlag(BindingFlags.Public);
         while ((targetType = targetType.BaseType) != null)
         {
             PropertyInfo[] properties = targetType.GetProperties(bindingAttr2);
             foreach (PropertyInfo propertyInfo in properties)
             {
                 PropertyInfo nonPublicProperty = propertyInfo;
                 int          num = initialProperties.IndexOf((PropertyInfo p) => p.Name == nonPublicProperty.Name);
                 if (num == -1)
                 {
                     initialProperties.Add(nonPublicProperty);
                 }
                 else
                 {
                     initialProperties[num] = nonPublicProperty;
                 }
             }
         }
     }
 }