diff --git a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Android.cs b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Android.cs index 9d59369d434..65a1f15ad31 100644 --- a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Android.cs +++ b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Android.cs @@ -45,7 +45,7 @@ public override bool Execute () if (LogTaskMessages) { Log.LogMessage (MessageImportance.Low, $" [Output] {nameof (Output)}:"); - foreach (var line in (Output ?? new string [0])) + foreach (var line in (Output ?? Array.Empty ())) Log.LogMessage (MessageImportance.Low, $" {line}"); } diff --git a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Emulator.cs b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Emulator.cs index 170b0bd6c72..4e0c40a8252 100644 --- a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Emulator.cs +++ b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Emulator.cs @@ -45,7 +45,7 @@ public override bool Execute () if (LogTaskMessages) { Log.LogMessage (MessageImportance.Low, $" [Output] {nameof (Output)}:"); - foreach (var line in (Output ?? new string [0])) + foreach (var line in (Output ?? Array.Empty ())) Log.LogMessage (MessageImportance.Low, $" {line}"); } diff --git a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/RunInstrumentationTests.cs b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/RunInstrumentationTests.cs index b8b80aba8b6..4345b514a18 100644 --- a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/RunInstrumentationTests.cs +++ b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/RunInstrumentationTests.cs @@ -49,7 +49,7 @@ public class RunInstrumentationTests : Adb public override bool Execute () { - InstrumentationArguments = InstrumentationArguments ?? new string [0]; + InstrumentationArguments = InstrumentationArguments ?? Array.Empty (); if (string.IsNullOrEmpty (NUnit2TestResultsFile)) { var n = new StringBuilder ("TestResult-").Append (Component); foreach (var c in Path.GetInvalidFileNameChars ()) { diff --git a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Zip.cs b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Zip.cs index 755e1364871..a2c1cbdca69 100644 --- a/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Zip.cs +++ b/build-tools/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/Zip.cs @@ -28,7 +28,7 @@ public override bool Execute () Log.LogMessage (MessageImportance.Low, $"Task {nameof (Zip)}"); Log.LogMessage (MessageImportance.Low, $" {nameof (File)}: {File.ItemSpec}"); Log.LogMessage (MessageImportance.Low, $" {nameof (Entries)}:"); - foreach (var p in Entries ?? new ITaskItem [0]) { + foreach (var p in Entries ?? Array.Empty ()) { Log.LogMessage (MessageImportance.Low, $" {p.ItemSpec}"); } Log.LogMessage (MessageImportance.Low, $" {nameof (Overwrite)}: {Overwrite}"); diff --git a/build-tools/api-merge/Mono.Options-PCL.cs b/build-tools/api-merge/Mono.Options-PCL.cs index 33c1588cf51..3fc9a7ab338 100644 --- a/build-tools/api-merge/Mono.Options-PCL.cs +++ b/build-tools/api-merge/Mono.Options-PCL.cs @@ -18,10 +18,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -42,16 +42,16 @@ // A Getopt::Long-inspired option parsing library for C#. // // NDesk.Options.OptionSet is built upon a key/value table, where the -// key is a option format string and the value is a delegate that is +// key is a option format string and the value is a delegate that is // invoked when the format string is matched. // // Option format strings: -// Regex-like BNF Grammar: +// Regex-like BNF Grammar: // name: .+ // type: [=:] // sep: ( [^{}]+ | '{' .+ '}' )? // aliases: ( name type sep ) ( '|' name type sep )* -// +// // Each '|'-delimited name is an alias for the associated action. If the // format string ends in a '=', it has a required value. If the format // string ends in a ':', it has an optional value. If neither '=' or ':' @@ -97,7 +97,7 @@ // p.Parse (new string[]{"-v", "--v", "/v", "-name=A", "/name", "B", "extra"}); // // The above would parse the argument string array, and would invoke the -// lambda expression three times, setting `verbose' to 3 when complete. +// lambda expression three times, setting `verbose' to 3 when complete. // It would also print out "A" and "B" to standard output. // The returned array would contain the string "extra". // @@ -364,7 +364,7 @@ private void AssertValid (int index) if (c.Option.OptionValueType == OptionValueType.Required && index >= values.Count) throw new OptionException (string.Format ( - c.OptionSet.MessageLocalizer ("Missing required value for option '{0}'."), c.OptionName), + c.OptionSet.MessageLocalizer ("Missing required value for option '{0}'."), c.OptionName), c.OptionName); } @@ -415,7 +415,7 @@ public OptionContext (OptionSet set) set { option = value; } } - public string OptionName { + public string OptionName { get { return name; } set { name = value; } } @@ -519,7 +519,7 @@ public string[] GetNames () public string[] GetValueSeparators () { if (separators == null) - return new string [0]; + return Array.Empty (); return (string[])separators.Clone (); } @@ -672,10 +672,10 @@ static IEnumerable GetArguments (TextReader reader, bool close) for (int i = 0; i < t; i++) { char c = line [i]; - + if (c == '"' || c == '\'') { char end = c; - + for (i++; i < t; i++) { c = line [i]; @@ -889,7 +889,7 @@ public OptionSet Add (string prototype, string description, Action actio { if (action == null) throw new ArgumentNullException ("action"); - Option p = new ActionOption (prototype, description, 1, + Option p = new ActionOption (prototype, description, 1, delegate (OptionValueCollection v) { action (v [0]); }, hidden); @@ -911,7 +911,7 @@ public OptionSet Add (string prototype, string description, OptionAction c.Option.MaxValueCount) { throw new OptionException (localizer (string.Format ( - "Error: Found {0} option values when expecting {1}.", + "Error: Found {0} option values when expecting {1}.", c.OptionValues.Count, c.Option.MaxValueCount)), c.OptionName); } @@ -1301,7 +1301,7 @@ bool WriteOptionPrototype (TextWriter o, Option p, ref int written) Write (o, ref written, names [0]); } - for (i = GetNextOptionIndex (names, i + 1); + for (i = GetNextOptionIndex (names, i + 1); i < names.Length; i = GetNextOptionIndex (names, i + 1)) { Write (o, ref written, ", "); Write (o, ref written, names [i].Length == 1 ? "-" : "--"); @@ -1314,7 +1314,7 @@ bool WriteOptionPrototype (TextWriter o, Option p, ref int written) Write (o, ref written, localizer ("[")); } Write (o, ref written, localizer ("=" + GetArgumentName (0, p.MaxValueCount, p.Description))); - string sep = p.ValueSeparators != null && p.ValueSeparators.Length > 0 + string sep = p.ValueSeparators != null && p.ValueSeparators.Length > 0 ? p.ValueSeparators [0] : " "; for (int c = 1; c < p.MaxValueCount; ++c) { diff --git a/build-tools/jnienv-gen/Mono.Options-PCL.cs b/build-tools/jnienv-gen/Mono.Options-PCL.cs index 33c1588cf51..3fc9a7ab338 100644 --- a/build-tools/jnienv-gen/Mono.Options-PCL.cs +++ b/build-tools/jnienv-gen/Mono.Options-PCL.cs @@ -18,10 +18,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -42,16 +42,16 @@ // A Getopt::Long-inspired option parsing library for C#. // // NDesk.Options.OptionSet is built upon a key/value table, where the -// key is a option format string and the value is a delegate that is +// key is a option format string and the value is a delegate that is // invoked when the format string is matched. // // Option format strings: -// Regex-like BNF Grammar: +// Regex-like BNF Grammar: // name: .+ // type: [=:] // sep: ( [^{}]+ | '{' .+ '}' )? // aliases: ( name type sep ) ( '|' name type sep )* -// +// // Each '|'-delimited name is an alias for the associated action. If the // format string ends in a '=', it has a required value. If the format // string ends in a ':', it has an optional value. If neither '=' or ':' @@ -97,7 +97,7 @@ // p.Parse (new string[]{"-v", "--v", "/v", "-name=A", "/name", "B", "extra"}); // // The above would parse the argument string array, and would invoke the -// lambda expression three times, setting `verbose' to 3 when complete. +// lambda expression three times, setting `verbose' to 3 when complete. // It would also print out "A" and "B" to standard output. // The returned array would contain the string "extra". // @@ -364,7 +364,7 @@ private void AssertValid (int index) if (c.Option.OptionValueType == OptionValueType.Required && index >= values.Count) throw new OptionException (string.Format ( - c.OptionSet.MessageLocalizer ("Missing required value for option '{0}'."), c.OptionName), + c.OptionSet.MessageLocalizer ("Missing required value for option '{0}'."), c.OptionName), c.OptionName); } @@ -415,7 +415,7 @@ public OptionContext (OptionSet set) set { option = value; } } - public string OptionName { + public string OptionName { get { return name; } set { name = value; } } @@ -519,7 +519,7 @@ public string[] GetNames () public string[] GetValueSeparators () { if (separators == null) - return new string [0]; + return Array.Empty (); return (string[])separators.Clone (); } @@ -672,10 +672,10 @@ static IEnumerable GetArguments (TextReader reader, bool close) for (int i = 0; i < t; i++) { char c = line [i]; - + if (c == '"' || c == '\'') { char end = c; - + for (i++; i < t; i++) { c = line [i]; @@ -889,7 +889,7 @@ public OptionSet Add (string prototype, string description, Action actio { if (action == null) throw new ArgumentNullException ("action"); - Option p = new ActionOption (prototype, description, 1, + Option p = new ActionOption (prototype, description, 1, delegate (OptionValueCollection v) { action (v [0]); }, hidden); @@ -911,7 +911,7 @@ public OptionSet Add (string prototype, string description, OptionAction c.Option.MaxValueCount) { throw new OptionException (localizer (string.Format ( - "Error: Found {0} option values when expecting {1}.", + "Error: Found {0} option values when expecting {1}.", c.OptionValues.Count, c.Option.MaxValueCount)), c.OptionName); } @@ -1301,7 +1301,7 @@ bool WriteOptionPrototype (TextWriter o, Option p, ref int written) Write (o, ref written, names [0]); } - for (i = GetNextOptionIndex (names, i + 1); + for (i = GetNextOptionIndex (names, i + 1); i < names.Length; i = GetNextOptionIndex (names, i + 1)) { Write (o, ref written, ", "); Write (o, ref written, names [i].Length == 1 ? "-" : "--"); @@ -1314,7 +1314,7 @@ bool WriteOptionPrototype (TextWriter o, Option p, ref int written) Write (o, ref written, localizer ("[")); } Write (o, ref written, localizer ("=" + GetArgumentName (0, p.MaxValueCount, p.Description))); - string sep = p.ValueSeparators != null && p.ValueSeparators.Length > 0 + string sep = p.ValueSeparators != null && p.ValueSeparators.Length > 0 ? p.ValueSeparators [0] : " "; for (int c = 1; c < p.MaxValueCount; ++c) { diff --git a/build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/Git.cs b/build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/Git.cs index 9860ee67a4c..1804655bd7f 100644 --- a/build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/Git.cs +++ b/build-tools/xa-prep-tasks/Xamarin.Android.BuildTools.PrepTasks/Git.cs @@ -52,7 +52,7 @@ public override bool Execute () if (LogTaskMessages) { Log.LogMessage (MessageImportance.Low, $" [Output] {nameof (Output)}:"); - foreach (var line in (Output ?? new string [0])) + foreach (var line in (Output ?? Array.Empty ())) Log.LogMessage (MessageImportance.Low, $" {line}"); } diff --git a/src/Mono.Android.Export/Mono.CodeGeneration/CodeClass.cs b/src/Mono.Android.Export/Mono.CodeGeneration/CodeClass.cs index 8579f267299..60b8c534572 100644 --- a/src/Mono.Android.Export/Mono.CodeGeneration/CodeClass.cs +++ b/src/Mono.Android.Export/Mono.CodeGeneration/CodeClass.cs @@ -6,10 +6,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -45,17 +45,17 @@ internal class CodeClass CodeBuilder instanceInit; CodeBuilder classInit; int varId; - + public CodeClass (ModuleBuilder mb, string name) : this (mb, name, TypeAttributes.Public, typeof(object)) { } - + public CodeClass (ModuleBuilder mb, string name, Type baseType, params Type[] interfaces) : this (mb, name, TypeAttributes.Public, baseType, interfaces) { } - + public CodeClass (ModuleBuilder mb, string name, TypeAttributes attr, Type baseType, params Type[] interfaces) { typeBuilder = mb.DefineType (name, attr, baseType, interfaces); @@ -66,7 +66,7 @@ public CodeClass (ModuleBuilder mb, string name, TypeAttributes attr, Type baseT public CodeCustomAttribute CreateCustomAttribute (Type attributeType) { return CreateCustomAttribute (attributeType, - Type.EmptyTypes, new object [0], new string [0], new object [0]); + Type.EmptyTypes, Array.Empty (), Array.Empty (), Array.Empty ()); } public CodeCustomAttribute CreateCustomAttribute (Type attributeType, Type [] ctorArgTypes, object [] ctorArgs, string [] namedArgFieldNames, object [] namedArgValues) @@ -107,35 +107,35 @@ public CodeMethod CreateMethod (string name, Type returnType, params Type[] para methods.Add (met); return met; } - + public CodeMethod CreateVirtualMethod (string name, Type returnType, params Type[] parameterTypes) { CodeMethod met = new CodeMethod (this, GetMethodName (name), MethodAttributes.Public | MethodAttributes.Virtual, returnType, parameterTypes); methods.Add (met); return met; } - + public CodeMethod CreateStaticMethod (string name, Type returnType, params Type[] parameterTypes) { CodeMethod met = new CodeMethod (this, GetMethodName (name), MethodAttributes.Public | MethodAttributes.Static, returnType, parameterTypes); methods.Add (met); return met; } - + public CodeMethod CreateMethod (string name, MethodAttributes attributes, Type returnType, params Type[] parameterTypes) { CodeMethod met = new CodeMethod (this, GetMethodName (name), attributes, returnType, parameterTypes); methods.Add (met); return met; } - + public CodeMethod GetDefaultConstructor () { if (ctor != null) return ctor; ctor = CreateConstructor (MethodAttributes.Public, Type.EmptyTypes); return ctor; } - + public CodeMethod CreateConstructor (params Type[] parameters) { return CreateConstructor (MethodAttributes.Private, parameters); @@ -150,7 +150,7 @@ public CodeMethod CreateConstructor (MethodAttributes attributes, params Type[] ctor.CodeBuilder.CurrentBlock.Add (cb.CurrentBlock); return ctor; } - + public CodeMethod GetStaticConstructor () { if (cctor != null) return cctor; @@ -160,18 +160,18 @@ public CodeMethod GetStaticConstructor () cctor.CodeBuilder.CurrentBlock.Add (cb.CurrentBlock); return cctor; } - + public CodeMethod ImplementMethod (Type baseType, string methodName) { MethodInfo basem = baseType.GetMethod (methodName); return ImplementMethod (baseType, basem); } - + public CodeMethod ImplementMethod (MethodInfo basem) { return ImplementMethod (basem.DeclaringType, basem); } - + public CodeMethod ImplementMethod (Type baseType, MethodInfo basem) { ParameterInfo[] pinfos = basem.GetParameters (); @@ -184,22 +184,22 @@ public CodeMethod ImplementMethod (Type baseType, MethodInfo basem) methods.Add (met); return met; } - + public CodeFieldReference DefineField (string name, Type type, params CodeCustomAttribute [] customAttributes) { return DefineField (GetFieldName (name), type, FieldAttributes.Public, null, customAttributes); } - + public CodeFieldReference DefineStaticField (CodeExpression initialValue, params CodeCustomAttribute [] customAttributes) { return DefineField (GetFieldName (null), initialValue.GetResultType(), FieldAttributes.Public | FieldAttributes.Static, initialValue, customAttributes); } - + public CodeFieldReference DefineStaticField (string name, Type type, CodeExpression initialValue, params CodeCustomAttribute [] customAttributes) { return DefineField (GetFieldName (name), type, FieldAttributes.Public | FieldAttributes.Static, initialValue, customAttributes); } - + public CodeFieldReference DefineField (string name, Type type, FieldAttributes attrs, CodeExpression initialValue, params CodeCustomAttribute [] customAttributes) { FieldBuilder fb = typeBuilder.DefineField (GetFieldName (name), type, attrs); @@ -212,51 +212,51 @@ public CodeFieldReference DefineField (string name, Type type, FieldAttributes a fr = new CodeFieldReference (fb); else fr = new CodeFieldReference (new CodeArgumentReference (TypeBuilder, 0, "this"), fb); - + if (null != (object) initialValue) { - CodeBuilder cb = (attrs & FieldAttributes.Static) == 0 ? GetInstanceInitBuilder () : GetClassInitBuilder (); + CodeBuilder cb = (attrs & FieldAttributes.Static) == 0 ? GetInstanceInitBuilder () : GetClassInitBuilder (); cb.Assign (fr, initialValue); } return fr; } - + public TypeBuilder TypeBuilder { get { return typeBuilder; } - } - + } + private CodeBuilder GetInstanceInitBuilder () { if (instanceInit != null) return instanceInit; instanceInit = new CodeBuilder (this); return instanceInit; } - + private CodeBuilder GetClassInitBuilder () { if (classInit != null) return classInit; classInit = new CodeBuilder (this); return classInit; } - + private string GetFieldName (string name) { if (name == null) return "__field_" + (varId++); else return name; } - + private string GetMethodName (string name) { if (name == null) return "__Method_" + (varId++); else return name; } - + private string GetPropertyName (string name) { if (name == null) return "__Property_" + (varId++); else return name; } - + public string PrintCode () { StringWriter sw = new StringWriter (); @@ -264,7 +264,7 @@ public string PrintCode () PrintCode (cw); return sw.ToString (); } - + public void PrintCode (CodeWriter cw) { for (int n=0; n 0) { if (!dots) cw.Write (" : "); else cw.Write (", "); @@ -293,9 +293,9 @@ public void PrintCode (CodeWriter cw) cw.Write (interfaces[n].ToString ()); } } - + cw.EndLine ().WriteLineInd ("{"); - + foreach (FieldInfo f in fields) { cw.BeginLine (); ArrayList atts = (ArrayList) fieldAttributes [f]; @@ -306,9 +306,9 @@ public void PrintCode (CodeWriter cw) cw.Write (f.FieldType.Name + " "); cw.Write (f.Name + ";"); cw.EndLine (); - cw.WriteLine (""); + cw.WriteLine (""); } - + for (int n=0; n 0) cw.WriteLine (""); @@ -322,23 +322,23 @@ public void PrintCode (CodeWriter cw) } cw.WriteLineUnind ("}"); } - + public Type CreateType () { if (ctor == null) ctor = GetDefaultConstructor (); - + foreach (CodeProperty prop in properties) prop.Generate (); foreach (CodeMethod met in methods) met.Generate (); - + Type t = typeBuilder.CreateType (); - + foreach (CodeMethod met in methods) met.UpdateMethodBase (t); - + foreach (CodeProperty prop in properties) prop.UpdatePropertyInfo (t); diff --git a/src/Mono.Android.Export/Mono.CodeGeneration/CodeCustomAttribute.cs b/src/Mono.Android.Export/Mono.CodeGeneration/CodeCustomAttribute.cs index acc9fc2b9ff..41d574cdbf7 100644 --- a/src/Mono.Android.Export/Mono.CodeGeneration/CodeCustomAttribute.cs +++ b/src/Mono.Android.Export/Mono.CodeGeneration/CodeCustomAttribute.cs @@ -6,10 +6,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -31,7 +31,7 @@ internal class CodeCustomAttribute { public static CodeCustomAttribute Create (Type attributeType) { - return Create (attributeType, Type.EmptyTypes, new object [0], new string [0], new object [0]); + return Create (attributeType, Type.EmptyTypes, Array.Empty (), Array.Empty (), Array.Empty ()); } public static CodeCustomAttribute Create (Type attributeType, Type [] ctorArgTypes, object [] ctorArgs, string [] namedArgNames, object [] namedArgValues) @@ -120,7 +120,7 @@ public string PrintCode () PrintCode (cw); return sw.ToString (); } - + public void PrintCode (CodeWriter cw) { cw.Write ("[").Write (type.Name).Write ("("); diff --git a/src/Mono.Android.Export/Mono.CodeGeneration/CodeMethod.cs b/src/Mono.Android.Export/Mono.CodeGeneration/CodeMethod.cs index 32a49880b0f..230dce1bdcb 100644 --- a/src/Mono.Android.Export/Mono.CodeGeneration/CodeMethod.cs +++ b/src/Mono.Android.Export/Mono.CodeGeneration/CodeMethod.cs @@ -6,10 +6,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -41,18 +41,18 @@ internal class CodeMethod Type[] parameterTypes; ArrayList customAttributes = new ArrayList (); CodeClass cls; - + internal static CodeMethod DefineMethod (CodeClass cls, string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) { return new CodeMethod (cls, name, attributes, returnType, parameterTypes); } - + public static CodeMethod DefineConstructor (CodeClass cls, MethodAttributes attributes, Type[] parameterTypes) { return new CodeMethod (cls, attributes, parameterTypes); } - - internal CodeMethod (CodeClass cls, string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) + + internal CodeMethod (CodeClass cls, string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) { this.cls = cls; this.typeBuilder = cls.TypeBuilder; @@ -60,63 +60,63 @@ internal CodeMethod (CodeClass cls, string name, MethodAttributes attributes, Ty this.attributes = attributes; this.returnType = returnType; this.parameterTypes = parameterTypes; - + methodBase = typeBuilder.DefineMethod (name, attributes, returnType, parameterTypes); builder = new CodeBuilder (cls); } - - CodeMethod (CodeClass cls, MethodAttributes attributes, Type[] parameterTypes) + + CodeMethod (CodeClass cls, MethodAttributes attributes, Type[] parameterTypes) { this.cls = cls; this.typeBuilder = cls.TypeBuilder; this.attributes = attributes; this.parameterTypes = parameterTypes; this.name = typeBuilder.Name; - + methodBase = typeBuilder.DefineConstructor (attributes, CallingConventions.Standard, parameterTypes); builder = new CodeBuilder (cls); } - + public TypeBuilder DeclaringType { get { return typeBuilder; } } - + public MethodInfo MethodInfo { get { return methodBase as MethodInfo; } } - + public MethodBase MethodBase { get { return methodBase; } } - + public string Name { get { return name; } } - + public MethodAttributes Attributes { get { return attributes; } } - + public Type ReturnType { get { return returnType; } } - + public Type[] ParameterTypes { get { return parameterTypes; } } - + public CodeBuilder CodeBuilder { get { return builder; } } - + public bool IsStatic { get { return (attributes & MethodAttributes.Static) != 0; } @@ -125,13 +125,13 @@ public bool IsStatic public CodeCustomAttribute CreateCustomAttribute (Type attributeType) { return CreateCustomAttribute (attributeType, - Type.EmptyTypes, new object [0]); + Type.EmptyTypes, Array.Empty ()); } public CodeCustomAttribute CreateCustomAttribute (Type attributeType, Type [] ctorArgTypes, object [] ctorArgs) { return CreateCustomAttribute (attributeType, - ctorArgTypes, ctorArgs, new string [0], new object [0]); + ctorArgTypes, ctorArgs, Array.Empty (), Array.Empty ()); } public CodeCustomAttribute CreateCustomAttribute (Type attributeType, Type [] ctorArgTypes, object [] ctorArgs, string [] namedArgFieldNames, object [] namedArgValues) @@ -166,7 +166,7 @@ public string PrintCode () PrintCode (cw); return sw.ToString (); } - + public virtual void PrintCode (CodeWriter cp) { cp.BeginLine (); @@ -185,12 +185,12 @@ public virtual void PrintCode (CodeWriter cp) cp.Write (")"); cp.EndLine (); cp.WriteLineInd ("{"); - + builder.PrintCode (cp); - + cp.WriteLineUnind ("}"); } - + public CodeArgumentReference GetArg (int n) { if (n < 0 || n >= parameterTypes.Length) @@ -199,21 +199,21 @@ public CodeArgumentReference GetArg (int n) int narg = IsStatic ? n : n + 1; return new CodeArgumentReference (parameterTypes[n], narg, "arg" + n); } - + public CodeArgumentReference GetThis () { if (IsStatic) throw new InvalidOperationException ("'this' not available in static methods"); - + return new CodeArgumentReference (DeclaringType, 0, "this"); } - + public void Generate () { ILGenerator gen = methodBase is MethodInfo ? ((MethodBuilder)methodBase).GetILGenerator() : ((ConstructorBuilder)methodBase).GetILGenerator(); Generate (gen); } - + internal void Generate (ILGenerator gen) { Label returnLabel = gen.DefineLabel (); @@ -222,7 +222,7 @@ internal void Generate (ILGenerator gen) gen.MarkLabel(returnLabel); gen.Emit(OpCodes.Ret); } - + public void UpdateMethodBase (Type type) { if (methodBase is MethodInfo) diff --git a/src/Mono.Android.Export/Mono.CodeGeneration/CodeProperty.cs b/src/Mono.Android.Export/Mono.CodeGeneration/CodeProperty.cs index a822fdc9891..43b5c991f76 100644 --- a/src/Mono.Android.Export/Mono.CodeGeneration/CodeProperty.cs +++ b/src/Mono.Android.Export/Mono.CodeGeneration/CodeProperty.cs @@ -6,10 +6,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -43,13 +43,13 @@ internal class CodeProperty Type[] parameterTypes; ArrayList customAttributes = new ArrayList (); CodeClass cls; - + internal static CodeProperty DefineProperty (CodeClass cls, string name, PropertyAttributes attributes, MethodAttributes methodAttributes, Type returnType, Type[] parameterTypes) { return new CodeProperty (cls, name, attributes, methodAttributes, returnType, parameterTypes); } - - internal CodeProperty (CodeClass cls, string name, PropertyAttributes attributes, MethodAttributes methodAttributes, Type returnType, Type[] parameterTypes) + + internal CodeProperty (CodeClass cls, string name, PropertyAttributes attributes, MethodAttributes methodAttributes, Type returnType, Type[] parameterTypes) { this.cls = cls; this.typeBuilder = cls.TypeBuilder; @@ -58,7 +58,7 @@ internal CodeProperty (CodeClass cls, string name, PropertyAttributes attributes this.methodAttributes = methodAttributes; this.returnType = returnType; this.parameterTypes = parameterTypes; - + PropertyBuilder pb = typeBuilder.DefineProperty (name, attributes, returnType, parameterTypes); pb.SetGetMethod (typeBuilder.DefineMethod ("get_" + name, methodAttributes, CallingConventions.Standard, returnType, Type.EmptyTypes)); pb.SetSetMethod (typeBuilder.DefineMethod ("set_" + name, methodAttributes, CallingConventions.Standard, typeof (void), new Type [] {returnType})); @@ -66,37 +66,37 @@ internal CodeProperty (CodeClass cls, string name, PropertyAttributes attributes set_builder = new CodeBuilder (cls); propertyInfo = pb; } - + public TypeBuilder DeclaringType { get { return typeBuilder; } } - + public PropertyBuilder PropertyBuilder { get { return propertyInfo as PropertyBuilder; } } - + public string Name { get { return name; } } - + public PropertyAttributes Attributes { get { return attributes; } } - + public Type ReturnType { get { return returnType; } } - + public Type[] ParameterTypes { get { return parameterTypes; } } - + public CodeBuilder CodeBuilderGet { get { return get_builder; } @@ -120,13 +120,13 @@ public bool IsPublic public CodeCustomAttribute CreateCustomAttribute (Type attributeType) { return CreateCustomAttribute (attributeType, - Type.EmptyTypes, new object [0]); + Type.EmptyTypes, Array.Empty ()); } public CodeCustomAttribute CreateCustomAttribute (Type attributeType, Type [] ctorArgTypes, object [] ctorArgs) { return CreateCustomAttribute (attributeType, - ctorArgTypes, ctorArgs, new string [0], new object [0]); + ctorArgTypes, ctorArgs, Array.Empty (), Array.Empty ()); } public CodeCustomAttribute CreateCustomAttribute (Type attributeType, Type [] ctorArgTypes, object [] ctorArgs, string [] namedArgFieldNames, object [] namedArgValues) @@ -158,7 +158,7 @@ public string PrintCode () PrintCode (cw); return sw.ToString (); } - + public void PrintCode (CodeWriter cp) { cp.BeginLine (); @@ -190,7 +190,7 @@ public void PrintCode (CodeWriter cp) cp.WriteLine ("}"); cp.WriteLineUnind ("}"); } - + public CodeArgumentReference GetArg (int n) { if (n < 0 || n >= parameterTypes.Length) @@ -199,15 +199,15 @@ public CodeArgumentReference GetArg (int n) int narg = IsStatic ? n : n + 1; return new CodeArgumentReference (parameterTypes[n], narg, "arg" + n); } - + public CodeArgumentReference GetThis () { if (IsStatic) throw new InvalidOperationException ("'this' not available in static methods"); - + return new CodeArgumentReference (DeclaringType, 0, "this"); } - + public void Generate () { ILGenerator gen; @@ -236,7 +236,7 @@ public void Generate () gen.Emit (OpCodes.Ret); } } - + public void UpdatePropertyInfo (Type type) { propertyInfo = type.GetProperty (propertyInfo.Name, parameterTypes); diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/IntentFilterAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/IntentFilterAttribute.Partial.cs index 07527c73d52..381ba53c64d 100644 --- a/src/Xamarin.Android.Build.Tasks/Mono.Android/IntentFilterAttribute.Partial.cs +++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/IntentFilterAttribute.Partial.cs @@ -88,7 +88,7 @@ public XElement ToElement (string packageName) ToAttribute ("Priority", Priority), ToAttribute ("AutoVerify", _AutoVerify), Actions.Select (a => new XElement ("action", new XAttribute (android + "name", ReplacePackage (a, packageName)))), - (Categories ?? new string[0]).Select (c => new XElement ("category", new XAttribute (android + "name", ReplacePackage (c, packageName)))), + (Categories ?? Array.Empty ()).Select (c => new XElement ("category", new XAttribute (android + "name", ReplacePackage (c, packageName)))), GetData (packageName)); AndroidResource.UpdateXmlResource (r); return r; @@ -127,7 +127,7 @@ IEnumerable GetData (string packageName) Func toPort = v => ToAttribute ("DataPort", ReplacePackage (v, packageName)); Func toScheme = v => ToAttribute ("DataScheme", ReplacePackage (v, packageName)); Func, string, XElement> toData = (f, s) => string.IsNullOrEmpty (s) ? null : new XElement ("data", f (s)); - var empty = new string [0]; + var empty = Array.Empty (); var dataList = Enumerable.Empty () .Concat ((DataHosts ?? empty).Select (p => toData (toHost, p))) .Concat ((DataMimeTypes ?? empty).Select (p => toData (toMimeType, p))) diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesLibraryAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesLibraryAttribute.Partial.cs index 989efcfd5ee..e7d85a35bf3 100644 --- a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesLibraryAttribute.Partial.cs +++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesLibraryAttribute.Partial.cs @@ -46,7 +46,7 @@ public static IEnumerable FromCustomAttributeProvider (ICu extra = new[]{"Name", "Required"}; } else { self = new UsesLibraryAttribute (); - extra = new string[0]; + extra = Array.Empty (); } self.specified = mapping.Load (self, attr); diff --git a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesPermissionAttribute.Partial.cs b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesPermissionAttribute.Partial.cs index 1870440dbb0..488e6b085cd 100644 --- a/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesPermissionAttribute.Partial.cs +++ b/src/Xamarin.Android.Build.Tasks/Mono.Android/UsesPermissionAttribute.Partial.cs @@ -11,7 +11,7 @@ namespace Android.App { partial class UsesPermissionAttribute { - + int _MaxSdkVersion; static ManifestDocumentElement mapping = new ManifestDocumentElement ("uses-permission") { @@ -42,7 +42,7 @@ public static IEnumerable FromCustomAttributeProvider ( extra = new[]{"Name"}; } else { self = new UsesPermissionAttribute (); - extra = new string [0]; + extra = Array.Empty (); } self.specified = mapping.Load (self, attr); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs index be43b151a0e..045675191ae 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs @@ -281,7 +281,7 @@ public override bool RunTask () Aot.TryGetSequencePointsMode (AndroidSequencePointsMode, out sequencePointsMode); var outputFiles = new List (); - uncompressedFileExtensions = UncompressedFileExtensions?.Split (new char [] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries) ?? new string [0]; + uncompressedFileExtensions = UncompressedFileExtensions?.Split (new char [] { ';', ',' }, StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty (); existingEntries.Clear (); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/CheckDuplicateJavaLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/CheckDuplicateJavaLibraries.cs index 89e3b4ffb57..1a0c1919177 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/CheckDuplicateJavaLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/CheckDuplicateJavaLibraries.cs @@ -17,7 +17,7 @@ public class CheckDuplicateJavaLibraries : AndroidTask public override string TaskPrefix => "CDJ"; public ITaskItem [] JavaSourceFiles { get; set; } - public ITaskItem[] JavaLibraries { get; set; } + public ITaskItem[] JavaLibraries { get; set; } public ITaskItem[] LibraryProjectJars { get; set; } public override bool RunTask () @@ -27,7 +27,7 @@ public override bool RunTask () jarFiles = jarFiles.Concat (JavaLibraries); else if (JavaLibraries != null) jarFiles = JavaLibraries; - var jarFilePaths = (LibraryProjectJars ?? new ITaskItem [0]).Concat (jarFiles ?? new ITaskItem [0]).Select (j => j.ItemSpec); + var jarFilePaths = (LibraryProjectJars ?? Array.Empty ()).Concat (jarFiles ?? Array.Empty ()).Select (j => j.ItemSpec); // Remove duplicate identical jars by name, size and content, and reject any jars that conflicts by name (i.e. different content). var jars = MonoAndroidHelper.DistinctFilesByContent (jarFilePaths).ToArray (); @@ -36,7 +36,7 @@ public override bool RunTask () Log.LogCodedError ("XA1014", Properties.Resources.XA1014, String.Join (", ", dups.ToArray ())); return false; } - + return true; } } diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs index 973d180ece8..66f14c7960f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs @@ -372,7 +372,7 @@ bool CreateJavaSources (IEnumerable javaTypes, TypeDefinitionCac endLineNumber: 0, endColumnNumber: 0, message: xae.MessageWithoutCode, - messageArgs: new object [0] + messageArgs: Array.Empty () ); } catch (DirectoryNotFoundException ex) { ok = false; diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs index bdd59ca4aa3..9e89f9ef496 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GeneratePackageManagerJava.cs @@ -188,7 +188,7 @@ void AddEnvironment () if (!Aot.TryGetSequencePointsMode (AndroidSequencePointsMode, out sequencePointsMode)) sequencePointsMode = SequencePointsMode.None; - foreach (ITaskItem env in Environments ?? new TaskItem[0]) { + foreach (ITaskItem env in Environments ?? Array.Empty ()) { foreach (string line in File.ReadLines (env.ItemSpec)) { var lineToWrite = line; if (lineToWrite.StartsWith ("MONO_LOG_LEVEL=", StringComparison.Ordinal)) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/GetConvertedJavaLibraries.cs b/src/Xamarin.Android.Build.Tasks/Tasks/GetConvertedJavaLibraries.cs index 334b17165f0..cb957840b89 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/GetConvertedJavaLibraries.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/GetConvertedJavaLibraries.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Linq; using Microsoft.Build.Framework; @@ -20,7 +21,7 @@ public class GetConvertedJavaLibraries : AndroidTask public override bool RunTask () { ConvertedFilesToBeGenerated = - (JarsToConvert ?? new string [0]).Select ( + (JarsToConvert ?? Array.Empty ()).Select ( j => Path.Combine (OutputJackDirectory, Files.HashString (j) + Path.ChangeExtension (Path.GetFileName (j), Extension))) .ToArray (); diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs index f9c30215e05..7c55675ffe6 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs @@ -17,7 +17,7 @@ public class Lint : AndroidToolTask public override string TaskPrefix => "LNT"; // we need to check for lint based errors and warnings - // Sample Manifest Warnings note the ^ and ~ differences.... + // Sample Manifest Warnings note the ^ and ~ differences.... // //AndroidManifest.xml:19: Warning: tag appears after tag [ManifestOrder] // @@ -61,8 +61,8 @@ public class Lint : AndroidToolTask public string JavaSdkPath { get; set; } /// - /// Location of an xml config files used to - /// determine whether issues are enabled or disabled + /// Location of an xml config files used to + /// determine whether issues are enabled or disabled /// for lint. Normally named lint.xml however it can /// be any file using the AndroidLintConfig build action /// @@ -109,7 +109,7 @@ public class Lint : AndroidToolTask /// /// Add the given folders (or paths) as a resource - /// directories for the project. + /// directories for the project. /// /// An array of ITaskItems containing the resource directories. public ITaskItem[] ResourceDirectories {get; set;} @@ -123,14 +123,14 @@ public class Lint : AndroidToolTask /// /// Add the given folder (or path) as a class directories - /// for the project. + /// for the project. /// /// An array of ITaskItems containing class directories. public ITaskItem[] ClassDirectories {get; set;} /// /// Add the given folders (or jar files, or paths) as - /// class directories for the project. + /// class directories for the project. /// /// An array of ITaskItems containing the class path jars. public ITaskItem[] ClassPathJars {get; set;} @@ -155,16 +155,16 @@ public class Lint : AndroidToolTask public Lint () { - ResourceDirectories = new ITaskItem[0]; - SourceDirectories = new ITaskItem[0]; - ClassDirectories = new ITaskItem[0]; - ClassPathJars = new ITaskItem[0]; - LibraryDirectories = new ITaskItem[0]; - LibraryJars = new ITaskItem[0]; + ResourceDirectories = Array.Empty (); + SourceDirectories = Array.Empty (); + ClassDirectories = Array.Empty (); + ClassPathJars = Array.Empty (); + LibraryDirectories = Array.Empty (); + LibraryJars = Array.Empty (); } static readonly Dictionary DisabledIssuesByVersion = new Dictionary () { - // We need to hard code this test in because Lint will issue an Error + // We need to hard code this test in because Lint will issue an Error // if android:debuggable appears in the manifest. We actually need that // in debug mode. It seems the android tools do some magic to // decide if its needed or not. @@ -333,7 +333,7 @@ void GenerateErrorOrWarning () if (type == "Warning") { if (!string.IsNullOrEmpty (file)) Log.LogWarning ("", "XA0102", "", file, line, column, 0, 0, text.Replace ("Warning:", "")); - else + else Log.LogCodedWarning ("XA0102", text.Replace ("Warning:", "")); } else { if (!string.IsNullOrEmpty (file)) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs index 41d76c59755..475e7aed14f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/ResolveLibraryProjectImports.cs @@ -46,7 +46,7 @@ public class ResolveLibraryProjectImports : AndroidTask [Output] public ITaskItem [] Jars { get; set; } - + [Output] public ITaskItem [] ResolvedAssetDirectories { get; set; } @@ -115,7 +115,7 @@ public override bool RunTask () new XElement ("ResolvedResourceDirectories", ResolvedResourceDirectories.ToXElements ("ResolvedResourceDirectory", knownMetadata) ), - new XElement ("ResolvedAssetDirectories", + new XElement ("ResolvedAssetDirectories", ResolvedAssetDirectories.ToXElements ("ResolvedAssetDirectory", knownMetadata)), new XElement ("ResolvedEnvironmentFiles", ResolvedEnvironmentFiles.ToXElements ("ResolvedEnvironmentFile", knownMetadata)), @@ -327,7 +327,7 @@ public override bool RunTask () } } } - foreach (var aarFile in AarLibraries ?? new ITaskItem[0]) { + foreach (var aarFile in AarLibraries ?? Array.Empty ()) { if (!File.Exists (aarFile.ItemSpec)) continue; string aarIdentityName = Path.GetFileName (aarFile.ItemSpec); @@ -370,7 +370,7 @@ public override bool RunTask () // temporarily extracted directory will look like: // _lp_/[aarFile] - + using (var zip = MonoAndroidHelper.ReadZipFile (aarFile.ItemSpec)) { try { updated |= Files.ExtractAll (zip, importsDir, modifyCallback: (entryFullName) => { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs index 72f0ec409b9..a8c9fa9161f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidUpdateResourcesTest.cs @@ -854,7 +854,7 @@ public class Foo { "res/raw/test.txt"); Assert.IsNotNull (rawContentBuildOne, "res/raw/test.txt should have been in the apk "); - string txt = Encoding.UTF8.GetString (rawContentBuildOne ?? new byte[0]); + string txt = Encoding.UTF8.GetString (rawContentBuildOne ?? Array.Empty ()); StringAssert.Contains ("Test Build 1", txt, $"res/raw/test.txt should have been 'Test Build 1' not {txt}"); Assert.IsNotNull (ZipHelper.ReadFileFromZip (apk, "res/raw/test2.txt"), "res/raw/test2.txt should have been in the apk."); theme.TextContent = () => @" @@ -878,7 +878,7 @@ public class Foo { byte[] rawContentBuildTwo = ZipHelper.ReadFileFromZip (apk, "res/raw/test.txt"); Assert.IsNotNull (rawContentBuildTwo, "res/raw/test.txt should have been in the apk "); - txt = Encoding.UTF8.GetString (rawContentBuildTwo ?? new byte[0]); + txt = Encoding.UTF8.GetString (rawContentBuildTwo ?? Array.Empty ()); StringAssert.Contains ("Test Build 2 Now", txt, $"res/raw/test.txt should have been 'Test Build 2' not {txt}"); rawToDelete.Deleted = true; rawToDelete.Timestamp = DateTimeOffset.UtcNow; diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index c53e2366002..71fedcecc38 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -3900,7 +3900,7 @@ public class CustomApp : Application " }); proj.AndroidResources.Add (new AndroidItem.AndroidResource (@"Resources\raw\my_ca") { - BinaryContent = () => new byte [0], // doesn't have to be real, just *exist* + BinaryContent = () => Array.Empty (), // doesn't have to be real, just *exist* }); using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/MakeBundleNativeCodeExternalTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/MakeBundleNativeCodeExternalTests.cs index 0aaa7fb4e25..7963439d825 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/MakeBundleNativeCodeExternalTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/MakeBundleNativeCodeExternalTests.cs @@ -1,4 +1,5 @@ -using Microsoft.Build.Framework; +using System; +using Microsoft.Build.Framework; using NUnit.Framework; using System.Collections.Generic; using System.IO; @@ -35,7 +36,7 @@ public void XA5104AndroidNdkNotFound (string androidNdkDirectory) var task1 = new MakeBundleNativeCodeExternal { BuildEngine = engine, AndroidNdkDirectory = androidNdkDirectory, - Assemblies = new ITaskItem [0], + Assemblies = Array.Empty (), SupportedAbis = new [] { "armeabi-v7a" }, TempOutputPath = path, ToolPath = "", @@ -55,7 +56,7 @@ public void XA5104AndroidNdkNotFound (string androidNdkDirectory) AndroidAotMode = "normal", AndroidApiLevel = "28", EnableLLVM = true, - ResolvedAssemblies = new ITaskItem [0], + ResolvedAssemblies = Array.Empty (), SupportedAbis = new [] { "armeabi-v7a" }, AotOutputDirectory = path, IntermediateAssemblyDir = path diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs index a1ec85f5780..8e41182cb90 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs @@ -601,11 +601,11 @@ XElement CreateApplicationElement (XElement manifest, string applicationClass, L throw new InvalidOperationException ("Application cannot have both a type with an [Application] attribute and an [assembly:Application] attribute."); ApplicationAttribute appAttr = assemblyAttr.SingleOrDefault () ?? typeAttr.SingleOrDefault (); - var ull1 = usesLibraryAttr ?? new UsesLibraryAttribute [0]; - var ull2 = typeUsesLibraryAttr.AsEnumerable () ?? new UsesLibraryAttribute [0]; + var ull1 = usesLibraryAttr ?? Array.Empty (); + var ull2 = typeUsesLibraryAttr.AsEnumerable () ?? Array.Empty (); var usesLibraryAttrs = ull1.Concat (ull2); - var ucl1 = usesConfigurationAttr ?? new UsesConfigurationAttribute [0]; - var ucl2 = typeUsesConfigurationAttr.AsEnumerable () ?? new UsesConfigurationAttribute [0]; + var ucl1 = usesConfigurationAttr ?? Array.Empty(); + var ucl2 = typeUsesConfigurationAttr.AsEnumerable () ?? Array.Empty (); var usesConfigurationattrs = ucl1.Concat (ucl2); bool needManifestAdd = true; @@ -1053,7 +1053,7 @@ public void CalculateVersionCode (string currentAbi, string versionCodePattern, { var regex = new Regex ("\\{(?([A-Za-z]+)):?[D0-9]*[\\}]"); var kvp = new Dictionary (); - foreach (var item in versionCodeProperties?.Split (new char [] { ';', ':' }) ?? new string [0]) { + foreach (var item in versionCodeProperties?.Split (new char [] { ';', ':' }) ?? Array.Empty ()) { var keyValue = item.Split (new char [] { '=' }); int val; if (!int.TryParse (keyValue [1], out val)) diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs index 1490bcb8ba8..f23b89d0e20 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs @@ -43,7 +43,7 @@ public static int RunProcess (string name, string args, DataReceivedEventHandler } Process p = new Process (); p.StartInfo = psi; - + p.OutputDataReceived += onOutput; p.ErrorDataReceived += onError; p.Start (); @@ -193,7 +193,7 @@ public int GetHashCode (ITaskItem obj) #if MSBUILD public static IEnumerable ExpandFiles (ITaskItem[] libraryProjectJars) { - libraryProjectJars = libraryProjectJars ?? new ITaskItem [0]; + libraryProjectJars = libraryProjectJars ?? Array.Empty (); return (from path in libraryProjectJars let dir = Path.GetDirectoryName (path.ItemSpec) let pattern = Path.GetFileName (path.ItemSpec) @@ -212,7 +212,7 @@ public static IEnumerable DistinctFilesByContent (IEnumerable fi { return filePaths.Select (p => new FileInfo (p)).ToArray ().Distinct (new MonoAndroidHelper.SizeAndContentFileComparer ()).Select (f => f.FullName).ToArray (); } - + public static IEnumerable GetDuplicateFileNames (IEnumerable fullPaths, string [] excluded) { var files = fullPaths.Select (full => Path.GetFileName (full)).Where (f => excluded == null || !excluded.Contains (f, StringComparer.OrdinalIgnoreCase)).ToArray (); @@ -221,7 +221,7 @@ public static IEnumerable GetDuplicateFileNames (IEnumerable ful if (String.Compare (files [i], files [j], StringComparison.OrdinalIgnoreCase) == 0) yield return files [i]; } - + public static bool IsEmbeddedReferenceJar (string jar) { return jar.StartsWith ("__reference__"); @@ -335,7 +335,7 @@ public static ZipArchive ReadZipFile (string filename) } #if MSBUILD - internal static IEnumerable GetFrameworkAssembliesToTreatAsUserAssemblies (ITaskItem[] resolvedAssemblies) + internal static IEnumerable GetFrameworkAssembliesToTreatAsUserAssemblies (ITaskItem[] resolvedAssemblies) { var ret = new List (); foreach (ITaskItem item in resolvedAssemblies) { diff --git a/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs b/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs index e17bc1e481a..8f27a22e088 100644 --- a/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs +++ b/src/Xamarin.Android.Build.Tasks/Utilities/TypeMapGenerator.cs @@ -420,7 +420,7 @@ bool GenerateRelease (bool skipJniAddNativeMethodRegistrationAttributeScan, List var typeMapEntryComparer = new TypeMapEntryArrayComparer (); foreach (ModuleReleaseData module in modules) { if (module.TypesScratch.Count == 0) { - module.Types = new TypeMapReleaseEntry[0]; + module.Types = Array.Empty (); continue; } diff --git a/src/Xamarin.Android.Tools.Aidl/AidlAst.cs b/src/Xamarin.Android.Tools.Aidl/AidlAst.cs index f8238e1425b..85195a3f2fe 100644 --- a/src/Xamarin.Android.Tools.Aidl/AidlAst.cs +++ b/src/Xamarin.Android.Tools.Aidl/AidlAst.cs @@ -12,26 +12,26 @@ public CompilationUnit (TypeName package, TypeName [] imports, ITypeDeclaration Imports = imports; Types = types; } - + public TypeName Package { get; private set; } public TypeName [] Imports { get; private set; } public ITypeDeclaration [] Types { get; private set; } } - + public interface ITypeDeclaration { } - + public class Parcelable : ITypeDeclaration { public Parcelable (TypeName name) { Name = name; } - + public TypeName Name { get; private set; } } - + public class Interface : ITypeDeclaration { public Interface (string modifier, string name, Method [] methods) @@ -39,15 +39,15 @@ public Interface (string modifier, string name, Method [] methods) Modifier = modifier; JavaName = name; Name = name [0] == 'I' ? name : 'I' + name; - Methods = methods ?? new Method [0]; + Methods = methods ?? Array.Empty (); } - + public string Modifier { get; private set; } public string JavaName { get; private set; } public string Name { get; private set; } public Method [] Methods { get; private set; } } - + public class Method { public Method (string modifier, TypeName returnType, string name, Argument [] args) @@ -56,7 +56,7 @@ public Method (string modifier, TypeName returnType, string name, Argument [] ar ReturnType = returnType; JavaName = name; Name = Util.ToPascalCase (name); - Arguments = args ?? new Argument [0]; + Arguments = args ?? Array.Empty (); } public string Modifier { get; private set; } @@ -65,7 +65,7 @@ public Method (string modifier, TypeName returnType, string name, Argument [] ar public string Name { get; private set; } public Argument [] Arguments { get; private set; } } - + public class Argument { public Argument (string modifier, TypeName type, string name) @@ -74,12 +74,12 @@ public Argument (string modifier, TypeName type, string name) Type = type; Name = name; } - + public string Modifier { get; private set; } public TypeName Type { get; private set; } public string Name { get; private set; } } - + public class TypeName { public TypeName (string [] identifiers) @@ -90,7 +90,7 @@ public TypeName (string [] identifiers) throw new ArgumentException ("'identifiers' contain one or more null values: {0}", String.Concat (identifiers)); this.Identifiers = identifiers; } - + public TypeName (string [] identifiers, TypeName [] genericArguments) { if (identifiers == null) @@ -102,17 +102,17 @@ public TypeName (string [] identifiers, TypeName [] genericArguments) this.Identifiers = identifiers; this.GenericArguments = genericArguments; } - + public string [] Identifiers { get; private set; } //public TypeName ElementType { get; private set; } public TypeName [] GenericArguments { get; private set; } public int ArrayDimension { get; internal set; } - + public string GetNamespace () { return GetFormattedIdentifiers (Identifiers.Length - 1); } - + public string GetPackage () { return GetJavaIdentifiers (Identifiers.Length - 1); @@ -127,7 +127,7 @@ public override string ToString () baseName += " []"; return baseName; } - + public string ToJavaString () { string baseName = GetJavaIdentifiers (Identifiers.Length); @@ -137,18 +137,18 @@ public string ToJavaString () baseName += " []"; return baseName; } - + string GetJavaIdentifiers (int count) { return String.Join (".", Identifiers.Take (count)); } - + string GetFormattedIdentifiers (int count) { return String.Join (".", (from n in Identifiers.Take (count) select Util.ToPascalCase (n)).ToArray ()); } } - + static class Util { public static string ToPascalCase (string s) diff --git a/src/Xamarin.Android.Tools.Aidl/CSharpCodeGenerator.cs b/src/Xamarin.Android.Tools.Aidl/CSharpCodeGenerator.cs index 1cb1ab0ff55..1401668affd 100644 --- a/src/Xamarin.Android.Tools.Aidl/CSharpCodeGenerator.cs +++ b/src/Xamarin.Android.Tools.Aidl/CSharpCodeGenerator.cs @@ -14,7 +14,7 @@ class NameResoltionCache CompilationUnit unit; Dictionary cache = new Dictionary (); IList parcelable_names; - + public NameResoltionCache (BindingDatabase database, CompilationUnit unit, IList parcelableNames) { this.database = database; @@ -25,7 +25,7 @@ public NameResoltionCache (BindingDatabase database, CompilationUnit unit, IList cache ["List"] = "Android.Runtime.JavaList"; cache ["Map"] = "Android.Runtime.JavaDictionary"; } - + public bool IsParcelable (TypeName type) { var jn = ToFullJavaName (type); @@ -35,7 +35,7 @@ public bool IsParcelable (TypeName type) return true; return false; } - + bool IsSupportedPrimitiveJavaType (string name) { switch (name) { @@ -52,19 +52,19 @@ bool IsSupportedPrimitiveJavaType (string name) } return false; } - + public string GetCSharpNamespace (TypeName name) { string dummy, javapkg = name != null ? name.GetPackage () : String.Empty; return database.NamespaceMappings.TryGetValue (javapkg, out dummy) ? dummy : name.GetNamespace (); } - + public string ToCSharpNamespace (TypeName package) { string dummy, javapkg = package != null ? package.ToJavaString () : String.Empty; return package == null ? String.Empty : database.NamespaceMappings.TryGetValue (javapkg, out dummy) ? dummy : package.ToString (); } - + public string ToFullJavaName (TypeName javaType) { string java = javaType.ToJavaString (); @@ -83,7 +83,7 @@ public string ToFullJavaName (TypeName javaType) // not found. return (unit.Package != null ? unit.Package.ToJavaString () + '.' : null) + java + suffix; } - + public string ToCSharp (TypeName javaType) // java name could be ns-less, or even partial ("import foo.Bar;" + "Bar.Baz" => "foo.Bar.Baz") { string java = javaType.ToJavaString (); @@ -104,7 +104,7 @@ public string ToCSharp (TypeName javaType) // java name could be ns-less, or eve return filter (cs + suffix); } - + var p = parcelable_names.FirstOrDefault (pp => pp.ToJavaString () == javaFullName); if (p != null) { var decentNS = GetCSharpNamespace (p); @@ -113,7 +113,7 @@ public string ToCSharp (TypeName javaType) // java name could be ns-less, or eve //Console.WriteLine ("Found in parcelable lookup " + java + " / " + cs); return filter (cs + suffix); } - + string csns = javaFullName != java ? GetCSharpNamespace (javaType) : String.Empty; cache [java] = cs = csns + (string.IsNullOrEmpty (csns) ? "" : ".") + javaType.Identifiers.Last (); //Console.WriteLine ("NOT Found in lookup " + java + " / " + cs); @@ -123,17 +123,17 @@ public string ToCSharp (TypeName javaType) // java name could be ns-less, or eve TextWriter w; BindingDatabase database; - + public CSharpCodeGenerator (TextWriter writer, BindingDatabase database) { w = writer; this.database = database; } - + CompilationUnit unit; NameResoltionCache name_cache; string self_ns; - + public void GenerateCode (CompilationUnit unit, IList parcelableNames, ConverterOptions opts) { w.WriteLine ("// This file is automatically generated and not supposed to be modified."); @@ -146,7 +146,7 @@ public void GenerateCode (CompilationUnit unit, IList parcelableNames, this.unit = unit; name_cache = new NameResoltionCache (database, unit, parcelableNames); self_ns = name_cache.ToCSharpNamespace (unit.Package); - + if (unit.Imports != null) { var nss = new List (); foreach (var imp in unit.Imports) { @@ -181,13 +181,13 @@ public void GenerateCode (CompilationUnit unit, IList parcelableNames, else if (type is Interface) GenerateCode ((Interface) type); } - + if (unit.Package != null) w.WriteLine ("}"); - + this.unit = null; } - + public void StubParcelable (Parcelable type) { string csNS = name_cache.GetCSharpNamespace (type.Name); @@ -221,7 +221,7 @@ public virtual void WriteToParcel (global::Android.OS.Parcel parcel, global::And if (csNS.Length > 0) w.WriteLine ("}"); } - + public void GenerateCode (Interface type) { w.WriteLine ("\tpublic interface " + type.Name + " : global::Android.OS.IInterface"); @@ -399,7 +399,7 @@ public string GetInterfaceDescriptor () w.WriteLine (@" }"); // end of Stub } - + public void GenerateCode (Method method) { w.Write ("\t\t{0} {1} (", ToOutputTypeName (name_cache.ToCSharp (method.ReturnType)), method.Name); @@ -414,7 +414,7 @@ public void GenerateCode (Method method) } w.WriteLine (");"); } - + string GetCreateStatements (TypeName type, string parcel, string arg) { string csname = name_cache.ToCSharp (type); @@ -492,7 +492,7 @@ string GetCreateStatements (TypeName type, string parcel, string arg) return String.Format ("{0} = {2}Stub.AsInterface ({1}.ReadStrongBinder ());", arg, parcel, ToOutputTypeName (csname)); } } - + string GetReadStatements (TypeName type, string parcel, string arg) { string csname = name_cache.ToCSharp (type); @@ -552,7 +552,7 @@ string GetReadStatements (TypeName type, string parcel, string arg) return String.Format ("{0} = {2}Stub.AsInterface ({1}.ReadStrongBinder ());", arg, parcel, ToOutputTypeName (csname)); } } - + string GetWriteStatements (TypeName type, string parcel, string arg, string parcelableWriteFlags) { string csname = name_cache.ToCSharp (type); @@ -656,13 +656,13 @@ string GetCreatorName (TypeName type) return String.Empty; } } - + string [] cs_units; - + string ToOutputTypeName (string name) { if (cs_units == null) - cs_units = unit.Package == null ? new string [0] : name_cache.ToCSharpNamespace (unit.Package).Split ('.'); + cs_units = unit.Package == null ? Array.Empty () : name_cache.ToCSharpNamespace (unit.Package).Split ('.'); int idx = name.IndexOf ('.'); if (idx < 0) return name; @@ -670,13 +670,13 @@ string ToOutputTypeName (string name) return name; return "global::" + name; } - + static CSharpCodeProvider csp = new CSharpCodeProvider (); static string SafeCSharpName (string name) { return csp.IsValidIdentifier (name) ? name : "@" + name; } - + string JoinArguments (Method m) { return m.Arguments != null ? String.Join (", ", (from a in m.Arguments select ToOutputTypeName (name_cache.ToCSharp (a.Type)) + " " + SafeCSharpName (a.Name)).ToArray ()) : null; diff --git a/src/Xamarin.Android.Tools.JavadocImporter/DocumentElement.cs b/src/Xamarin.Android.Tools.JavadocImporter/DocumentElement.cs index 962ea4874ff..8e18584eb58 100644 --- a/src/Xamarin.Android.Tools.JavadocImporter/DocumentElement.cs +++ b/src/Xamarin.Android.Tools.JavadocImporter/DocumentElement.cs @@ -372,10 +372,10 @@ public override IEnumerable GetTypeSummaryNodes (XElement jd) .Elements ("div").Where (e => Application.HasHtmlClass (e, "description")) .First (); if (desc == null) - return new XNode [0]; + return Array.Empty (); var div = desc.XPathSelectElement ("ul/li/div"); if (div == null) - return new XNode [0]; + return Array.Empty (); return div.Nodes (); } diff --git a/tests/MSBuildDeviceIntegration/Tests/InstantRunTest.cs b/tests/MSBuildDeviceIntegration/Tests/InstantRunTest.cs index 5dfe6bb14d1..6061395244e 100644 --- a/tests/MSBuildDeviceIntegration/Tests/InstantRunTest.cs +++ b/tests/MSBuildDeviceIntegration/Tests/InstantRunTest.cs @@ -178,7 +178,7 @@ public void SkipFastDevAlreadyInstalledFile ([Values ("dx", "d8")] string dexToo #pragma warning disable 414 static object [] SkipFastDevAlreadyInstalledResourcesSource = new object [] { - new object[] { new Package [0], null }, + new object[] { Array.Empty (), null }, new object[] { new Package [] { KnownPackages.AndroidSupportV4_27_0_2_1, KnownPackages.SupportV7AppCompat_27_0_2_1}, "Android.Support.V7.App.AppCompatActivity" }, }; #pragma warning restore 414 diff --git a/tools/tmt/AnELF.cs b/tools/tmt/AnELF.cs index f953a533806..792ad2ff944 100644 --- a/tools/tmt/AnELF.cs +++ b/tools/tmt/AnELF.cs @@ -11,7 +11,7 @@ namespace tmt { abstract class AnELF { - protected static readonly byte[] EmptyArray = new byte[0]; + protected static readonly byte[] EmptyArray = Array.Empty (); const string DynsymSectionName = ".dynsym"; const string SymtabSectionName = ".symtab";