Exemplo n.º 1
0
        /// <summary>
        /// Gets special Mixpanel property and throws <see cref="MixpanelObjectStructureException"/>
        /// if property is not set or <see cref="MixpanelRequiredPropertyNullOrEmptyException"/> if property
        /// value is null.
        /// </summary>
        /// <param name="propName">Name of the property.</param>
        /// <param name="validateFn">
        /// Custom validation function. Value will not be null. If it was null an exception
        /// will be thrown before.
        /// </param>
        /// <param name="convertFn">Custom value convert function.</param>
        public object GetSpecialRequiredProp(string propName,
                                             Action <object> validateFn = null, Func <object, object> convertFn = null)
        {
            object val;

            if (!SpecialProps.TryGetValue(propName, out val))
            {
                throw new MixpanelObjectStructureException(
                          string.Format("'{0}' property is not set.", propName));
            }

            if (val == null)
            {
                throw new MixpanelRequiredPropertyNullOrEmptyException(
                          string.Format("'{0}' property can't be null.", propName));
            }

            if (validateFn != null)
            {
                validateFn(val);
            }

            if (convertFn != null)
            {
                val = convertFn(val);
            }

            return(val);
        }
Exemplo n.º 2
0
        public void RemoveProperty(string propertyName,
                                   PropertyNameSource propertyNameSource = PropertyNameSource.Default)
        {
            if (propertyName.IsNullOrWhiteSpace())
            {
                return;
            }

            if (!SpecialProps.Remove(propertyName))
            {
                Props.Remove(_nameFormatter.Format(propertyName, propertyNameSource));
            }
        }
Exemplo n.º 3
0
        public object GetSpecialProp(string propName, Func <object, object> convertFn = null)
        {
            object val;

            if (!SpecialProps.TryGetValue(propName, out val))
            {
                return(null);
            }

            if (val != null && convertFn != null)
            {
                val = convertFn(val);
            }
            return(val);
        }
Exemplo n.º 4
0
 public void ClearAllProperties()
 {
     SpecialProps.Clear();
     Props.Clear();
 }