Exemple #1
0
 public ObjectProperty(
     string propertyName, PropertyNameSource propertyNameSource, object value)
     : this()
 {
     PropertyName       = propertyName;
     PropertyNameSource = propertyNameSource;
     Value = value;
 }
Exemple #2
0
 public ObjectPropertyInfo(
     string propertyName, PropertyNameSource propertyNameSource, PropertyInfo propertyInfo)
     : this()
 {
     PropertyName       = propertyName;
     PropertyNameSource = propertyNameSource;
     PropertyInfo       = propertyInfo;
 }
 public ObjectPropertyInfo(
     string propertyName, PropertyNameSource propertyNameSource, PropertyInfo propertyInfo)
     : this()
 {
     PropertyName = propertyName;
     PropertyNameSource = propertyNameSource;
     PropertyInfo = propertyInfo;
 }
 public ObjectProperty(
     string propertyName, PropertyNameSource propertyNameSource, object value)
     : this()
 {
     PropertyName = propertyName;
     PropertyNameSource = propertyNameSource;
     Value = value;
 }
Exemple #5
0
        private void CheckProperty(
            string name, PropertyNameSource source, object value, IList <ObjectProperty> properties)
        {
            var decimalProperty = GetProperty(name, properties);

            Assert.That(decimalProperty.PropertyNameSource, Is.EqualTo(source));
            Assert.That(decimalProperty.Value, Is.EqualTo(value));
        }
        public bool SetPropertyIfNotNull(string propertyName, object value,
                                         PropertyNameSource propertyNameSource = PropertyNameSource.Default)
        {
            if (value == null)
            {
                return(false);
            }

            return(SetProperty(propertyName, value, propertyNameSource));
        }
 public ObjectProperty(
     string propertyName,
     PropertyNameSource propertyNameSource,
     PropertyOrigin origin,
     object value)
 {
     PropertyName       = propertyName;
     PropertyNameSource = propertyNameSource;
     Origin             = origin;
     Value = value;
 }
        private void CheckProperty(
            string name,
            PropertyNameSource source,
            object value,
            ObjectProperty[] properties)
        {
            var objectProperty = GetProperty(name, properties);

            Assert.That(objectProperty.PropertyNameSource, Is.EqualTo(source));
            Assert.That(objectProperty.Value, Is.EqualTo(value));
        }
        public static string Format(
            string propertyName,
            PropertyNameSource propertyNameSource,
            MixpanelConfig config = null)
        {
            MixpanelPropertyNameFormat propertyNameFormat =
                ConfigHelper.GetMixpanelPropertyNameFormat(config);

            if (propertyNameFormat == MixpanelPropertyNameFormat.None ||
                propertyNameSource != PropertyNameSource.Default)
            {
                return(propertyName);
            }

            bool sentenceCase = propertyNameFormat == MixpanelPropertyNameFormat.SentenceCase;
            bool titleCase    = propertyNameFormat == MixpanelPropertyNameFormat.TitleCase;
            bool lowerCase    = propertyNameFormat == MixpanelPropertyNameFormat.LowerCase;

            var newName = new StringBuilder(propertyName.Length + 5);

            var firstLetter = propertyName[0];

            if ((sentenceCase || titleCase) && !char.IsUpper(firstLetter))
            {
                firstLetter = char.ToUpper(firstLetter);
            }
            else if (lowerCase && !char.IsLower(firstLetter))
            {
                firstLetter = char.ToLower(firstLetter);
            }
            newName.Append(firstLetter);

            for (int i = 1; i < propertyName.Length; i++)
            {
                var letter = propertyName[i];
                if (char.IsUpper(letter))
                {
                    // Do not add space if previous letter is space
                    if (propertyName[i - 1] != ' ')
                    {
                        newName.Append(' ');
                    }

                    if (sentenceCase || lowerCase)
                    {
                        letter = char.ToLower(letter);
                    }
                }
                newName.Append(letter);
            }

            return(newName.ToString());
        }
        public string Format(string propName, PropertyNameSource propertyNameSource = PropertyNameSource.Default)
        {
            Debug.Assert(!propName.IsNullOrWhiteSpace());

            var propertyNameFormat = _config != null
                ? _config.MixpanelPropertyNameFormat
                : MixpanelConfig.Global.MixpanelPropertyNameFormat;

            if (propertyNameFormat == MixpanelPropertyNameFormat.None ||
                propertyNameSource != PropertyNameSource.Default)
            {
                return(propName);
            }

            bool sentenseCase = propertyNameFormat == MixpanelPropertyNameFormat.SentenceCase;
            bool titleCase    = propertyNameFormat == MixpanelPropertyNameFormat.TitleCase;
            bool lowerCase    = propertyNameFormat == MixpanelPropertyNameFormat.LowerCase;

            var newName = new StringBuilder(propName.Length + 5);

            var firstLetter = propName[0];

            if ((sentenseCase || titleCase) && !char.IsUpper(firstLetter))
            {
                firstLetter = char.ToUpper(firstLetter);
            }
            else if (lowerCase && !char.IsLower(firstLetter))
            {
                firstLetter = char.ToLower(firstLetter);
            }
            newName.Append(firstLetter);

            for (int i = 1; i < propName.Length; i++)
            {
                var letter = propName[i];
                if (char.IsUpper(letter))
                {
                    // Do not add space if previous letter is space
                    if (propName[i - 1] != ' ')
                    {
                        newName.Append(' ');
                    }

                    if (sentenseCase || lowerCase)
                    {
                        letter = char.ToLower(letter);
                    }
                }
                newName.Append(letter);
            }

            return(newName.ToString());
        }
        public string Format(string propName, PropertyNameSource propertyNameSource = PropertyNameSource.Default)
        {
            Debug.Assert(!propName.IsNullOrWhiteSpace());

            var propertyNameFormat = _config != null
                ? _config.MixpanelPropertyNameFormat
                : MixpanelConfig.Global.MixpanelPropertyNameFormat;

            if (propertyNameFormat == MixpanelPropertyNameFormat.None ||
                propertyNameSource != PropertyNameSource.Default)
            {
                return propName;
            }

            bool sentenseCase = propertyNameFormat == MixpanelPropertyNameFormat.SentenceCase;
            bool titleCase = propertyNameFormat == MixpanelPropertyNameFormat.TitleCase;
            bool lowerCase = propertyNameFormat == MixpanelPropertyNameFormat.LowerCase;

            var newName = new StringBuilder(propName.Length + 5);

            var firstLetter = propName[0];
            if ((sentenseCase || titleCase) && !char.IsUpper(firstLetter))
            {
                firstLetter = char.ToUpper(firstLetter);
            }
            else if(lowerCase && !char.IsLower(firstLetter))
            {
                firstLetter = char.ToLower(firstLetter);
            }
            newName.Append(firstLetter);

            for (int i = 1; i < propName.Length; i++)
            {
                var letter = propName[i];
                if (char.IsUpper(letter))
                {
                    // Do not add space if previous letter is space
                    if (propName[i - 1] != ' ')
                    {
                        newName.Append(' ');
                    }

                    if (sentenseCase || lowerCase)
                    {
                        letter = char.ToLower(letter);
                    }
                }
                newName.Append(letter);
            }

            return newName.ToString();
        }
        public void RemoveProperty(string propertyName,
                                   PropertyNameSource propertyNameSource = PropertyNameSource.Default)
        {
            if (propertyName.IsNullOrWhiteSpace())
            {
                return;
            }

            if (!SpecialProps.Remove(propertyName))
            {
                Props.Remove(_nameFormatter.Format(propertyName, propertyNameSource));
            }
        }
        public bool SetProperty(string propertyName, object value,
                                PropertyNameSource propertyNameSource = PropertyNameSource.Default)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                return(false);
            }

            var parsedProperty = _valueParser.Parse(value);

            if (!parsedProperty.IsValid)
            {
                return(false);
            }

            string bindingProp;

            if (_specialPropsBindings.TryGetValue(propertyName.ToLower(), out bindingProp))
            {
                SpecialProps[bindingProp] = parsedProperty.Value;
            }
            else
            {
                switch (_messagePropetiesRules)
                {
                case MessagePropetiesRules.None:
                    break;

                case MessagePropetiesRules.NumericsOnly:
                    if (!_valueParser.IsNumeric(parsedProperty.Value))
                    {
                        return(false);
                    }
                    break;

                case MessagePropetiesRules.ListsOnly:
                    if (!_valueParser.IsEnumerable(parsedProperty.Value))
                    {
                        return(false);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Props[_nameFormatter.Format(propertyName, propertyNameSource)] = parsedProperty.Value;
            }

            return(true);
        }
 public ObjectProperty(PropertyNameSource propertyNameSource, object value)
     : this()
 {
     PropertyNameSource = propertyNameSource;
     Value = value;
 }
 private void CheckProperty(
     string name, PropertyNameSource source, object value, IList<ObjectProperty> properties)
 {
     var decimalProperty = GetProperty(name, properties);
     Assert.That(decimalProperty.PropertyNameSource, Is.EqualTo(source));
     Assert.That(decimalProperty.Value, Is.EqualTo(value));
 }
        public bool SetPropertyIfNotNull(string propertyName, object value,
            PropertyNameSource propertyNameSource = PropertyNameSource.Default)
        {
            if (value == null)
            {
                return false;
            }

            return SetProperty(propertyName, value, propertyNameSource);
        }
        public bool SetProperty(string propertyName, object value,
            PropertyNameSource propertyNameSource = PropertyNameSource.Default)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                return false;
            }

            var parsedProperty = _valueParser.Parse(value);
            if (!parsedProperty.IsValid)
            {
                return false;
            }

            string bindingProp;
            if (_specialPropsBindings.TryGetValue(propertyName.ToLower(), out bindingProp))
            {
                SpecialProps[bindingProp] = parsedProperty.Value;
            }
            else
            {
                switch (_messagePropetiesRules)
                {
                    case MessagePropetiesRules.None:
                        break;
                    case MessagePropetiesRules.NumericsOnly:
                        if (!_valueParser.IsNumeric(parsedProperty.Value))
                        {
                            return false;
                        }
                        break;
                    case MessagePropetiesRules.ListsOnly:
                        if (!_valueParser.IsEnumerable(parsedProperty.Value))
                        {
                            return false;
                        }
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                Props[_nameFormatter.Format(propertyName, propertyNameSource)] = parsedProperty.Value;
            }

            return true;
        }
        public void RemoveProperty(string propertyName,
            PropertyNameSource propertyNameSource = PropertyNameSource.Default)
        {
            if (propertyName.IsNullOrWhiteSpace())
            {
                return;
            }

            if (!SpecialProps.Remove(propertyName))
            {
                Props.Remove(_nameFormatter.Format(propertyName, propertyNameSource));
            }
        }