Skip to content

Allow default values of Value Types to be send to docker API as query string parameters #312

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions src/Docker.DotNet/QueryString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public IDictionary<string, string[]> GetKeyValuePairs()
}

// Serialize
if (attribute.IsRequired || !IsDefaultOfType(value))
if (value != null)
{
var keyStr = attribute.Name;
string[] valueStr;
Expand Down Expand Up @@ -113,16 +113,6 @@ private Tuple<PropertyInfo, TAttribType>[] FindAttributedPublicProperties<TValue
return attributedPublicProperties.Select(pi =>
new Tuple<PropertyInfo, TAttribType>(pi, pi.GetCustomAttribute<TAttribType>())).ToArray();
}

private static bool IsDefaultOfType(object o)
{
if (o is ValueType)
{
return o.Equals(Activator.CreateInstance(o.GetType()));
}

return o == null;
}
}

/// <summary>
Expand Down Expand Up @@ -151,4 +141,4 @@ public string GetQueryString()
v => $"{Uri.EscapeUriString(_key)}={Uri.EscapeDataString(v)}"));
}
}
}
}