Esempio n. 1
0
        private static MemberInfo[] BuildPublicAccessors(IEnumerable <MemberInfo> allMembers)
        {
            // Multiple types may define the same property (e.g. the class and multiple interfaces) - filter this to one of those properties
            var filteredMembers = allMembers
                                  .OfType <PropertyInfo>()
                                  .GroupBy(x => x.Name) // group properties of the same name together
                                  .Select(x =>
                                          x.Any(y => y.CanWrite && y.CanRead)
                        ? // favor the first property that can both read & write - otherwise pick the first one
                                          x.First(y => y.CanWrite && y.CanRead)
                        : x.First())
                                  .Where(pi => pi.CanWrite || PrimitiveExtensions.IsListOrDictionaryType(pi.PropertyType))
                                  .OfType <MemberInfo>()                          // cast back to MemberInfo so we can add back FieldInfo objects
                                  .Concat(allMembers.Where(x => x is FieldInfo)); // add FieldInfo objects back

            return(filteredMembers.ToArray());
        }