Skip to content

Using custom properties dynamically #111

Description

@jancisl1

Hi,
I'm new to github community, I don't how these things should be properly addresed, but I really needed to use custom properties dynamically for contacts, but didn't know how, so I searched through source code and found
in PropertyTransport class, that there was a code for this but it's buggy.

In "\Api\Shared\PropertyTransportModel.cs", there is this method "ToPropertyTransportModel" which is used to add properties to request body

Starting from line 35

    else if(typeof(IEnumerable<>).IsAssignableFrom(prop.PropertyType) && typeof(PropertyValuePair).IsAssignableFrom(prop.PropertyType.GetElementType()))             
               {
                   IEnumerable<PropertyValuePair> pairs = value as IEnumerable<PropertyValuePair>;
                   foreach (var item in pairs)
                   {
                       Properties.Add(item);
                   }
                    continue;
              }

So if you are extending ContactHubSpotModel with this kind of property, you should be able to put there you're custom properties

[DataMember(Name ="CustomProperties")]
[IgnoreDataMember]
public List<PropertyValuePair> CustomProperties { get; set; } = new List<PropertyValuePair>();

But it doesn't work, because of the buggy if-statement. When I changed it to this, it it worked.

 else if(
              (
                   typeof(IEnumerable<>).IsAssignableFrom(prop.PropertyType) 
                   && typeof(PropertyValuePair).IsAssignableFrom(prop.PropertyType.GetElementType())
              )
             || typeof(IEnumerable<PropertyValuePair>).IsAssignableFrom(prop.PropertyType)
       )

Do I understand correctly how this should be used? Is there a better way to user properties dynamically? Maybe this fix needs to be implemented?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions