예제 #1
0
        public override Style EvaluateCondition(object item)
        {
            var comparisoncompPropReflection = new FastReflectionHelper()
            {
                PropertyName = this.ValueMemberPath
            };
            object comparisonPropValue = comparisoncompPropReflection.GetPropertyValue(item);

            var selectionPropReflection = new FastReflectionHelper()
            {
                PropertyName = this.SelectionMemberPath
            };
            object selectionPropValue = selectionPropReflection.GetPropertyValue(item);

            if (this.EvaluateConditionAgainstPropertyValue(comparisonPropValue))
            {
                if (this.EvaluateSelectionAgainstPropertyValue(selectionPropValue))
                {
                    return(this.SelectedStyle);
                }
                else
                {
                    return(this.DeSelectedStyle);
                }
            }
            return(null);
        }
예제 #2
0
        public void RegisterIdentitiesFromAssembly(Assembly assembly)
        {
            var sb = new StringBuilder();

            foreach (var ic in assembly.GetTypes().Where(x => typeof(IIdentity).IsAssignableFrom(x) && !x.IsAbstract && x.IsClass))
            {
                var tag = EventStoreIdentity.GetTagForIdentityClass(ic);

                {
                    var ctor = ic.Constructor(new Type[] { typeof(long) });
                    if (ctor == null)
                    {
                        var message = String.Format("Identity {0} must have the constructor {1}(long id)\n", ic.FullName, ic.Name);
                        Logger.Error(message);
                        sb.AppendFormat(message);
                        continue; //move to the next type, or everythign will crash.
                    }
                    var activator = FastReflectionHelper.GetActivator(ctor);

                    _longBasedFactories[tag] = (id) => (IIdentity)activator(new object[] { id });
                }
            }

            var errors = sb.ToString();

            if (!String.IsNullOrWhiteSpace(errors))
            {
                throw new JarvisFrameworkEngineException("Found identities with errors:\n" + errors);
            }
        }
        public override Style EvaluateCondition(object item)
        {
            var frh = new FastReflectionHelper {
                PropertyName = this.ValueMemberPath
            };
            object propertyValue = frh.GetPropertyValue(item);

            if (this.EvaluateConditionAgainstPropertyValue(propertyValue))
            {
                return(this.StyleToApply);
            }
            return(null);
        }
예제 #4
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            var nominalType = typeof(T);

            FastReflectionHelper.ObjectActivator activator;
            if (!_activators.TryGetValue(nominalType, out activator))
            {
                var ctor = nominalType.Constructor(new Type[] { typeof(string) });
                activator = FastReflectionHelper.GetActivator(ctor);
                _activators[nominalType] = activator;
            }
            return(activator(new object[] { (string)value }));
        }
예제 #5
0
        public override Style EvaluateCondition(object item)
        {
            var reflection = new FastReflectionHelper {
                PropertyName = this.ValueMemberPath
            };
            object propertyValue = reflection.GetPropertyValue(item);

            if (this.EvaluateConditionAgainstPropertyValue(propertyValue))
            {
                return(this.ValueTrueStyle);
            }
            return(ValueFalseStyle);
        }
예제 #6
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.String)
            {
                FastReflectionHelper.ObjectActivator activator;
                if (!_activators.TryGetValue(objectType, out activator))
                {
                    var ctor = objectType.Constructor(new Type[] { typeof(string) });
                    activator = FastReflectionHelper.GetActivator(ctor);
                    _activators[objectType] = activator;
                }

                var typedId = activator(new object[] { Convert.ToString((object)reader.Value) });
                return(typedId);
            }
            return(null);
        }
        private void AddGroup(
            List <ISectionInformation> groupInformation,
            List <string> groupNames, string[] groupNamesArray,
            int currentIndex, object group, string groupingField)
        {
            List <object> groupValues = new List <object>();

            foreach (var name in groupNames)
            {
                FastReflectionHelper helper;
                if (!_groupHelpers.TryGetValue(name, out helper))
                {
                    helper = new FastReflectionHelper();
                    helper.PropertyName = name;
                    _groupHelpers[name] = helper;
                }

                var val = helper.GetPropertyValue(group);
                groupValues.Add(val);
            }
            var groupCount = 0;

            FastReflectionHelper countHelper;

            if (!_groupHelpers.TryGetValue(groupingField, out countHelper))
            {
                countHelper = new FastReflectionHelper();
                countHelper.PropertyName     = groupingField;
                _groupHelpers[groupingField] = countHelper;
            }

            var countVal = countHelper.GetPropertyValue(group);

            if (countVal != null)
            {
                groupCount = Convert.ToInt32(countVal);
            }
            DefaultSectionInformation groupInfo = new DefaultSectionInformation(
                currentIndex,
                currentIndex + (groupCount - 1),
                groupNamesArray,
                groupValues.ToArray());

            groupInformation.Add(groupInfo);
        }
예제 #8
0
        public object Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            if (context.Reader.CurrentBsonType == BsonType.Null)
            {
                context.Reader.ReadNull();
                return(null);
            }

            var id = context.Reader.ReadString();

            FastReflectionHelper.ObjectActivator activator;
            if (!_activators.TryGetValue(args.NominalType, out activator))
            {
                var ctor = args.NominalType.Constructor(new Type[] { typeof(string) });
                activator = FastReflectionHelper.GetActivator(ctor);
                _activators[args.NominalType] = activator;
            }
            return(activator(new object[] { id }));
        }