Exemple #1
0
 private void LoadFromKvp(IEnumerable <KeyValuePair <string, object> > expected)
 {
     foreach (var kvp in expected)
     {
         IMemberAccessor accessor  = MemberAccessors.PropertyOrField(kvp.Key);
         object          specified = kvp.Value;
         _items.Add(kvp.Key, new ExpectedAccessorData(
                        kvp.Key,
                        specified,
                        Matcher(specified),
                        accessor
                        ));
     }
 }
Exemple #2
0
 private void LoadFromObject(object expected, TestMemberFilter filter)
 {
     foreach (var f in filter.GetMembers(expected.GetType().GetTypeInfo()))
     {
         IMemberAccessor accessor;
         accessor = MemberAccessors.PropertyOrField(f);
         object specified = accessor.GetValue(expected);
         _items.Add(f.Name, new ExpectedAccessorData(
                        f.Name,
                        specified,
                        Matcher(specified),
                        accessor
                        ));
     }
 }
        private List <IMemberAccessor> FindAccessors()
        {
            var result = new List <IMemberAccessor>();
            var fields = _type.GetFields(BindingFlags.Public | BindingFlags.Instance);
            var props  = _type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            var all    = fields.Concat <MemberInfo>(props);

            foreach (var mem in all)
            {
                var attr   = mem.GetCustomAttribute <DebuggerBrowsableAttribute>();
                var access = MemberAccessors.PropertyOrField(mem);

                if (attr == null)
                {
                    result.Add(access);
                    continue;
                }

                switch (attr.State)
                {
                case DebuggerBrowsableState.Never:
                    break;

                case DebuggerBrowsableState.Collapsed:
                    result.Add(new CollapsedImpl(mem.Name));
                    break;

                case DebuggerBrowsableState.RootHidden:
                    IList <IMemberAccessor> accessors;
                    try {
                        accessors = DisplayActualSchema.Create(access.ReturnType).Accessors;
                    } catch (InvalidOperationException) {
                        // There was a circular dependency in the type dependency graph because
                        // we tried to resolve the factory value of a schema that is already in
                        // progress of being written.  Handle this by collapsing
                        result.Add(new CollapsedImpl(mem.Name));
                        break;
                    }
                    result.AddRange(
                        accessors.Select(a => HideRoot(access, a))
                        );
                    break;
                }
            }
            result.Sort((x, y) => x.Name.CompareTo(y.Name));
            return(result);
        }