-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Cleanup TypeConverter replacements #203
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ab0b3b2
Remove dead code from DateTimeConverter2
hughbe a3c0fba
Cleanup DateTimeOffsetConverter2
hughbe f5ed558
Cleanup TypeUriConverter
hughbe 6902413
Cleanup TypeListConverter
hughbe ced5cdd
Cleanup other Xaml Replacement converters
hughbe File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,17 @@ | |
using System.Reflection; | ||
using System.Security; | ||
|
||
namespace System.Windows.Markup | ||
namespace System.Xaml.Replacements | ||
{ | ||
class DateTimeOffsetConverter2 : TypeConverter | ||
internal class DateTimeOffsetConverter2 : TypeConverter | ||
{ | ||
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) | ||
{ | ||
if (destinationType == typeof(string) || destinationType == typeof(InstanceDescriptor)) | ||
{ | ||
return true; | ||
} | ||
|
||
return base.CanConvertTo(context, destinationType); | ||
} | ||
|
||
|
@@ -27,42 +28,32 @@ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceT | |
{ | ||
return true; | ||
} | ||
|
||
return base.CanConvertFrom(context, sourceType); | ||
} | ||
|
||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) | ||
{ | ||
if ((destinationType == typeof(string)) && (value is DateTimeOffset)) | ||
if (value is DateTimeOffset dtOffset) | ||
{ | ||
if (culture == null) | ||
if (destinationType == typeof(string)) | ||
{ | ||
culture = CultureInfo.CurrentCulture; | ||
return dtOffset.ToString("O", culture ?? CultureInfo.CurrentCulture); | ||
} | ||
|
||
return ((DateTimeOffset)value).ToString("O", culture); | ||
} | ||
if ((destinationType == typeof(InstanceDescriptor)) && (value is DateTimeOffset)) | ||
{ | ||
// Use the year, month, day, hour, minute, second, millisecond, offset constructor | ||
// Should there be a branch to use the calendar constructor? | ||
DateTimeOffset dtOffset = (DateTimeOffset)value; | ||
|
||
Type intType = typeof(int); | ||
ConstructorInfo constructor = typeof(DateTimeOffset).GetConstructor( | ||
new Type[] { | ||
intType, | ||
intType, | ||
intType, | ||
intType, | ||
intType, | ||
intType, | ||
intType, | ||
typeof(TimeSpan) | ||
} | ||
); | ||
|
||
if (constructor != null) | ||
else if (destinationType == typeof(InstanceDescriptor)) | ||
{ | ||
// Use the year, month, day, hour, minute, second, millisecond, offset constructor | ||
ConstructorInfo constructor = typeof(DateTimeOffset).GetConstructor(new Type[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. constructor will always exist, remove null check |
||
{ | ||
typeof(int), | ||
typeof(int), | ||
typeof(int), | ||
typeof(int), | ||
typeof(int), | ||
typeof(int), | ||
typeof(int), | ||
typeof(TimeSpan) | ||
}); | ||
return new InstanceDescriptor( | ||
constructor, | ||
new object[] { | ||
|
@@ -77,23 +68,16 @@ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo cul | |
}, | ||
true); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
return base.ConvertTo(context, culture, value, destinationType); | ||
} | ||
|
||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) | ||
{ | ||
if (value is string) | ||
if (value is string s) | ||
{ | ||
string s = ((string)value).Trim(); | ||
|
||
if (culture == null) | ||
{ | ||
culture = CultureInfo.CurrentCulture; | ||
} | ||
return DateTimeOffset.Parse(s, culture, DateTimeStyles.None); | ||
return DateTimeOffset.Parse(s.Trim(), culture ?? CultureInfo.CurrentCulture, DateTimeStyles.None); | ||
} | ||
|
||
return base.ConvertFrom(context, culture, value); | ||
|
60 changes: 0 additions & 60 deletions
60
...oft.DotNet.Wpf/src/System.Xaml/System/Xaml/Replacements/DateTimeValueSerializerContext.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
DateTimeValueSerializerContext
doesn't have any functionality, we can just pass null and remove the class here and in the otherDateTimeConverter2