| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,11 +32,13 @@ internal ClassObject(Type tp) : base(tp) | |||
| 32 | 32 | internal IntPtr GetDocString() | |
| 33 | 33 | { | |
| 34 | 34 | MethodBase[] methods = binder.GetMethods(); | |
| 35 | - string str = ""; | ||
| 35 | + var str = ""; | ||
| 36 | 36 | foreach (MethodBase t in methods) | |
| 37 | 37 | { | |
| 38 | 38 | if (str.Length > 0) | |
| 39 | + { | ||
| 39 | 40 | str += Environment.NewLine; | |
| 41 | + } | ||
| 40 | 42 | str += t.ToString(); | |
| 41 | 43 | } | |
| 42 | 44 | return Runtime.PyString_FromString(str); | |
@@ -48,7 +50,7 @@ internal IntPtr GetDocString() | |||
| 48 | 50 | /// </summary> | |
| 49 | 51 | public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) | |
| 50 | 52 | { | |
| 51 | - ClassObject self = GetManagedObject(tp) as ClassObject; | ||
| 53 | + var self = GetManagedObject(tp) as ClassObject; | ||
| 52 | 54 | ||
| 53 | 55 | // Sanity check: this ensures a graceful error if someone does | |
| 54 | 56 | // something intentially wrong like use the managed metatype for | |
@@ -72,7 +74,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) | |||
| 72 | 74 | } | |
| 73 | 75 | ||
| 74 | 76 | IntPtr op = Runtime.PyTuple_GetItem(args, 0); | |
| 75 | - Object result; | ||
| 77 | + object result; | ||
| 76 | 78 | ||
| 77 | 79 | if (!Converter.ToManaged(op, type, out result, true)) | |
| 78 | 80 | { | |
@@ -94,7 +96,7 @@ public static IntPtr tp_new(IntPtr tp, IntPtr args, IntPtr kw) | |||
| 94 | 96 | return IntPtr.Zero; | |
| 95 | 97 | } | |
| 96 | 98 | ||
| 97 | - Object obj = self.binder.InvokeRaw(IntPtr.Zero, args, kw); | ||
| 99 | + object obj = self.binder.InvokeRaw(IntPtr.Zero, args, kw); | ||
| 98 | 100 | if (obj == null) | |
| 99 | 101 | { | |
| 100 | 102 | return IntPtr.Zero; | |
@@ -119,8 +121,8 @@ public override IntPtr type_subscript(IntPtr idx) | |||
| 119 | 121 | { | |
| 120 | 122 | return Exceptions.RaiseTypeError("type expected"); | |
| 121 | 123 | } | |
| 122 | - ClassBase c = GetManagedObject(idx) as ClassBase; | ||
| 123 | - Type t = (c != null) ? c.type : Converter.GetTypeByAlias(idx); | ||
| 124 | + var c = GetManagedObject(idx) as ClassBase; | ||
| 125 | + Type t = c != null ? c.type : Converter.GetTypeByAlias(idx); | ||
| 124 | 126 | if (t == null) | |
| 125 | 127 | { | |
| 126 | 128 | return Exceptions.RaiseTypeError("type expected"); | |
@@ -159,7 +161,7 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx) | |||
| 159 | 161 | { | |
| 160 | 162 | //ManagedType self = GetManagedObject(ob); | |
| 161 | 163 | IntPtr tp = Runtime.PyObject_TYPE(ob); | |
| 162 | - ClassBase cls = (ClassBase)GetManagedObject(tp); | ||
| 164 | + var cls = (ClassBase)GetManagedObject(tp); | ||
| 163 | 165 | ||
| 164 | 166 | if (cls.indexer == null || !cls.indexer.CanGet) | |
| 165 | 167 | { | |
@@ -171,7 +173,7 @@ public static IntPtr mp_subscript(IntPtr ob, IntPtr idx) | |||
| 171 | 173 | // parameters. If so, use it directly, else make a new tuple | |
| 172 | 174 | // with the index arg (method binders expect arg tuples). | |
| 173 | 175 | IntPtr args = idx; | |
| 174 | - bool free = false; | ||
| 176 | + var free = false; | ||
| 175 | 177 | ||
| 176 | 178 | if (!Runtime.PyTuple_Check(idx)) | |
| 177 | 179 | { | |
@@ -205,7 +207,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) | |||
| 205 | 207 | { | |
| 206 | 208 | //ManagedType self = GetManagedObject(ob); | |
| 207 | 209 | IntPtr tp = Runtime.PyObject_TYPE(ob); | |
| 208 | - ClassBase cls = (ClassBase)GetManagedObject(tp); | ||
| 210 | + var cls = (ClassBase)GetManagedObject(tp); | ||
| 209 | 211 | ||
| 210 | 212 | if (cls.indexer == null || !cls.indexer.CanSet) | |
| 211 | 213 | { | |
@@ -217,7 +219,7 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) | |||
| 217 | 219 | // parameters. If so, use it directly, else make a new tuple | |
| 218 | 220 | // with the index arg (method binders expect arg tuples). | |
| 219 | 221 | IntPtr args = idx; | |
| 220 | - bool free = false; | ||
| 222 | + var free = false; | ||
| 221 | 223 | ||
| 222 | 224 | if (!Runtime.PyTuple_Check(idx)) | |
| 223 | 225 | { | |
@@ -233,15 +235,15 @@ public static int mp_ass_subscript(IntPtr ob, IntPtr idx, IntPtr v) | |||
| 233 | 235 | int numOfDefaultArgs = Runtime.PyTuple_Size(defaultArgs); | |
| 234 | 236 | int temp = i + numOfDefaultArgs; | |
| 235 | 237 | IntPtr real = Runtime.PyTuple_New(temp + 1); | |
| 236 | - for (int n = 0; n < i; n++) | ||
| 238 | + for (var n = 0; n < i; n++) | ||
| 237 | 239 | { | |
| 238 | 240 | IntPtr item = Runtime.PyTuple_GetItem(args, n); | |
| 239 | 241 | Runtime.XIncref(item); | |
| 240 | 242 | Runtime.PyTuple_SetItem(real, n, item); | |
| 241 | 243 | } | |
| 242 | 244 | ||
| 243 | 245 | // Add Default Args if needed | |
| 244 | - for (int n = 0; n < numOfDefaultArgs; n++) | ||
| 246 | + for (var n = 0; n < numOfDefaultArgs; n++) | ||
| 245 | 247 | { | |
| 246 | 248 | IntPtr item = Runtime.PyTuple_GetItem(defaultArgs, n); | |
| 247 | 249 | Runtime.XIncref(item); | |
@@ -288,23 +290,23 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) | |||
| 288 | 290 | { | |
| 289 | 291 | //ManagedType self = GetManagedObject(ob); | |
| 290 | 292 | IntPtr tp = Runtime.PyObject_TYPE(ob); | |
| 291 | - ClassBase cb = (ClassBase)GetManagedObject(tp); | ||
| 293 | + var cb = (ClassBase)GetManagedObject(tp); | ||
| 292 | 294 | ||
| 293 | 295 | if (cb.type != typeof(Delegate)) | |
| 294 | 296 | { | |
| 295 | 297 | Exceptions.SetError(Exceptions.TypeError, "object is not callable"); | |
| 296 | 298 | return IntPtr.Zero; | |
| 297 | 299 | } | |
| 298 | 300 | ||
| 299 | - CLRObject co = (CLRObject)ManagedType.GetManagedObject(ob); | ||
| 300 | - Delegate d = co.inst as Delegate; | ||
| 301 | + var co = (CLRObject)GetManagedObject(ob); | ||
| 302 | + var d = co.inst as Delegate; | ||
| 301 | 303 | BindingFlags flags = BindingFlags.Public | | |
| 302 | 304 | BindingFlags.NonPublic | | |
| 303 | 305 | BindingFlags.Instance | | |
| 304 | 306 | BindingFlags.Static; | |
| 305 | 307 | ||
| 306 | 308 | MethodInfo method = d.GetType().GetMethod("Invoke", flags); | |
| 307 | - MethodBinder binder = new MethodBinder(method); | ||
| 309 | + var binder = new MethodBinder(method); | ||
| 308 | 310 | return binder.Invoke(ob, args, kw); | |
| 309 | 311 | } | |
| 310 | 312 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,8 +52,8 @@ static Converter() | |||
| 52 | 52 | /// </summary> | |
| 53 | 53 | internal static Type GetTypeByAlias(IntPtr op) | |
| 54 | 54 | { | |
| 55 | - if ((op == Runtime.PyStringType) || | ||
| 56 | - (op == Runtime.PyUnicodeType)) | ||
| 55 | + if (op == Runtime.PyStringType || | ||
| 56 | + op == Runtime.PyUnicodeType) | ||
| 57 | 57 | { | |
| 58 | 58 | return stringType; | |
| 59 | 59 | } | |
@@ -83,24 +83,24 @@ internal static IntPtr GetPythonTypeByAlias(Type op) | |||
| 83 | 83 | return Runtime.PyUnicodeType; | |
| 84 | 84 | } | |
| 85 | 85 | ||
| 86 | - else if (Runtime.IsPython3 && ((op == int16Type) || | ||
| 87 | - (op == int32Type) || | ||
| 88 | - (op == int64Type))) | ||
| 86 | + else if (Runtime.IsPython3 && (op == int16Type || | ||
| 87 | + op == int32Type || | ||
| 88 | + op == int64Type)) | ||
| 89 | 89 | { | |
| 90 | 90 | return Runtime.PyIntType; | |
| 91 | 91 | } | |
| 92 | 92 | ||
| 93 | - else if ((op == int16Type) || | ||
| 94 | - (op == int32Type)) | ||
| 93 | + else if (op == int16Type || | ||
| 94 | + op == int32Type) | ||
| 95 | 95 | { | |
| 96 | 96 | return Runtime.PyIntType; | |
| 97 | 97 | } | |
| 98 | 98 | else if (op == int64Type) | |
| 99 | 99 | { | |
| 100 | 100 | return Runtime.PyLongType; | |
| 101 | 101 | } | |
| 102 | - else if ((op == doubleType) || | ||
| 103 | - (op == singleType)) | ||
| 102 | + else if (op == doubleType || | ||
| 103 | + op == singleType) | ||
| 104 | 104 | { | |
| 105 | 105 | return Runtime.PyFloatType; | |
| 106 | 106 | } | |
@@ -123,7 +123,7 @@ internal static IntPtr ToPython<T>(T value) | |||
| 123 | 123 | return ToPython(value, typeof(T)); | |
| 124 | 124 | } | |
| 125 | 125 | ||
| 126 | - internal static IntPtr ToPython(Object value, Type type) | ||
| 126 | + internal static IntPtr ToPython(object value, Type type) | ||
| 127 | 127 | { | |
| 128 | 128 | if (value is PyObject) | |
| 129 | 129 | { | |
@@ -144,7 +144,7 @@ internal static IntPtr ToPython(Object value, Type type) | |||
| 144 | 144 | ||
| 145 | 145 | // it the type is a python subclass of a managed type then return the | |
| 146 | 146 | // underlying python object rather than construct a new wrapper object. | |
| 147 | - IPythonDerivedType pyderived = value as IPythonDerivedType; | ||
| 147 | + var pyderived = value as IPythonDerivedType; | ||
| 148 | 148 | if (null != pyderived) | |
| 149 | 149 | { | |
| 150 | 150 | return ClassDerivedObject.ToPython(pyderived); | |
@@ -221,7 +221,9 @@ internal static IntPtr ToPython(Object value, Type type) | |||
| 221 | 221 | foreach (object o in (IEnumerable)value) | |
| 222 | 222 | { | |
| 223 | 223 | using (var p = new PyObject(ToPython(o, o?.GetType()))) | |
| 224 | + { | ||
| 224 | 225 | resultlist.Append(p); | |
| 226 | + } | ||
| 225 | 227 | } | |
| 226 | 228 | Runtime.XIncref(resultlist.Handle); | |
| 227 | 229 | return resultlist.Handle; | |
@@ -237,7 +239,7 @@ internal static IntPtr ToPython(Object value, Type type) | |||
| 237 | 239 | /// In a few situations, we don't have any advisory type information | |
| 238 | 240 | /// when we want to convert an object to Python. | |
| 239 | 241 | /// </summary> | |
| 240 | - internal static IntPtr ToPythonImplicit(Object value) | ||
| 242 | + internal static IntPtr ToPythonImplicit(object value) | ||
| 241 | 243 | { | |
| 242 | 244 | if (value == null) | |
| 243 | 245 | { | |
@@ -266,7 +268,7 @@ internal static bool ToManaged(IntPtr value, Type type, | |||
| 266 | 268 | ||
| 267 | 269 | ||
| 268 | 270 | internal static bool ToManagedValue(IntPtr value, Type obType, | |
| 269 | - out Object result, bool setError) | ||
| 271 | + out object result, bool setError) | ||
| 270 | 272 | { | |
| 271 | 273 | if (obType == typeof(PyObject)) | |
| 272 | 274 | { | |
@@ -290,8 +292,8 @@ internal static bool ToManagedValue(IntPtr value, Type obType, | |||
| 290 | 292 | result = tmp; | |
| 291 | 293 | return true; | |
| 292 | 294 | } | |
| 293 | - string err = "value cannot be converted to {0}"; | ||
| 294 | - err = String.Format(err, obType); | ||
| 295 | + var err = "value cannot be converted to {0}"; | ||
| 296 | + err = string.Format(err, obType); | ||
| 295 | 297 | Exceptions.SetError(Exceptions.TypeError, err); | |
| 296 | 298 | return false; | |
| 297 | 299 | } | |
@@ -474,7 +476,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo | |||
| 474 | 476 | } | |
| 475 | 477 | long ll = (long)Runtime.PyLong_AsLongLong(op); | |
| 476 | 478 | Runtime.XDecref(op); | |
| 477 | - if ((ll == -1) && Exceptions.ErrorOccurred()) | ||
| 479 | + if (ll == -1 && Exceptions.ErrorOccurred()) | ||
| 478 | 480 | { | |
| 479 | 481 | goto overflow; | |
| 480 | 482 | } | |
@@ -487,7 +489,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo | |||
| 487 | 489 | } | |
| 488 | 490 | ||
| 489 | 491 | case TypeCode.Boolean: | |
| 490 | - result = (Runtime.PyObject_IsTrue(value) != 0); | ||
| 492 | + result = Runtime.PyObject_IsTrue(value) != 0; | ||
| 491 | 493 | return true; | |
| 492 | 494 | ||
| 493 | 495 | case TypeCode.Byte: | |
@@ -791,9 +793,9 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo | |||
| 791 | 793 | ||
| 792 | 794 | if (setError) | |
| 793 | 795 | { | |
| 794 | - string format = "'{0}' value cannot be converted to {1}"; | ||
| 796 | + var format = "'{0}' value cannot be converted to {1}"; | ||
| 795 | 797 | string tpName = Runtime.PyObject_GetTypeName(value); | |
| 796 | - string error = String.Format(format, tpName, obType); | ||
| 798 | + string error = string.Format(format, tpName, obType); | ||
| 797 | 799 | Exceptions.SetError(Exceptions.TypeError, error); | |
| 798 | 800 | } | |
| 799 | 801 | ||
@@ -803,20 +805,20 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo | |||
| 803 | 805 | ||
| 804 | 806 | if (setError) | |
| 805 | 807 | { | |
| 806 | - string error = "value too large to convert"; | ||
| 808 | + var error = "value too large to convert"; | ||
| 807 | 809 | Exceptions.SetError(Exceptions.OverflowError, error); | |
| 808 | 810 | } | |
| 809 | 811 | ||
| 810 | 812 | return false; | |
| 811 | 813 | } | |
| 812 | 814 | ||
| 813 | 815 | ||
| 814 | - static void SetConversionError(IntPtr value, Type target) | ||
| 816 | + private static void SetConversionError(IntPtr value, Type target) | ||
| 815 | 817 | { | |
| 816 | 818 | IntPtr ob = Runtime.PyObject_Repr(value); | |
| 817 | 819 | string src = Runtime.GetManagedString(ob); | |
| 818 | 820 | Runtime.XDecref(ob); | |
| 819 | - string error = String.Format("Cannot convert {0} to {1}", src, target); | ||
| 821 | + string error = string.Format("Cannot convert {0} to {1}", src, target); | ||
| 820 | 822 | Exceptions.SetError(Exceptions.TypeError, error); | |
| 821 | 823 | } | |
| 822 | 824 | ||
@@ -844,9 +846,9 @@ private static bool ToArray(IntPtr value, Type obType, out object result, bool s | |||
| 844 | 846 | Array items = Array.CreateInstance(elementType, size); | |
| 845 | 847 | ||
| 846 | 848 | // XXX - is there a better way to unwrap this if it is a real array? | |
| 847 | - for (int i = 0; i < size; i++) | ||
| 849 | + for (var i = 0; i < size; i++) | ||
| 848 | 850 | { | |
| 849 | - Object obj = null; | ||
| 851 | + object obj = null; | ||
| 850 | 852 | IntPtr item = Runtime.PySequence_GetItem(value, i); | |
| 851 | 853 | if (item == IntPtr.Zero) | |
| 852 | 854 | { | |
@@ -899,7 +901,7 @@ private static bool ToEnum(IntPtr value, Type obType, out object result, bool se | |||
| 899 | 901 | ||
| 900 | 902 | if (setError) | |
| 901 | 903 | { | |
| 902 | - string error = "invalid enumeration value"; | ||
| 904 | + var error = "invalid enumeration value"; | ||
| 903 | 905 | Exceptions.SetError(Exceptions.ValueError, error); | |
| 904 | 906 | } | |
| 905 | 907 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,7 +74,7 @@ internal class ObjectOffset | |||
| 74 | 74 | static ObjectOffset() | |
| 75 | 75 | { | |
| 76 | 76 | int size = IntPtr.Size; | |
| 77 | - int n = 0; // Py_TRACE_REFS add two pointers to PyObject_HEAD | ||
| 77 | + var n = 0; // Py_TRACE_REFS add two pointers to PyObject_HEAD | ||
| 78 | 78 | #if Py_DEBUG | |
| 79 | 79 | _ob_next = 0; | |
| 80 | 80 | _ob_prev = 1 * size; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,7 +43,7 @@ public ModuleObject(string name) | |||
| 43 | 43 | IntPtr pyname = Runtime.PyString_FromString(moduleName); | |
| 44 | 44 | IntPtr pyfilename = Runtime.PyString_FromString(filename); | |
| 45 | 45 | IntPtr pydocstring = Runtime.PyString_FromString(docstring); | |
| 46 | - IntPtr pycls = TypeManager.GetTypeHandle(this.GetType()); | ||
| 46 | + IntPtr pycls = TypeManager.GetTypeHandle(GetType()); | ||
| 47 | 47 | Runtime.PyDict_SetItemString(dict, "__name__", pyname); | |
| 48 | 48 | Runtime.PyDict_SetItemString(dict, "__file__", pyfilename); | |
| 49 | 49 | Runtime.PyDict_SetItemString(dict, "__doc__", pydocstring); | |
@@ -318,7 +318,7 @@ public CLRModule() : base("clr") | |||
| 318 | 318 | // import requires the module to pass PyModule_Check. :( | |
| 319 | 319 | if (!hacked) | |
| 320 | 320 | { | |
| 321 | - IntPtr type = this.tpHandle; | ||
| 321 | + IntPtr type = tpHandle; | ||
| 322 | 322 | IntPtr mro = Marshal.ReadIntPtr(type, TypeOffset.tp_mro); | |
| 323 | 323 | IntPtr ext = Runtime.ExtendTuple(mro, Runtime.PyModuleType); | |
| 324 | 324 | Marshal.WriteIntPtr(type, TypeOffset.tp_mro, ext); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -895,7 +895,9 @@ public override bool TryGetMember(GetMemberBinder binder, out object result) | |||
| 895 | 895 | return true; | |
| 896 | 896 | } | |
| 897 | 897 | else | |
| 898 | + { | ||
| 898 | 899 | return base.TryGetMember(binder, out result); | |
| 900 | + } | ||
| 899 | 901 | } | |
| 900 | 902 | ||
| 901 | 903 | public override bool TrySetMember(SetMemberBinder binder, object value) | |
@@ -906,13 +908,18 @@ public override bool TrySetMember(SetMemberBinder binder, object value) | |||
| 906 | 908 | return true; | |
| 907 | 909 | } | |
| 908 | 910 | else | |
| 911 | + { | ||
| 909 | 912 | return base.TrySetMember(binder, value); | |
| 913 | + } | ||
| 910 | 914 | } | |
| 911 | 915 | ||
| 912 | 916 | private void GetArgs(object[] inargs, out PyTuple args, out PyDict kwargs) | |
| 913 | 917 | { | |
| 914 | 918 | int arg_count; | |
| 915 | - for (arg_count = 0; arg_count < inargs.Length && !(inargs[arg_count] is Py.KeywordArguments); ++arg_count) ; | ||
| 919 | + for (arg_count = 0; arg_count < inargs.Length && !(inargs[arg_count] is Py.KeywordArguments); ++arg_count) | ||
| 920 | + { | ||
| 921 | + ; | ||
| 922 | + } | ||
| 916 | 923 | IntPtr argtuple = Runtime.PyTuple_New(arg_count); | |
| 917 | 924 | for (var i = 0; i < arg_count; i++) | |
| 918 | 925 | { | |
@@ -975,7 +982,9 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o | |||
| 975 | 982 | return true; | |
| 976 | 983 | } | |
| 977 | 984 | else | |
| 985 | + { | ||
| 978 | 986 | return base.TryInvokeMember(binder, args, out result); | |
| 987 | + } | ||
| 979 | 988 | } | |
| 980 | 989 | ||
| 981 | 990 | public override bool TryInvoke(InvokeBinder binder, object[] args, out object result) | |
@@ -1003,7 +1012,9 @@ public override bool TryInvoke(InvokeBinder binder, object[] args, out object re | |||
| 1003 | 1012 | return true; | |
| 1004 | 1013 | } | |
| 1005 | 1014 | else | |
| 1015 | + { | ||
| 1006 | 1016 | return base.TryInvoke(binder, args, out result); | |
| 1017 | + } | ||
| 1007 | 1018 | } | |
| 1008 | 1019 | ||
| 1009 | 1020 | public override bool TryConvert(ConvertBinder binder, out object result) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments