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

Fix TimeSpan support in sourcegen #62130

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -75,6 +75,7 @@ private sealed class Parser

private readonly Type _booleanType;
private readonly Type _charType;
private readonly Type _timeSpanType;
private readonly Type _dateTimeType;
private readonly Type _nullableOfTType;
private readonly Type _objectType;
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)
};
}

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