Esempio n. 1
0
        public void SetIdentityForOutput <T>(IList <T> entities, TableInfo tableInfo, object lastRowIdScalar)
        {
            long counter = (long)lastRowIdScalar;

            string       identityPropertyName = tableInfo.PropertyColumnNamesDict.SingleOrDefault(a => a.Value == tableInfo.IdentityColumnName).Key;
            FastProperty identityFastProperty = tableInfo.FastPropertyDict[identityPropertyName];

            string idTypeName = identityFastProperty.Property.PropertyType.Name;
            object idValue    = null;

            for (int i = entities.Count - 1; i >= 0; i--)
            {
                idValue = idTypeName switch
                {
                    "Int64" => counter, // long is default
                    "UInt64" => (ulong)counter,
                    "Int32" => (int)counter,
                    "UInt32" => (uint)counter,
                    "Int16" => (short)counter,
                    "UInt16" => (ushort)counter,
                    "Byte" => (byte)counter,
                    "SByte" => (sbyte)counter,
                    _ => counter,
                };
                identityFastProperty.Set(entities[i], idValue);
                counter--;
            }
        }
Esempio n. 2
0
        public TCounterCategory GetCounter <TCounterCategory>(string instance) where TCounterCategory : class, CounterCategory, new()
        {
            Type            t = typeof(TCounterCategory);
            CounterCategory value;

            if (_counterCache.TryGetValue(t, out value))
            {
                return((TCounterCategory)value);
            }

            //cache miss

            var cat          = new TCounterCategory();
            var categoryName = t.Name;
            var props        = t.GetProperties();


            foreach (var propertyInfo in props)
            {
                var fp = new FastProperty <TCounterCategory>(propertyInfo);
                fp.Set(cat, CreateCounter(categoryName, propertyInfo.Name, instance));
            }

            _counterCache.Add(t, cat);

            return(cat);
        }
        public void ApplyTo(Configuration cfg, UntypedChannel channel)
        {
            if (_types.Count == 0)
            {
                return;
            }

            PropertyInfo propertyInfo = _listenerAccessor.GetMemberPropertyInfo();
            var          property     = new FastProperty <EventListeners, TListener[]>(propertyInfo);

            TListener listener = _listenerFactory(channel, _types);

            TListener[] existing = property.Get(cfg.EventListeners);
            if (existing == null || existing.Length == 0)
            {
                property.Set(cfg.EventListeners, new[] { listener });
            }
            else
            {
                property.Set(cfg.EventListeners, existing.Concat(Enumerable.Repeat(listener, 1)).ToArray());
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a delegate saga repository that sets the designated property using the
        /// value returned by the value provider specified.
        /// </summary>
        /// <typeparam name="T1">The property type</typeparam>
        /// <param name="repository">The repository to decorate</param>
        /// <param name="propertyExpression">The property to set</param>
        /// <param name="valueProvider">The value provider for the property</param>
        /// <returns></returns>
        public static ISagaRepository <TSaga> Create <T1>(ISagaRepository <TSaga> repository,
                                                          Expression <Func <TSaga, T1> > propertyExpression,
                                                          Func <TSaga, T1> valueProvider)
        {
            var property = new FastProperty <TSaga, T1>(propertyExpression.GetMemberPropertyInfo(),
                                                        BindingFlags.NonPublic);

            return(new DelegatingSagaRepository <TSaga>(repository, saga =>
            {
                T1 value = valueProvider(saga);
                property.Set(saga, value);
            }));
        }
Esempio n. 5
0
        public void Should_be_able_to_access_a_private_setter()
        {
            PrivateSetter instance = new PrivateSetter();

            var property = instance.GetType()
                           .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                           .Where(x => x.Name == "Name")
                           .First();


            var fastProperty = new FastProperty <PrivateSetter>(property, BindingFlags.NonPublic);

            const string expectedValue = "Chris";

            fastProperty.Set(instance, expectedValue);

            Assert.AreEqual(expectedValue, fastProperty.Get(instance));
        }
Esempio n. 6
0
        /// <summary>
        /// Creates a delegate saga repository that sets the designated property using the
        /// value returned by the value provider specified.
        /// </summary>
        /// <typeparam name="T1">The property type</typeparam>
        /// <typeparam name="T2">The second property type</typeparam>
        /// <param name="repository">The repository to decorate</param>
        /// <param name="propertyExpression1">The first property to set</param>
        /// <param name="valueProvider1">The first property value provider</param>
        /// <param name="propertyExpression2">The second property to set</param>
        /// <param name="valueProvider2">The second value provider</param>
        /// <returns></returns>
        public static ISagaRepository <TSaga> Create <T1, T2>(ISagaRepository <TSaga> repository,
                                                              Expression <Func <TSaga, T1> > propertyExpression1,
                                                              Func <TSaga, T1> valueProvider1,
                                                              Expression <Func <TSaga, T2> > propertyExpression2,
                                                              Func <TSaga, T2> valueProvider2)
        {
            var property1 = new FastProperty <TSaga, T1>(propertyExpression1.GetMemberPropertyInfo(),
                                                         BindingFlags.NonPublic);
            var property2 = new FastProperty <TSaga, T2>(propertyExpression2.GetMemberPropertyInfo(),
                                                         BindingFlags.NonPublic);

            return(new DelegatingSagaRepository <TSaga>(repository, saga =>
            {
                T1 value = valueProvider1(saga);
                property1.Set(saga, value);

                T2 value2 = valueProvider2(saga);
                property2.Set(saga, value2);
            }));
        }
Esempio n. 7
0
        private void BindEventAction(int all, int i, FastProperty <T, int> property)
        {
            var e      = _sources[i];
            var eevent = BasicEvent <T> .GetEvent(e);

            var eventAction = new BasicEventAction <T>(eevent);

            int flag = 1 << i;

            eventAction.Then(x =>
            {
                int value = property.Get(x) | flag;
                property.Set(x, value);

                if (value == all)
                {
                    x.RaiseEvent(_target);
                }
            });

            _bindEventAction(eventAction);
        }
Esempio n. 8
0
 public void Set(TInstance instance, State state)
 {
     _property.Set(instance, state);
 }
Esempio n. 9
0
 public void Magnum_CompiledExpressionTrees()
 {
     fastProperty.Set(testUri, "Testing");
 }