| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,8 +23,8 @@ internal class AssemblyManager | |||
| 23 | 23 | // than it can end up referring to assemblies that are already unloaded (default behavior after unload appDomain - | |
| 24 | 24 | // unless LoaderOptimization.MultiDomain is used); | |
| 25 | 25 | // So for multidomain support it is better to have the dict. recreated for each app-domain initialization | |
| 26 | - private static ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces = | ||
| 27 | - new ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>>(); | ||
| 26 | + private static readonly ConcurrentDictionary<string, ConcurrentDictionary<Assembly, string>> namespaces = | ||
| 27 | + new(); | ||
| 28 | 28 | ||
| 29 | 29 | #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. | |
| 30 | 30 | // domain-level handlers are initialized in Initialize | |
@@ -33,7 +33,7 @@ internal class AssemblyManager | |||
| 33 | 33 | #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. | |
| 34 | 34 | ||
| 35 | 35 | // updated only under GIL? | |
| 36 | - private static Dictionary<string, int> probed = new Dictionary<string, int>(32); | ||
| 36 | + private static readonly Dictionary<string, int> probed = new(32); | ||
| 37 | 37 | ||
| 38 | 38 | // modified from event handlers below, potentially triggered from different .NET threads | |
| 39 | 39 | private static readonly ConcurrentQueue<Assembly> assemblies = new(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -247,10 +247,9 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p | |||
| 247 | 247 | Runtime.PyDict_SetItem(dict, PyIdentifier.__doc__, doc.Borrow()); | |
| 248 | 248 | } | |
| 249 | 249 | ||
| 250 | - var co = impl as ClassObject; | ||
| 251 | 250 | // If this is a ClassObject AND it has constructors, generate a __doc__ attribute. | |
| 252 | 251 | // required that the ClassObject.ctors be changed to internal | |
| 253 | - if (co != null) | ||
| 252 | + if (impl is ClassObject co) | ||
| 254 | 253 | { | |
| 255 | 254 | if (co.NumCtors > 0 && !co.HasCustomNew()) | |
| 256 | 255 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ namespace Python.Runtime.Codecs | |||
| 10 | 10 | /// </summary> | |
| 11 | 11 | public sealed class DecoderGroup: IPyObjectDecoder, IEnumerable<IPyObjectDecoder>, IDisposable | |
| 12 | 12 | { | |
| 13 | - readonly List<IPyObjectDecoder> decoders = new List<IPyObjectDecoder>(); | ||
| 13 | + readonly List<IPyObjectDecoder> decoders = new(); | ||
| 14 | 14 | ||
| 15 | 15 | /// <summary> | |
| 16 | 16 | /// Add specified decoder to the group | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ namespace Python.Runtime.Codecs | |||
| 10 | 10 | /// </summary> | |
| 11 | 11 | public sealed class EncoderGroup: IPyObjectEncoder, IEnumerable<IPyObjectEncoder>, IDisposable | |
| 12 | 12 | { | |
| 13 | - readonly List<IPyObjectEncoder> encoders = new List<IPyObjectEncoder>(); | ||
| 13 | + readonly List<IPyObjectEncoder> encoders = new(); | ||
| 14 | 14 | ||
| 15 | 15 | /// <summary> | |
| 16 | 16 | /// Add specified encoder to the group | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,8 +15,8 @@ namespace Python.Runtime | |||
| 15 | 15 | /// </summary> | |
| 16 | 16 | public static class PyObjectConversions | |
| 17 | 17 | { | |
| 18 | - static readonly DecoderGroup decoders = new DecoderGroup(); | ||
| 19 | - static readonly EncoderGroup encoders = new EncoderGroup(); | ||
| 18 | + static readonly DecoderGroup decoders = new(); | ||
| 19 | + static readonly EncoderGroup encoders = new(); | ||
| 20 | 20 | ||
| 21 | 21 | /// <summary> | |
| 22 | 22 | /// Registers specified encoder (marshaller) | |
@@ -62,7 +62,7 @@ public static void RegisterDecoder(IPyObjectDecoder decoder) | |||
| 62 | 62 | } | |
| 63 | 63 | ||
| 64 | 64 | static readonly ConcurrentDictionary<Type, IPyObjectEncoder[]> | |
| 65 | - clrToPython = new ConcurrentDictionary<Type, IPyObjectEncoder[]>(); | ||
| 65 | + clrToPython = new(); | ||
| 66 | 66 | static IPyObjectEncoder[] GetEncoders(Type type) | |
| 67 | 67 | { | |
| 68 | 68 | lock (encoders) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,15 +18,15 @@ private Converter() | |||
| 18 | 18 | { | |
| 19 | 19 | } | |
| 20 | 20 | ||
| 21 | - private static Type objectType; | ||
| 22 | - private static Type stringType; | ||
| 23 | - private static Type singleType; | ||
| 24 | - private static Type doubleType; | ||
| 25 | - private static Type int16Type; | ||
| 26 | - private static Type int32Type; | ||
| 27 | - private static Type int64Type; | ||
| 28 | - private static Type boolType; | ||
| 29 | - private static Type typeType; | ||
| 21 | + private static readonly Type objectType; | ||
| 22 | + private static readonly Type stringType; | ||
| 23 | + private static readonly Type singleType; | ||
| 24 | + private static readonly Type doubleType; | ||
| 25 | + private static readonly Type int16Type; | ||
| 26 | + private static readonly Type int32Type; | ||
| 27 | + private static readonly Type int64Type; | ||
| 28 | + private static readonly Type boolType; | ||
| 29 | + private static readonly Type typeType; | ||
| 30 | 30 | ||
| 31 | 31 | static Converter() | |
| 32 | 32 | { | |
@@ -151,8 +151,7 @@ internal static NewReference ToPython(object? value, Type type) | |||
| 151 | 151 | ||
| 152 | 152 | // it the type is a python subclass of a managed type then return the | |
| 153 | 153 | // underlying python object rather than construct a new wrapper object. | |
| 154 | - var pyderived = value as IPythonDerivedType; | ||
| 155 | - if (null != pyderived) | ||
| 154 | + if (value is IPythonDerivedType pyderived) | ||
| 156 | 155 | { | |
| 157 | 156 | if (!IsTransparentProxy(pyderived)) | |
| 158 | 157 | return ClassDerivedObject.ToPython(pyderived); | |
@@ -161,7 +160,7 @@ internal static NewReference ToPython(object? value, Type type) | |||
| 161 | 160 | // ModuleObjects are created in a way that their wrapping them as | |
| 162 | 161 | // a CLRObject fails, the ClassObject has no tpHandle. Return the | |
| 163 | 162 | // pyHandle as is, do not convert. | |
| 164 | - if (value is ModuleObject modobj) | ||
| 163 | + if (value is ModuleObject) | ||
| 165 | 164 | { | |
| 166 | 165 | throw new NotImplementedException(); | |
| 167 | 166 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,13 +15,13 @@ namespace Python.Runtime | |||
| 15 | 15 | /// </summary> | |
| 16 | 16 | internal class DelegateManager | |
| 17 | 17 | { | |
| 18 | - private readonly Dictionary<Type,Type> cache = new Dictionary<Type, Type>(); | ||
| 18 | + private readonly Dictionary<Type,Type> cache = new(); | ||
| 19 | 19 | private readonly Type basetype = typeof(Dispatcher); | |
| 20 | 20 | private readonly Type arrayType = typeof(object[]); | |
| 21 | 21 | private readonly Type voidtype = typeof(void); | |
| 22 | 22 | private readonly Type typetype = typeof(Type); | |
| 23 | 23 | private readonly Type pyobjType = typeof(PyObject); | |
| 24 | - private readonly CodeGenerator codeGenerator = new CodeGenerator(); | ||
| 24 | + private readonly CodeGenerator codeGenerator = new(); | ||
| 25 | 25 | private readonly ConstructorInfo arrayCtor; | |
| 26 | 26 | private readonly MethodInfo dispatch; | |
| 27 | 27 | ||
@@ -309,7 +309,7 @@ protected Dispatcher(PyObject target, Type dtype) | |||
| 309 | 309 | { | |
| 310 | 310 | tpName += $" of size {Runtime.PyTuple_Size(op)}"; | |
| 311 | 311 | } | |
| 312 | - StringBuilder sb = new StringBuilder(); | ||
| 312 | + var sb = new StringBuilder(); | ||
| 313 | 313 | if (!isVoid) sb.Append(rtype.FullName); | |
| 314 | 314 | for (int i = 0; i < pi.Length; i++) | |
| 315 | 315 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -196,8 +196,7 @@ public static bool SetError(Exception e) | |||
| 196 | 196 | // might get a managed exception raised that is a wrapper for a | |
| 197 | 197 | // Python exception. In that case we'd rather have the real thing. | |
| 198 | 198 | ||
| 199 | - var pe = e as PythonException; | ||
| 200 | - if (pe != null) | ||
| 199 | + if (e is PythonException pe) | ||
| 201 | 200 | { | |
| 202 | 201 | pe.Restore(); | |
| 203 | 202 | return true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,7 @@ public ErrorArgs(Exception error) | |||
| 41 | 41 | [DefaultValue(true)] | |
| 42 | 42 | public bool Enable { get; set; } = true; | |
| 43 | 43 | ||
| 44 | - private ConcurrentQueue<PendingFinalization> _objQueue = new(); | ||
| 44 | + private readonly ConcurrentQueue<PendingFinalization> _objQueue = new(); | ||
| 45 | 45 | private readonly ConcurrentQueue<PendingFinalization> _derivedQueue = new(); | |
| 46 | 46 | private readonly ConcurrentQueue<Py_buffer> _bufferQueue = new(); | |
| 47 | 47 | private int _throttled; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,8 +61,7 @@ public static void Shutdown() | |||
| 61 | 61 | ||
| 62 | 62 | public static string? GetManagedString(BorrowedReference op) | |
| 63 | 63 | { | |
| 64 | - string s; | ||
| 65 | - if (TryGetInterned(op, out s)) | ||
| 64 | + if (TryGetInterned(op, out string s)) | ||
| 66 | 65 | { | |
| 67 | 66 | return s; | |
| 68 | 67 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments