public void ParseAndSetProperties(object props) { if (props == null) { return; } foreach (var property in _propertiesDigger.Get(props)) { SetProperty(property.PropertyName, property.Value, property.PropertyNameSource); } }
/// <summary> /// Creates an instance of <see cref="MixpanelClient"/>. This constructor is usually used /// when you want to call only 'Send' and 'SendAsync' methods, because in this case /// token is already specified in each <see cref="MixpanelMessage"/>. /// </summary> /// <param name="config"> /// Configuration for this particular client. Set properties from this class will override global properties. /// </param> /// <param name="superProperties"> /// Object with properties that will be attached to every message for the current mixpanel client. /// If some of the properties are not valid mixpanel properties they will be ignored. Check documentation /// on project page https://github.com/eealeivan/mixpanel-csharp for valid property types. /// </param> public MixpanelClient(MixpanelConfig config = null, object superProperties = null) { this.config = config; UtcNow = () => DateTime.UtcNow; // Parse super properties only one time this.superProperties = PropertiesDigger.Get(superProperties, PropertyOrigin.SuperProperty).ToList(); }
private void ProcessRawProperties(object rawProperties) { if (rawProperties == null) { return; } foreach (ObjectProperty objectProperty in PropertiesDigger.Get(rawProperties, PropertyOrigin.RawProperty)) { ProcessObjectProperty(objectProperty); } }
public void Given_Class_When_MixpanelNameAndDataMemberAttributes_Then_MixpanelNameUsed() { var obj = new Class5 { DecimalProperty = DecimalPropertyValue2, }; var properties = PropertiesDigger.Get(obj, PropertyOrigin.RawProperty).ToArray(); Assert.That(properties.Count, Is.EqualTo(1)); CheckProperty( DecimalPropertyName2, PropertyNameSource.MixpanelName, DecimalPropertyValue2, properties); }
public void Given_StringObjectDic_When_ValidInput_Then_AllParsed() { var dic = new Dictionary <string, object> { { DecimalPropertyName, DecimalPropertyValue }, { StringPropertyName, StringPropertyValue }, { DateTimePropertyName, DateTimePropertyValue } }; var properties = PropertiesDigger.Get(dic, PropertyOrigin.RawProperty).ToArray(); CheckProperties(properties); }
public void Given_Class_When_ValidInput_Then_AllParsed() { var obj = new Class1 { DecimalProperty = DecimalPropertyValue, StringProperty = StringPropertyValue, DateTimeProperty = DateTimePropertyValue }; var properties = PropertiesDigger.Get(obj, PropertyOrigin.RawProperty).ToArray(); CheckProperties(properties); }
public void Given_ExpandoObject_When_ValidInput_Then_AllParsed() { dynamic expando = new ExpandoObject(); expando.DecimalProperty = DecimalPropertyValue; expando.StringProperty = StringPropertyValue; expando.DateTimeProperty = DateTimePropertyValue; var properties = ((IEnumerable <ObjectProperty>)PropertiesDigger.Get(expando, PropertyOrigin.RawProperty)) .ToArray(); CheckProperties(properties); }
public void Given_Hashtable_When_MixedInput_Then_OnlyValidParsed() { var hashtable = new Hashtable { { 1, IntPropertyValue }, { DecimalPropertyName, DecimalPropertyValue }, { StringPropertyName, StringPropertyValue }, { DateTimePropertyName, DateTimePropertyValue } }; var properties = PropertiesDigger.Get(hashtable, PropertyOrigin.RawProperty).ToArray(); CheckProperties(properties); }
public void Given_Dynamic_When_ValidInput_Then_AllParsed() { dynamic dyn = new { DecimalProperty = DecimalPropertyValue, StringProperty = StringPropertyValue, DateTimeProperty = DateTimePropertyValue }; var properties = ((IEnumerable <ObjectProperty>)PropertiesDigger.Get(dyn, PropertyOrigin.RawProperty)) .ToArray(); CheckProperties(properties); }
public void Given_StringDecimalDic_When_ValidInput_Then_AllParsed() { var dic = new Dictionary <string, decimal> { { DecimalPropertyName, DecimalPropertyValue }, { DecimalPropertyName2, DecimalPropertyValue2 } }; var properties = PropertiesDigger.Get(dic, PropertyOrigin.RawProperty).ToArray(); Assert.That(properties.Count, Is.EqualTo(2)); CheckProperty(DecimalPropertyName, PropertyNameSource.Default, DecimalPropertyValue, properties); CheckProperty(DecimalPropertyName2, PropertyNameSource.Default, DecimalPropertyValue2, properties); }
public void Given_Class_When_DataContractAttribute_Then_DataMemberParsed() { var obj = new Class3 { DecimalProperty = DecimalPropertyValue2, StringProperty = StringPropertyValue2, DateTimeProperty = DateTimePropertyValue, IgnoredProperty = StringPropertyValue }; var properties = PropertiesDigger.Get(obj, PropertyOrigin.RawProperty).ToArray(); Assert.That(properties.Count, Is.EqualTo(1)); CheckProperty(StringPropertyName2, PropertyNameSource.DataMember, StringPropertyValue2, properties); }
public void Given_Class_When_MixpanelNameAttribute_Then_MixpanelNameUsed() { var obj = new Class2 { DecimalProperty = DecimalPropertyValue2, StringProperty = StringPropertyValue2, DateTimeProperty = DateTimePropertyValue }; var properties = PropertiesDigger.Get(obj, PropertyOrigin.RawProperty).ToArray(); Assert.That(properties.Count, Is.EqualTo(3)); CheckProperty( DecimalPropertyName2, PropertyNameSource.MixpanelName, DecimalPropertyValue2, properties); CheckProperty( StringPropertyName2, PropertyNameSource.MixpanelName, StringPropertyValue2, properties); CheckProperty( DateTimePropertyName, PropertyNameSource.Default, DateTimePropertyValue, properties); }
public void Get_StringKeyObjectValueDictionary_Parsed() { var dic = new Dictionary <string, object> { { DecimalPropertyName, DecimalPropertyValue }, { StringPropertyName, StringPropertyValue }, { DateTimePropertyName, DateTimePropertyValue } }; var properties = _digger.Get(dic); CheckProperties(properties); }