Example #1
0
 /// <summary>
 /// Create instance and add to the configuration.
 /// If <param name="harvester"/> is null, use the <see cref="AllFieldsAndPropertiesHarvester"/> to harvest the fields.
 /// </summary>
 public ProjectionHarvester(
     Configuration configuration = null,
     IFieldHarvester harvester   = null)
 {
     if (configuration != null)
     {
         configuration.Add(this);
     }
     harvestingStrategy = harvester ?? new AllFieldsAndPropertiesHarvester();
 }
        /// <summary>
        /// Add a handler. Adding will override the existing behaviour only when the
        /// added handler handles a type that is already handleable by the current configuration.
        /// </summary>
        public Configuration Add(IFieldHarvester handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            fieldHarvesters.Push(handler);
            return(this);
        }
        static void Asserts(ProjectionHarvester harvester)
        {
            IFieldHarvester fh = (IFieldHarvester)harvester;

            Assert.IsTrue(fh.CanHandleType(typeof(A)));
            var fields = fh.GetFields(typeof(A)).Select(x => x.SanitizedName);

            CollectionAssert.AreEquivalent(new[] { "Name" }, fields);

            Assert.IsTrue(fh.CanHandleType(typeof(B)));
            fields = fh.GetFields(typeof(B)).Select(x => x.SanitizedName);
            CollectionAssert.AreEquivalent(new[] { "Name", "Age" }, fields);

            Assert.IsFalse(fh.CanHandleType(typeof(C)));
        }
            public void Include_Fieldsarr_WorksForTypesAndSubtypes()
            {
                var harvester = new ProjectionHarvester();

                harvester.Include <B>(x => x.Name, x => x.Age);

                IFieldHarvester fh = (IFieldHarvester)harvester;

                Assert.IsFalse(fh.CanHandleType(typeof(A)));
                Assert.IsTrue(fh.CanHandleType(typeof(B)));
                var fields = fh.GetFields(typeof(B)).Select(x => x.SanitizedName);

                CollectionAssert.AreEquivalent(new[] { "Name", "Age" }, fields);

                Assert.IsFalse(fh.CanHandleType(typeof(C)));
            }
Example #5
0
            public void Exclude_FieldInSuperclass_WorksForTypesAndSubtypes()
            {
                var harvester = new SelectiveHarvester();

                harvester.Exclude <B>(x => x.Name);

                IFieldHarvester fh = (IFieldHarvester)harvester;

                Assert.IsFalse(fh.CanHandleType(typeof(A)));

                Assert.IsTrue(fh.CanHandleType(typeof(B)));
                var fields = fh.GetFields(typeof(B)).Select(x => x.SanitizedName);

                CollectionAssert.AreEquivalent(new[] { "X", "Y", "Age" }, fields);

                Assert.IsFalse(fh.CanHandleType(typeof(C)));
            }
Example #6
0
 /// <summary>
 /// Add a configuration. Adding will override the existing behaviour only when the
 /// added handler handles a type that is already handlable by the current configuration.
 /// </summary>
 public void Add(IFieldHarvester handler)
 {
     fieldHarvesters.Insert(0, handler);
 }
Example #7
0
 /// <summary>
 /// Find a handler for the type. Handlers are examined in the reverse order of adding and the first match is returned.
 /// </summary>
 public bool TryGetFieldHarvester(Type source, out IFieldHarvester result)
 {
     result = fieldHarvesters.FirstOrDefault(x => x.CanHandleType(source));
     return(result != null);
 }
 /// <summary>
 /// Add a configuration. Adding will override the existing behaviour only when the
 /// added handler handles a type that is already handleable by the current configuration.
 /// </summary>
 public Configuration Add(IFieldHarvester handler)
 {
     fieldHarvesters.Insert(0, handler);
     return(this);
 }
Example #9
0
 /// <summary>
 /// Find a handler for the type. Handlers are examined in the reverse order of adding and the first match is returned.
 /// </summary>
 public bool TryGetFieldHarvester(Type source, out IFieldHarvester result)
 {
     result = fieldHarvesters.FirstOrDefault(x => x.CanHandleType(source));
     return result != null;
 }
Example #10
0
        /// <summary>
        /// Add a configuration. Adding will override the existing behaviour only when the
        /// added handler handles a type that is already handleable by the current configuration.
        /// </summary>
        public Configuration Add(IFieldHarvester handler)
        {
            if (handler == null)
                throw new ArgumentNullException("handler");

            fieldHarvesters.Push(handler);
            return this;
        }
Example #11
0
 /// <summary>
 /// Add a configuration. Adding will override the existing behaviour only when the
 /// added handler handles a type that is already handleable by the current configuration.
 /// </summary>
 public Configuration Add(IFieldHarvester handler)
 {
     fieldHarvesters.Push(handler);
     return(this);
 }
Example #12
0
 /// <summary>
 /// Add a configuration. Adding will override the existing behaviour only when the 
 /// added handler handles a type that is already handlable by the current configuration.
 /// </summary>
 public void Add(IFieldHarvester handler)
 {
   fieldHarvesters.Insert(0, handler);
 }
Example #13
0
 /// <summary>
 /// Create instance and add to the configuration.
 /// </summary>
 public ProjectionHarvester(IFieldHarvester harvester)
     : this(null, harvester)
 {
 }