Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using custom properties dynamically #111

Open
jancisl1 opened this issue May 20, 2021 · 0 comments
Open

Using custom properties dynamically #111

jancisl1 opened this issue May 20, 2021 · 0 comments

Comments

@jancisl1
Copy link

jancisl1 commented May 20, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant