Skip to content

Commit

Permalink
fix for local scope being null - dont serialize provider if default
Browse files Browse the repository at this point in the history
  • Loading branch information
kasravi committed Jul 19, 2017
1 parent da0ca80 commit 2598360
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Composite/Data/DataSourceId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public DataSourceId(IDataId dataId, string providerName, Type interfaceType)
/// <summary>
/// This is for internal use only!
/// </summary>
[JsonConstructor]
public DataSourceId(IDataId dataId, string providerName, Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo localeScope)
{
// This constructor has to be extremely fast, we have up to 100.000 objects related while some requests
Expand All @@ -50,6 +49,19 @@ public DataSourceId(IDataId dataId, string providerName, Type interfaceType, Dat
this.ExistsInStore = true;
}

[JsonConstructor]
private DataSourceId(IDataId dataId, string providerName, Type interfaceType, DataScopeIdentifier dataScopeIdentifier, string localeScope)
{
// This constructor has to be extremely fast, we have up to 100.000 objects related while some requests

this.DataId = dataId ?? throw new ArgumentNullException(nameof(dataId));
ProviderName = providerName ?? DataProviderRegistry.DefaultDynamicTypeDataProviderName;
if (string.IsNullOrEmpty(providerName)) throw new ArgumentNullException(nameof(providerName));
InterfaceType = interfaceType ?? throw new ArgumentNullException(nameof(interfaceType));
DataScopeIdentifier = dataScopeIdentifier ?? throw new ArgumentNullException(nameof(dataScopeIdentifier));
LocaleScope = CultureInfo.CreateSpecificCulture(localeScope);
this.ExistsInStore = true;
}


/// <summary>
Expand All @@ -74,6 +86,11 @@ internal DataSourceId(Type interfaceType)
/// </summary>
public string ProviderName { get; }

private bool ShouldSerializeProviderName()
{
// don't serialize ProviderName if it is default
return (ProviderName != DataProviderRegistry.DefaultDynamicTypeDataProviderName);
}

/// <summary>
/// The interface used for the data element. This is expected to be implementing IData.
Expand All @@ -96,8 +113,11 @@ internal DataSourceId(Type interfaceType)
/// <summary>
/// The language from which the data element originate.
/// </summary>
[JsonIgnore]
public CultureInfo LocaleScope { get; internal set; }

[JsonProperty(PropertyName = "localeScope")]
private string LocalScopeName => LocaleScope.Name;

/// <summary>
/// True when the data element represents a physically stored element
Expand Down

0 comments on commit 2598360

Please sign in to comment.