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

[release/6.0] Fix TimeSpan support in sourcegen #62191

Merged
merged 3 commits into from
Jan 8, 2022
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private sealed class Parser
private readonly Type _objectType;
private readonly Type _stringType;

private readonly Type? _timeSpanType;
private readonly Type? _dateTimeOffsetType;
private readonly Type? _byteArrayType;
private readonly Type? _guidType;
Expand Down Expand Up @@ -202,6 +203,7 @@ public Parser(Compilation compilation, in JsonSourceGenerationContext sourceGene

_booleanType = _metadataLoadContext.Resolve(SpecialType.System_Boolean);
_charType = _metadataLoadContext.Resolve(SpecialType.System_Char);
_timeSpanType = _metadataLoadContext.Resolve(typeof(TimeSpan));
_dateTimeType = _metadataLoadContext.Resolve(SpecialType.System_DateTime);
_nullableOfTType = _metadataLoadContext.Resolve(SpecialType.System_Nullable_T);
_objectType = _metadataLoadContext.Resolve(SpecialType.System_Object);
Expand Down Expand Up @@ -1506,6 +1508,7 @@ private void PopulateKnownTypes()
_knownTypes.Add(_stringType);

AddTypeIfNotNull(_knownTypes, _byteArrayType);
AddTypeIfNotNull(_knownTypes, _timeSpanType);
AddTypeIfNotNull(_knownTypes, _dateTimeOffsetType);
AddTypeIfNotNull(_knownTypes, _guidType);
AddTypeIfNotNull(_knownTypes, _uriType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ protected static ActiveOrUpcomingEvent CreateActiveOrUpcomingEvent()
EndDate = DateTime.UtcNow.AddYears(1),
Name = "Just a name",
ImageUrl = "https://www.dotnetfoundation.org/theme/img/carousel/foundation-diagram-content.png",
StartDate = DateTime.UtcNow
StartDate = DateTime.UtcNow,
Offset = TimeSpan.FromHours(2)
ericstj marked this conversation as resolved.
Show resolved Hide resolved
};
}

Expand All @@ -413,6 +414,7 @@ protected static void VerifyActiveOrUpcomingEvent(ActiveOrUpcomingEvent expected
Assert.Equal(expected.ImageUrl, obj.ImageUrl);
Assert.Equal(expected.Name, obj.Name);
Assert.Equal(expected.StartDate, obj.StartDate);
Assert.Equal(expected.Offset, obj.Offset);
}

protected static CampaignSummaryViewModel CreateCampaignSummaryViewModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class ActiveOrUpcomingEvent
public string Description { get; set; }
public DateTimeOffset StartDate { get; set; }
public DateTimeOffset EndDate { get; set; }
public TimeSpan Offset { get; set; }
}

public class CampaignSummaryViewModel
Expand Down