diff --git a/CodeJam.Main/Readme.txt b/CodeJam.Main/Readme.txt index 373239604..3dc0b0e0d 100644 --- a/CodeJam.Main/Readme.txt +++ b/CodeJam.Main/Readme.txt @@ -1,8 +1,13 @@ CodeJam 2.2.0-beta3 Release Notes --------------------------------- +What's new in 2.2.0 +----------------------- +* StartsWithInvariant/EndsWithInvariant/IndexOfInvariant/LastIndexOfInvariant methods. +* Code cleanup. + What's new in 2.2.0-rc1 -------------------------- +----------------------- * Add deconstructor to IndexedItem, used in WithIndex extension method. * Code cleanup. diff --git a/CodeJam.Main/Strings/StringExtensions.ToXxx.cs b/CodeJam.Main/Strings/StringExtensions.ToXxx.cs index e507314e5..0aec3b509 100644 --- a/CodeJam.Main/Strings/StringExtensions.ToXxx.cs +++ b/CodeJam.Main/Strings/StringExtensions.ToXxx.cs @@ -28,6 +28,104 @@ public static string ToInvariantString([NotNull] this T s) where T : IFormatt public static string ToInvariantString([NotNull] this T s, string format) where T : IFormattable => s.ToString(format, CultureInfo.InvariantCulture); +#if !LESSTHAN_NETCOREAPP20 && !LESSTHAN_NETSTANDARD20 + /// + /// Determines whether the beginning of this string instance matches the specified string when compared using the + /// invariant culture. + /// + /// String to check. + /// The string to compare. + /// true if this instance begins with value; otherwise, false. + public static bool StartsWithInvariant(this string str, string value) => + str.StartsWith(value, StringComparison.InvariantCulture); + + /// + /// Reports the zero-based index of the first occurrence of the specified string in the + /// using the invariant culture. + /// + /// The string to check. + /// The string to seek. + /// + /// The index position of the value parameter if that string is found, or -1 if it is not. If value is , + /// the return value is 0 + /// + public static int IndexOfInvariant(this string str, string value) => + str.IndexOf(value, StringComparison.InvariantCulture); + + /// + /// Reports the zero-based index of the first occurrence of the specified string in the + /// using the invariant culture. Parameter specify the starting search position in the current string. + /// + /// The string to check. + /// The string to seek. + /// The search starting position. + /// + /// The index position of the value parameter if that string is found, or -1 if it is not. If value is , + /// the return value is 0 + /// + public static int IndexOfInvariant(this string str, string value, int startIndex) => + str.IndexOf(value, startIndex, StringComparison.InvariantCulture); + + /// + /// Reports the zero-based index of the first occurrence of the specified string in the + /// using the invariant culture. Parameters specify the starting search position in the current string and + /// the number of characters in the current string to search. + /// + /// The string to check. + /// The string to seek. + /// The search starting position. + /// The number of character positions to examine. + /// + /// The index position of the value parameter if that string is found, or -1 if it is not. If value is , + /// the return value is 0 + /// + public static int IndexOfInvariant(this string str, string value, int startIndex, int count) => + str.IndexOf(value, startIndex, count, StringComparison.InvariantCulture); + + /// + /// Reports the zero-based index of the last occurrence of the specified string in the + /// using the invariant culture. + /// + /// The string to check. + /// The string to seek. + /// + /// The index position of the value parameter if that string is found, or -1 if it is not. If value is , + /// the return value is 0 + /// + public static int LastIndexOfInvariant(this string str, string value) => + str.LastIndexOf(value, StringComparison.InvariantCulture); + + /// + /// Reports the zero-based index of the last occurrence of the specified string in the + /// using the invariant culture. Parameter specify the starting search position in the current string. + /// + /// The string to check. + /// The string to seek. + /// The search starting position. + /// + /// The index position of the value parameter if that string is found, or -1 if it is not. If value is , + /// the return value is 0 + /// + public static int LastIndexOfInvariant(this string str, string value, int startIndex) => + str.LastIndexOf(value, startIndex, StringComparison.InvariantCulture); + + /// + /// Reports the zero-based index of the last occurrence of the specified string in the + /// using the invariant culture. Parameters specify the starting search position in the current string and + /// the number of characters in the current string to search. + /// + /// The string to check. + /// The string to seek. + /// The search starting position. + /// The number of character positions to examine. + /// + /// The index position of the value parameter if that string is found, or -1 if it is not. If value is , + /// the return value is 0 + /// + public static int LastIndexOfInvariant(this string str, string value, int startIndex, int count) => + str.LastIndexOf(value, startIndex, count, StringComparison.InvariantCulture); +#endif + #region DateTime /// /// Converts the string representation of a number in a specified style and culture-specific format to its diff --git a/CodeJam.Main/Targeting/TypeExtensions.cs b/CodeJam.Main/Targeting/TypeExtensions.cs index b2985f4ed..d43d5ad2e 100644 --- a/CodeJam.Main/Targeting/TypeExtensions.cs +++ b/CodeJam.Main/Targeting/TypeExtensions.cs @@ -89,39 +89,39 @@ public static bool GetIsPublic([NotNull] this Type type) #endif } - [MethodImpl(AggressiveInlining)] - public static bool GetIsNestedPublic([NotNull] this Type type) - { -#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 - return type.GetTypeInfo().IsNestedPublic; -#else - return type.IsNestedPublic; -#endif - } - - [MethodImpl(AggressiveInlining)] - public static bool GetIsFromLocalAssembly([NotNull] this Type type) - { -#if SILVERLIGHT - string assemblyName = type.GetAssembly().FullName; -#else - var assemblyName = type.GetAssembly().GetName().Name; -#endif - - try - { -#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 - Assembly.Load(new AssemblyName { Name = assemblyName }); -#else - Assembly.Load(assemblyName); -#endif - return true; - } - catch - { - return false; - } - } +// [MethodImpl(AggressiveInlining)] +// public static bool GetIsNestedPublic([NotNull] this Type type) +// { +//#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 +// return type.GetTypeInfo().IsNestedPublic; +//#else +// return type.IsNestedPublic; +//#endif +// } + +// [MethodImpl(AggressiveInlining)] +// public static bool GetIsFromLocalAssembly([NotNull] this Type type) +// { +//#if SILVERLIGHT +// string assemblyName = type.GetAssembly().FullName; +//#else +// var assemblyName = type.GetAssembly().GetName().Name; +//#endif + +// try +// { +//#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 +// Assembly.Load(new AssemblyName { Name = assemblyName }); +//#else +// Assembly.Load(assemblyName); +//#endif +// return true; +// } +// catch +// { +// return false; +// } +// } [MethodImpl(AggressiveInlining)] public static bool GetIsGenericType([NotNull] this Type type) @@ -184,15 +184,15 @@ public static bool GetContainsGenericParameters([NotNull] this Type type) #endif } - [MethodImpl(AggressiveInlining)] - public static bool GetIsDefined([NotNull] this Type type, [NotNull] Type attributeType) - { -#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 - return type.GetTypeInfo().IsDefined(attributeType); -#else - return Attribute.IsDefined(type, attributeType); -#endif - } +// [MethodImpl(AggressiveInlining)] +// public static bool GetIsDefined([NotNull] this Type type, [NotNull] Type attributeType) +// { +//#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 +// return type.GetTypeInfo().IsDefined(attributeType); +//#else +// return Attribute.IsDefined(type, attributeType); +//#endif +// } [MethodImpl(AggressiveInlining)] public static bool GetIsDefined([NotNull] this Type type, [NotNull] Type attributeType, bool inherit) @@ -214,78 +214,78 @@ public static bool GetIsArray([NotNull] this Type type) #endif } - [MethodImpl(AggressiveInlining)] - public static PropertyInfo GetGetProperty([NotNull] this Type type, [NotNull] string propertyName) - { -#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 - return type.GetTypeInfo().GetProperty(propertyName); -#else - return type.GetProperty(propertyName); -#endif - } - - [MethodImpl(AggressiveInlining)] - public static T GetPropertyValue([NotNull] this Type type, [NotNull] string propertyName, object target) - { -#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 - var property = type.GetTypeInfo().GetDeclaredProperty(propertyName); - return (T)property.GetValue(target); -#else - return (T)type.InvokeMember(propertyName, BindingFlags.GetProperty, null, target, null); -#endif - } - - [MethodImpl(AggressiveInlining)] - public static void SetPropertyValue( - [NotNull] this Type type, [NotNull] string propertyName, object target, object value) - { -#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 - var property = type.GetTypeInfo().GetDeclaredProperty(propertyName); - property.SetValue(target, value); -#else - type.InvokeMember(propertyName, BindingFlags.SetProperty, null, target, new[] { value }); -#endif - } - - [MethodImpl(AggressiveInlining)] - public static T GetFieldValue([NotNull] this Type type, [NotNull] string fieldName, object target) - { -#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 - var field = type.GetTypeInfo().GetDeclaredField(fieldName); - return (T)field.GetValue(target); -#else - return (T)type.InvokeMember(fieldName, BindingFlags.GetField | BindingFlags.GetProperty, null, target, null); -#endif - } - - [MethodImpl(AggressiveInlining)] - public static void SetFieldValue([NotNull] this Type type, [NotNull] string fieldName, object target, object value) - { -#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 - var field = type.GetTypeInfo().GetDeclaredField(fieldName); - if (field != null) - { - field.SetValue(target, value); - } - else - { - type.SetPropertyValue(fieldName, target, value); - } -#else - type.InvokeMember(fieldName, BindingFlags.SetField | BindingFlags.SetProperty, null, target, new[] { value }); -#endif - } - - [MethodImpl(AggressiveInlining)] - public static void InvokeMethod([NotNull] this Type type, [NotNull] string methodName, object target, T value) - { -#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 - var method = type.GetTypeInfo().GetDeclaredMethod(methodName); - method.Invoke(target, new object[] { value }); -#else - type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, target, new object[] { value }); -#endif - } +// [MethodImpl(AggressiveInlining)] +// public static PropertyInfo GetGetProperty([NotNull] this Type type, [NotNull] string propertyName) +// { +//#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 +// return type.GetTypeInfo().GetProperty(propertyName); +//#else +// return type.GetProperty(propertyName); +//#endif +// } + +// [MethodImpl(AggressiveInlining)] +// public static T GetPropertyValue([NotNull] this Type type, [NotNull] string propertyName, object target) +// { +//#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 +// var property = type.GetTypeInfo().GetDeclaredProperty(propertyName); +// return (T)property.GetValue(target); +//#else +// return (T)type.InvokeMember(propertyName, BindingFlags.GetProperty, null, target, null); +//#endif +// } + +// [MethodImpl(AggressiveInlining)] +// public static void SetPropertyValue( +// [NotNull] this Type type, [NotNull] string propertyName, object target, object value) +// { +//#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 +// var property = type.GetTypeInfo().GetDeclaredProperty(propertyName); +// property.SetValue(target, value); +//#else +// type.InvokeMember(propertyName, BindingFlags.SetProperty, null, target, new[] { value }); +//#endif +// } + +// [MethodImpl(AggressiveInlining)] +// public static T GetFieldValue([NotNull] this Type type, [NotNull] string fieldName, object target) +// { +//#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 +// var field = type.GetTypeInfo().GetDeclaredField(fieldName); +// return (T)field.GetValue(target); +//#else +// return (T)type.InvokeMember(fieldName, BindingFlags.GetField | BindingFlags.GetProperty, null, target, null); +//#endif +// } + +// [MethodImpl(AggressiveInlining)] +// public static void SetFieldValue([NotNull] this Type type, [NotNull] string fieldName, object target, object value) +// { +//#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 +// var field = type.GetTypeInfo().GetDeclaredField(fieldName); +// if (field != null) +// { +// field.SetValue(target, value); +// } +// else +// { +// type.SetPropertyValue(fieldName, target, value); +// } +//#else +// type.InvokeMember(fieldName, BindingFlags.SetField | BindingFlags.SetProperty, null, target, new[] { value }); +//#endif +// } + +// [MethodImpl(AggressiveInlining)] +// public static void InvokeMethod([NotNull] this Type type, [NotNull] string methodName, object target, T value) +// { +//#if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 +// var method = type.GetTypeInfo().GetDeclaredMethod(methodName); +// method.Invoke(target, new object[] { value }); +//#else +// type.InvokeMember(methodName, BindingFlags.InvokeMethod, null, target, new object[] { value }); +//#endif +// } #if LESSTHAN_NETSTANDARD20 || LESSTHAN_NETCOREAPP20 diff --git a/CodeJam.sln.DotSettings b/CodeJam.sln.DotSettings index 90cdcb970..75479c767 100644 --- a/CodeJam.sln.DotSettings +++ b/CodeJam.sln.DotSettings @@ -396,6 +396,7 @@ True True True + True True True True