Skip to content

Commit b22b3a2

Browse files
committed
Remove all usage of deprecated APIs
1 parent 764b090 commit b22b3a2

51 files changed

Lines changed: 263 additions & 504 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ServiceStack.Text/AssemblyUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public static Type FindType(string typeName)
5656
public static Type MainInterface<T>()
5757
{
5858
var t = typeof(T);
59-
if (t.BaseType() == typeof(object))
59+
if (t.BaseType == typeof(object))
6060
{
6161
// on Windows, this can be just "t.GetInterfaces()" but Mono doesn't return in order.
62-
var interfaceType = t.Interfaces().FirstOrDefault(i => !t.Interfaces().Any(i2 => i2.Interfaces().Contains(i)));
62+
var interfaceType = t.GetInterfaces().FirstOrDefault(i => !t.GetInterfaces().Any(i2 => i2.GetInterfaces().Contains(i)));
6363
if (interfaceType != null) return interfaceType;
6464
}
6565
return t; // not safe to use interface, as it might be a superclass's one.

src/ServiceStack.Text/AutoMappingUtils.cs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public static T ConvertTo<T>(this object from)
2828
if (fromType == typeof(T))
2929
return (T)from;
3030

31-
if (fromType.IsValueType() || typeof(T).IsValueType())
31+
if (fromType.IsValueType || typeof(T).IsValueType)
3232
{
33-
if (!fromType.IsEnum() && !typeof(T).IsEnum())
33+
if (!fromType.IsEnum && !typeof(T).IsEnum)
3434
{
3535
if (typeof(T) == typeof(char) && from is string s)
3636
return (T)(s.Length > 0 ? (object) s[0] : null);
@@ -58,7 +58,7 @@ public static T ConvertTo<T>(this object from)
5858
return (T)ChangeValueType(from, typeof(T));
5959
}
6060

61-
if (typeof(IEnumerable).IsAssignableFromType(typeof(T)))
61+
if (typeof(IEnumerable).IsAssignableFrom(typeof(T)))
6262
{
6363
var listResult = TranslateListWithElements.TryTranslateCollections(
6464
fromType, typeof(T), from);
@@ -72,10 +72,10 @@ public static T ConvertTo<T>(this object from)
7272

7373
public static T CreateCopy<T>(this T from)
7474
{
75-
if (typeof(T).IsValueType())
75+
if (typeof(T).IsValueType)
7676
return (T)ChangeValueType(from, typeof(T));
7777

78-
if (typeof(IEnumerable).IsAssignableFromType(typeof(T)))
78+
if (typeof(IEnumerable).IsAssignableFrom(typeof(T)))
7979
{
8080
var listResult = TranslateListWithElements.TryTranslateCollections(
8181
from.GetType(), typeof(T), from);
@@ -101,10 +101,10 @@ public static object ConvertTo(this object from, Type type)
101101
if (from.GetType() == type)
102102
return from;
103103

104-
if (from.GetType().IsValueType() || type.IsValueType())
104+
if (from.GetType().IsValueType || type.IsValueType)
105105
return ChangeValueType(from, type);
106106

107-
if (typeof(IEnumerable).IsAssignableFromType(type))
107+
if (typeof(IEnumerable).IsAssignableFrom(type))
108108
{
109109
var listResult = TranslateListWithElements.TryTranslateCollections(
110110
from.GetType(), type, from);
@@ -129,7 +129,7 @@ private static object ChangeValueType(object from, Type type)
129129

130130
public static object ChangeTo(this string strValue, Type type)
131131
{
132-
if (type.IsValueType() && !type.IsEnum() && type.HasInterface(typeof(IConvertible)))
132+
if (type.IsValueType && !type.IsEnum && type.HasInterface(typeof(IConvertible)))
133133
{
134134
try
135135
{
@@ -177,14 +177,14 @@ public static bool IsDebugBuild(this Assembly assembly)
177177
public static object PopulateWith(object obj)
178178
{
179179
if (obj == null) return null;
180-
var isHttpResult = obj.GetType().Interfaces().Any(x => x.Name == "IHttpResult"); // No coupling FTW!
180+
var isHttpResult = obj.GetType().GetInterfaces().Any(x => x.Name == "IHttpResult"); // No coupling FTW!
181181
if (isHttpResult)
182182
{
183183
obj = new CustomHttpResult();
184184
}
185185

186186
var type = obj.GetType();
187-
if (type.IsArray() || type.IsValueType() || type.IsGeneric())
187+
if (type.IsArray || type.IsValueType || type.IsGenericType)
188188
{
189189
var value = CreateDefaultValue(type, new Dictionary<Type, int>(20));
190190
return value;
@@ -224,19 +224,18 @@ private static object PopulateObjectInternal(object obj, Dictionary<Type, int> r
224224

225225
public static object GetDefaultValue(this Type type)
226226
{
227-
if (!type.IsValueType()) return null;
227+
if (!type.IsValueType) return null;
228228

229-
object defaultValue;
230-
if (DefaultValueTypes.TryGetValue(type, out defaultValue)) return defaultValue;
229+
if (DefaultValueTypes.TryGetValue(type, out var defaultValue))
230+
return defaultValue;
231231

232232
defaultValue = Activator.CreateInstance(type);
233233

234234
Dictionary<Type, object> snapshot, newCache;
235235
do
236236
{
237237
snapshot = DefaultValueTypes;
238-
newCache = new Dictionary<Type, object>(DefaultValueTypes);
239-
newCache[type] = defaultValue;
238+
newCache = new Dictionary<Type, object>(DefaultValueTypes) { [type] = defaultValue };
240239

241240
} while (!ReferenceEquals(
242241
Interlocked.CompareExchange(ref DefaultValueTypes, newCache, snapshot), snapshot));
@@ -304,7 +303,7 @@ private static Dictionary<string, AssignmentMember> GetMembers(Type type, bool i
304303
}
305304
else
306305
{
307-
if (propertyInfo.CanWrite && propertyInfo.SetMethod() != null)
306+
if (propertyInfo.CanWrite && propertyInfo.GetSetMethod(nonPublic:true) != null)
308307
{
309308
map[info.Name] = new AssignmentMember(propertyInfo.PropertyType, propertyInfo);
310309
continue;
@@ -419,7 +418,7 @@ public static void SetProperty(this PropertyInfo propertyInfo, object obj, objec
419418
return;
420419
}
421420

422-
var propertySetMetodInfo = propertyInfo.SetMethod();
421+
var propertySetMetodInfo = propertyInfo.GetSetMethod(nonPublic:true);
423422
if (propertySetMetodInfo != null)
424423
{
425424
propertySetMetodInfo.Invoke(obj, new[] { value });
@@ -431,7 +430,7 @@ public static object GetProperty(this PropertyInfo propertyInfo, object obj)
431430
if (propertyInfo == null || !propertyInfo.CanRead)
432431
return null;
433432

434-
var getMethod = propertyInfo.GetMethodInfo();
433+
var getMethod = propertyInfo.GetGetMethod(nonPublic:true);
435434
return getMethod != null ? getMethod.Invoke(obj, TypeConstants.EmptyObjectArray) : null;
436435
}
437436

@@ -462,7 +461,7 @@ public static bool IsUnsettableValue(FieldInfo fieldInfo, PropertyInfo propertyI
462461
// Currently we define those properties as properties declared on
463462
// types defined in mscorlib
464463

465-
if (propertyInfo != null && propertyInfo.ReflectedType() != null)
464+
if (propertyInfo != null && propertyInfo.ReflectedType != null)
466465
{
467466
return PclExport.Instance.InSameAssembly(propertyInfo.DeclaringType, typeof(object));
468467
}
@@ -489,32 +488,31 @@ public static object CreateDefaultValue(Type type, Dictionary<Type, int> recursi
489488
return type.Name;
490489
}
491490

492-
if (type.IsEnum())
491+
if (type.IsEnum)
493492
{
494493
return Enum.GetValues(type).GetValue(0);
495494
}
496495

497-
if (type.IsAbstract())
496+
if (type.IsAbstract)
498497
return null;
499498

500499
// If we have hit our recursion limit for this type, then return null
501-
int recurseLevel; // will get set to 0 if TryGetValue() fails
502-
recursionInfo.TryGetValue(type, out recurseLevel);
500+
recursionInfo.TryGetValue(type, out var recurseLevel);
503501
if (recurseLevel > MaxRecursionLevelForDefaultValues) return null;
504502

505503
recursionInfo[type] = recurseLevel + 1; // increase recursion level for this type
506504
try // use a try/finally block to make sure we decrease the recursion level for this type no matter which code path we take,
507505
{
508506

509507
//when using KeyValuePair<TKey, TValue>, TKey must be non-default to stuff in a Dictionary
510-
if (type.IsGeneric() && type.GenericTypeDefinition() == typeof(KeyValuePair<,>))
508+
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
511509
{
512-
var genericTypes = type.GenericTypeArguments();
510+
var genericTypes = type.GetGenericArguments();
513511
var valueType = Activator.CreateInstance(type, CreateDefaultValue(genericTypes[0], recursionInfo), CreateDefaultValue(genericTypes[1], recursionInfo));
514512
return PopulateObjectInternal(valueType, recursionInfo);
515513
}
516514

517-
if (type.IsValueType())
515+
if (type.IsValueType)
518516
{
519517
return type.CreateInstance();
520518
}
@@ -524,7 +522,7 @@ public static object CreateDefaultValue(Type type, Dictionary<Type, int> recursi
524522
return PopulateArray(type, recursionInfo);
525523
}
526524

527-
var constructorInfo = type.GetEmptyConstructor();
525+
var constructorInfo = type.GetConstructor(Type.EmptyTypes);
528526
var hasEmptyConstructor = constructorInfo != null;
529527

530528
if (hasEmptyConstructor)
@@ -550,7 +548,7 @@ public static object CreateDefaultValue(Type type, Dictionary<Type, int> recursi
550548

551549
public static void SetGenericCollection(Type realisedListType, object genericObj, Dictionary<Type, int> recursionInfo)
552550
{
553-
var args = realisedListType.GenericTypeArguments();
551+
var args = realisedListType.GetGenericArguments();
554552
if (args.Length != 1)
555553
{
556554
Tracer.Instance.WriteError("Found a generic list that does not take one generic argument: {0}", realisedListType);
@@ -580,9 +578,9 @@ public static Array PopulateArray(Type type, Dictionary<Type, int> recursionInfo
580578
//TODO: replace with InAssignableFrom
581579
public static bool CanCast(Type toType, Type fromType)
582580
{
583-
if (toType.IsInterface())
581+
if (toType.IsInterface)
584582
{
585-
var interfaceList = fromType.Interfaces().ToList();
583+
var interfaceList = fromType.GetInterfaces().ToList();
586584
if (interfaceList.Contains(toType)) return true;
587585
}
588586
else
@@ -593,7 +591,7 @@ public static bool CanCast(Type toType, Type fromType)
593591
{
594592
areSameTypes = baseType == toType;
595593
}
596-
while (!areSameTypes && (baseType = fromType.BaseType()) != null);
594+
while (!areSameTypes && (baseType = fromType.BaseType) != null);
597595

598596
if (areSameTypes) return true;
599597
}
@@ -617,7 +615,7 @@ public static IEnumerable<KeyValuePair<PropertyInfo, T>> GetPropertyAttributes<T
617615
}
618616
}
619617
}
620-
while ((baseType = baseType.BaseType()) != null);
618+
while ((baseType = baseType.BaseType) != null);
621619
}
622620
}
623621

@@ -799,15 +797,15 @@ public static GetMemberDelegate CreateTypeConverter(Type fromType, Type toType)
799797
var underlyingToType = Nullable.GetUnderlyingType(toType) ?? toType;
800798
var underlyingFromType = Nullable.GetUnderlyingType(fromType) ?? fromType;
801799

802-
if (underlyingToType.IsEnum())
800+
if (underlyingToType.IsEnum)
803801
{
804-
if (underlyingFromType.IsEnum() || fromType == typeof(string))
802+
if (underlyingFromType.IsEnum || fromType == typeof(string))
805803
return fromValue => Enum.Parse(underlyingToType, fromValue.ToString(), ignoreCase: true);
806804

807805
if (underlyingFromType.IsIntegerType())
808806
return fromValue => Enum.ToObject(underlyingToType, fromValue);
809807
}
810-
else if (underlyingFromType.IsEnum())
808+
else if (underlyingFromType.IsEnum)
811809
{
812810
if (underlyingToType.IsIntegerType())
813811
return fromValue => Convert.ChangeType(fromValue, underlyingToType, null);
@@ -816,7 +814,7 @@ public static GetMemberDelegate CreateTypeConverter(Type fromType, Type toType)
816814
{
817815
return null;
818816
}
819-
else if (typeof(IEnumerable).IsAssignableFromType(fromType))
817+
else if (typeof(IEnumerable).IsAssignableFrom(fromType))
820818
{
821819
return fromValue =>
822820
{
@@ -826,7 +824,7 @@ public static GetMemberDelegate CreateTypeConverter(Type fromType, Type toType)
826824
return listResult ?? fromValue;
827825
};
828826
}
829-
else if (toType.IsValueType())
827+
else if (toType.IsValueType)
830828
{
831829
return fromValue => Convert.ChangeType(fromValue, toType, provider: null);
832830
}

src/ServiceStack.Text/CollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public static ICollection<T> CreateAndPopulate<T>(Type ofCollectionType, T[] wit
1717
var genericTypeDefinition = genericType != null
1818
? genericType.GetGenericTypeDefinition()
1919
: null;
20-
#if !XBOX
20+
2121
if (genericTypeDefinition == typeof(HashSet<>))
2222
return new HashSet<T>(withItems);
23-
#endif
23+
2424
if (genericTypeDefinition == typeof(LinkedList<>))
2525
return new LinkedList<T>(withItems);
2626

src/ServiceStack.Text/Common/DeserializeCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static ParseStringSegmentDelegate GetParseStringSegmentMethod(Type type)
4343
if (type.HasInterface(typeof(ICollection<int>)))
4444
return value => ParseIntCollection(value, type);
4545

46-
var elementType = collectionInterface.GenericTypeArguments()[0];
46+
var elementType = collectionInterface.GetGenericArguments()[0];
4747
var supportedTypeParseMethod = Serializer.GetParseStringSegmentFn(elementType);
4848
if (supportedTypeParseMethod != null)
4949
{

src/ServiceStack.Text/Common/DeserializeCustomGenericType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static object ParseTuple(Type tupleType, StringSegment value)
4949
Serializer.EatItemSeperatorOrMapEndChar(value, ref index);
5050
}
5151

52-
var ctor = tupleType.DeclaredConstructors()
52+
var ctor = tupleType.GetConstructors()
5353
.First(x => x.GetParameters().Length == genericArgs.Length);
5454
return ctor.Invoke(argValues);
5555
}

src/ServiceStack.Text/Common/DeserializeDictionary.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
using ServiceStack.Text.Json;
2121
using ServiceStack.Text.Pools;
2222
using ServiceStack.Text.Support;
23+
2324
#if NETSTANDARD2_0
2425
using Microsoft.Extensions.Primitives;
25-
#else
26-
using ServiceStack.Text.Support;
2726
#endif
2827

2928
namespace ServiceStack.Text.Common
@@ -51,7 +50,7 @@ public static ParseStringSegmentDelegate GetParseStringSegmentMethod(Type type)
5150
{
5251
return GetParseStringSegmentMethod(typeof(Dictionary<object, object>));
5352
}
54-
if (typeof(IDictionary).IsAssignableFromType(type))
53+
if (typeof(IDictionary).IsAssignableFrom(type))
5554
{
5655
return s => ParseIDictionary(s, type);
5756
}
@@ -69,7 +68,7 @@ public static ParseStringSegmentDelegate GetParseStringSegmentMethod(Type type)
6968
return ParseJsonObject;
7069
}
7170

72-
var dictionaryArgs = mapInterface.GenericTypeArguments();
71+
var dictionaryArgs = mapInterface.GetGenericArguments();
7372
var keyTypeParseMethod = Serializer.GetParseStringSegmentFn(dictionaryArgs[KeyIndex]);
7473
if (keyTypeParseMethod == null) return null;
7574

src/ServiceStack.Text/Common/DeserializeKeyValuePair.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static ParseStringSegmentDelegate GetParseStringSegmentMethod(Type type)
4141
{
4242
var mapInterface = type.GetTypeWithGenericInterfaceOf(typeof(KeyValuePair<,>));
4343

44-
var keyValuePairArgs = mapInterface.GenericTypeArguments();
44+
var keyValuePairArgs = mapInterface.GetGenericArguments();
4545
var keyTypeParseMethod = Serializer.GetParseStringSegmentFn(keyValuePairArgs[KeyIndex]);
4646
if (keyTypeParseMethod == null) return null;
4747

src/ServiceStack.Text/Common/DeserializeListWithElements.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public static ICollection<T> ParseGenericList(StringSegment value, Type createLi
178178
if (!(value = DeserializeListWithElements<TSerializer>.StripList(value)).HasValue) return null;
179179

180180
var isReadOnly = createListType != null
181-
&& (createListType.IsGeneric() && createListType.GenericTypeDefinition() == typeof(ReadOnlyCollection<>));
181+
&& (createListType.IsGenericType && createListType.GetGenericTypeDefinition() == typeof(ReadOnlyCollection<>));
182182

183183
var to = (createListType == null || isReadOnly)
184184
? new List<T>()
@@ -282,7 +282,7 @@ public static ParseStringSegmentDelegate GetParseStringSegmentFn()
282282
if (typeof(T) == typeof(List<int>))
283283
return DeserializeListWithElements<TSerializer>.ParseIntList;
284284

285-
var elementType = listInterface.GenericTypeArguments()[0];
285+
var elementType = listInterface.GetGenericArguments()[0];
286286

287287
var supportedTypeParseMethod = DeserializeListWithElements<TSerializer>.Serializer.GetParseStringSegmentFn(elementType);
288288
if (supportedTypeParseMethod != null)
@@ -328,7 +328,7 @@ public static ParseStringSegmentDelegate GetParseStringSegmentFn()
328328
if (typeof(T) == typeof(IEnumerable<int>))
329329
return DeserializeListWithElements<TSerializer>.ParseIntList;
330330

331-
var elementType = enumerableInterface.GenericTypeArguments()[0];
331+
var elementType = enumerableInterface.GetGenericArguments()[0];
332332

333333
var supportedTypeParseMethod = DeserializeListWithElements<TSerializer>.Serializer.GetParseStringSegmentFn(elementType);
334334
if (supportedTypeParseMethod != null)

0 commit comments

Comments
 (0)