2ce53fc
From bf5c5a72978a0f9d32c9934e216bfaaf2d1717be Mon Sep 17 00:00:00 2001
2ce53fc
From: =?UTF-8?q?Robert-Andr=C3=A9=20Mauchin?= <zebob.m@gmail.com>
2ce53fc
Date: Mon, 3 Feb 2020 18:38:58 +0100
2ce53fc
Subject: [PATCH] Replace new Csharp features with old ones
2ce53fc
MIME-Version: 1.0
2ce53fc
Content-Type: text/plain; charset=UTF-8
2ce53fc
Content-Transfer-Encoding: 8bit
2ce53fc
2ce53fc
Replace new Csharp features like switch statements and
2ce53fc
"is null" to allow mdoc.exe to build with mcs.
2ce53fc
2ce53fc
Signed-off-by: Robert-André Mauchin <zebob.m@gmail.com>
2ce53fc
---
2ce53fc
 mdoc/Mono.Documentation/Updater/DocUtils.cs   | 91 ++++++++++---------
2ce53fc
 .../CppFormatters/CppFullMemberFormatter.cs   | 26 +++---
2ce53fc
 .../Updater/Formatters/FSharpFormatter.cs     | 16 ++--
2ce53fc
 .../Updater/Formatters/JsFormatter.cs         | 27 +++---
2ce53fc
 .../Updater/Formatters/JsMemberFormatter.cs   |  9 +-
2ce53fc
 5 files changed, 85 insertions(+), 84 deletions(-)
2ce53fc
2ce53fc
diff --git a/mdoc/Mono.Documentation/Updater/DocUtils.cs b/mdoc/Mono.Documentation/Updater/DocUtils.cs
2ce53fc
index 331ef90..fe2da59 100644
2ce53fc
--- a/mdoc/Mono.Documentation/Updater/DocUtils.cs
2ce53fc
+++ b/mdoc/Mono.Documentation/Updater/DocUtils.cs
2ce53fc
@@ -287,24 +287,24 @@ namespace Mono.Documentation.Updater
2ce53fc
             return inst != null
2ce53fc
                     ? inst.GenericArguments.Count
2ce53fc
                     : type.GenericParameters.Count;
2ce53fc
-        }
2ce53fc
+        }
2ce53fc
 
2ce53fc
         class TypeEquality : IEqualityComparer<TypeReference>
2ce53fc
-        {
2ce53fc
-            bool IEqualityComparer<TypeReference>.Equals (TypeReference x, TypeReference y)
2ce53fc
+        {
2ce53fc
+            bool IEqualityComparer<TypeReference>.Equals (TypeReference x, TypeReference y)
2ce53fc
+            {
2ce53fc
+                if (x == null && y == null) return true;
2ce53fc
+                if (x == null || y == null) return false;
2ce53fc
+                return x.FullName == y.FullName;
2ce53fc
+            }
2ce53fc
+
2ce53fc
+            int IEqualityComparer<TypeReference>.GetHashCode (TypeReference obj)
2ce53fc
             {
2ce53fc
-                if (x is null && y is null) return true;
2ce53fc
-                if (x is null || y is null) return false;
2ce53fc
-                return x.FullName == y.FullName;
2ce53fc
-            }
2ce53fc
-
2ce53fc
-            int IEqualityComparer<TypeReference>.GetHashCode (TypeReference obj)
2ce53fc
-            {
2ce53fc
-                return obj.GetHashCode ();
2ce53fc
+                return obj.GetHashCode ();
2ce53fc
             }
2ce53fc
         }
2ce53fc
         static TypeEquality typeEqualityComparer = new TypeEquality ();
2ce53fc
-
2ce53fc
+
2ce53fc
         public static IEnumerable<TypeReference> GetAllPublicInterfaces (TypeDefinition type)
2ce53fc
         {
2ce53fc
             return GetAllInterfacesFromType (type)
2ce53fc
@@ -314,7 +314,7 @@ namespace Mono.Documentation.Updater
2ce53fc
 
2ce53fc
         private static IEnumerable<TypeReference> GetAllInterfacesFromType(TypeDefinition type)
2ce53fc
         {
2ce53fc
-            if (type is null)
2ce53fc
+            if (type == null)
2ce53fc
                 yield break;
2ce53fc
 
2ce53fc
             foreach(var i in type.Interfaces)
2ce53fc
@@ -525,26 +525,29 @@ namespace Mono.Documentation.Updater
2ce53fc
             FillUnifiedMemberTypeNames(unifiedTypeNames, memberReference as IGenericParameterProvider);// Fill the member generic parameters unified names as M0, M1....
2ce53fc
             FillUnifiedTypeNames(unifiedTypeNames, memberReference.DeclaringType, genericInterface);// Fill the type generic parameters unified names as T0, T1....
2ce53fc
 
2ce53fc
-            switch (memberReference)
2ce53fc
-            {
2ce53fc
-                case IMethodSignature methodSignature:
2ce53fc
-                    buf.Append(GetUnifiedTypeName(methodSignature.ReturnType, unifiedTypeNames)).Append(" ");
2ce53fc
-                    buf.Append(SimplifyName(memberReference.Name)).Append(" ");
2ce53fc
-                    AppendParameters(buf, methodSignature.Parameters, unifiedTypeNames);
2ce53fc
-                    break;
2ce53fc
-                case PropertyDefinition propertyReference:
2ce53fc
-                    buf.Append(GetUnifiedTypeName(propertyReference.PropertyType, unifiedTypeNames)).Append(" ");
2ce53fc
-                    if (propertyReference.GetMethod != null)
2ce53fc
-                        buf.Append("get").Append(" ");
2ce53fc
-                    if (propertyReference.SetMethod != null)
2ce53fc
-                        buf.Append("set").Append(" ");
2ce53fc
-                    buf.Append(SimplifyName(memberReference.Name)).Append(" ");
2ce53fc
-                    AppendParameters(buf, propertyReference.Parameters, unifiedTypeNames);
2ce53fc
-                    break;
2ce53fc
-                case EventDefinition eventReference:
2ce53fc
-                    buf.Append(GetUnifiedTypeName(eventReference.EventType, unifiedTypeNames)).Append(" ");
2ce53fc
-                    buf.Append(SimplifyName(memberReference.Name)).Append(" ");
2ce53fc
-                    break;
2ce53fc
+            if (memberReference is IMethodSignature)
2ce53fc
+            {
2ce53fc
+                IMethodSignature methodSignature = (IMethodSignature)memberReference;
2ce53fc
+                buf.Append(GetUnifiedTypeName(methodSignature.ReturnType, unifiedTypeNames)).Append(" ");
2ce53fc
+                buf.Append(SimplifyName(memberReference.Name)).Append(" ");
2ce53fc
+                AppendParameters(buf, methodSignature.Parameters, unifiedTypeNames);
2ce53fc
+            }
2ce53fc
+            if (memberReference is PropertyDefinition)
2ce53fc
+            {
2ce53fc
+                PropertyDefinition propertyReference = (PropertyDefinition)memberReference;
2ce53fc
+                buf.Append(GetUnifiedTypeName(propertyReference.PropertyType, unifiedTypeNames)).Append(" ");
2ce53fc
+                if (propertyReference.GetMethod != null)
2ce53fc
+                    buf.Append("get").Append(" ");
2ce53fc
+                if (propertyReference.SetMethod != null)
2ce53fc
+                    buf.Append("set").Append(" ");
2ce53fc
+                buf.Append(SimplifyName(memberReference.Name)).Append(" ");
2ce53fc
+                AppendParameters(buf, propertyReference.Parameters, unifiedTypeNames);
2ce53fc
+            }
2ce53fc
+            if (memberReference is EventDefinition)
2ce53fc
+            {
2ce53fc
+                EventDefinition eventReference = (EventDefinition)memberReference;
2ce53fc
+                buf.Append(GetUnifiedTypeName(eventReference.EventType, unifiedTypeNames)).Append(" ");
2ce53fc
+                buf.Append(SimplifyName(memberReference.Name)).Append(" ");
2ce53fc
             }
2ce53fc
             
2ce53fc
             var memberUnifiedTypeNames = new Dictionary<string, string>();
2ce53fc
@@ -666,14 +669,20 @@ namespace Mono.Documentation.Updater
2ce53fc
         /// </summary>
2ce53fc
         private static Collection<MethodReference> GetOverrides(MemberReference memberReference)
2ce53fc
         {
2ce53fc
-            switch (memberReference)
2ce53fc
+            if (memberReference is MethodDefinition)
2ce53fc
+            {
2ce53fc
+                MethodDefinition methodDefinition = (MethodDefinition)memberReference;
2ce53fc
+                return methodDefinition.Overrides;
2ce53fc
+            }
2ce53fc
+            if (memberReference is PropertyDefinition)
2ce53fc
+            {
2ce53fc
+                PropertyDefinition propertyDefinition = (PropertyDefinition)memberReference;
2ce53fc
+                return (propertyDefinition.GetMethod ?? propertyDefinition.SetMethod)?.Overrides;
2ce53fc
+            }
2ce53fc
+            if (memberReference is EventDefinition)
2ce53fc
             {
2ce53fc
-                case MethodDefinition methodDefinition:
2ce53fc
-                    return methodDefinition.Overrides;
2ce53fc
-                case PropertyDefinition propertyDefinition:
2ce53fc
-                    return (propertyDefinition.GetMethod ?? propertyDefinition.SetMethod)?.Overrides;
2ce53fc
-                case EventDefinition evendDefinition:
2ce53fc
-                    return evendDefinition.AddMethod.Overrides;
2ce53fc
+                EventDefinition evendDefinition = (EventDefinition)memberReference;
2ce53fc
+                return evendDefinition.AddMethod.Overrides;
2ce53fc
             }
2ce53fc
 
2ce53fc
             return null;
2ce53fc
@@ -692,4 +701,4 @@ namespace Mono.Documentation.Updater
2ce53fc
             return method.Name.StartsWith("op_", StringComparison.Ordinal);
2ce53fc
         }
2ce53fc
     }
2ce53fc
-}
2ce53fc
\ No newline at end of file
2ce53fc
+}
2ce53fc
diff --git a/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppFullMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppFullMemberFormatter.cs
2ce53fc
index 7d68c38..6b9bcf6 100644
2ce53fc
--- a/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppFullMemberFormatter.cs
2ce53fc
+++ b/mdoc/Mono.Documentation/Updater/Formatters/CppFormatters/CppFullMemberFormatter.cs
2ce53fc
@@ -1029,20 +1029,16 @@ namespace Mono.Documentation.Updater.Formatters.CppFormatters
2ce53fc
             if (mref.IsDefinition == false)
2ce53fc
                 mref = mref.Resolve() as MemberReference;
2ce53fc
             
2ce53fc
-            switch (mref)
2ce53fc
-            {
2ce53fc
-                case FieldDefinition field:
2ce53fc
-                    return IsSupportedField(field);
2ce53fc
-                case MethodDefinition method:
2ce53fc
-                    return IsSupportedMethod(method);
2ce53fc
-                case PropertyDefinition property:
2ce53fc
-                    return IsSupportedProperty(property);
2ce53fc
-                case EventDefinition @event:
2ce53fc
-                    return IsSupportedEvent(@event);
2ce53fc
-                case AttachedPropertyDefinition _:
2ce53fc
-                case AttachedEventDefinition _:
2ce53fc
-                    return false;
2ce53fc
-            }
2ce53fc
+            if (mref is FieldDefinition)
2ce53fc
+                return IsSupportedField((FieldDefinition)mref);
2ce53fc
+            else if (mref is MethodDefinition)
2ce53fc
+                return IsSupportedMethod((MethodDefinition)mref);
2ce53fc
+            else if (mref is PropertyDefinition)
2ce53fc
+                return IsSupportedProperty((PropertyDefinition)mref);
2ce53fc
+            else if (mref is EventDefinition)
2ce53fc
+                return IsSupportedEvent((EventDefinition)mref);
2ce53fc
+            else if (mref is AttachedPropertyDefinition || mref is AttachedEventDefinition)
2ce53fc
+                return false;
2ce53fc
 
2ce53fc
             throw new NotSupportedException("Unsupported member type: " + mref?.GetType().FullName);
2ce53fc
         }
2ce53fc
@@ -1119,4 +1115,4 @@ namespace Mono.Documentation.Updater.Formatters.CppFormatters
2ce53fc
             return true;
2ce53fc
         }
2ce53fc
     }
2ce53fc
-}
2ce53fc
\ No newline at end of file
2ce53fc
+}
2ce53fc
diff --git a/mdoc/Mono.Documentation/Updater/Formatters/FSharpFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/FSharpFormatter.cs
2ce53fc
index 236d56f..f91bf9a 100644
2ce53fc
--- a/mdoc/Mono.Documentation/Updater/Formatters/FSharpFormatter.cs
2ce53fc
+++ b/mdoc/Mono.Documentation/Updater/Formatters/FSharpFormatter.cs
2ce53fc
@@ -1029,15 +1029,15 @@ namespace Mono.Documentation.Updater
2ce53fc
                 }
2ce53fc
                 return false;
2ce53fc
             }
2ce53fc
-            switch (mref)
2ce53fc
+            if (mref is MethodDefinition)
2ce53fc
             {
2ce53fc
-                case MethodDefinition method:
2ce53fc
-                    return !(method.HasCustomAttributes && method.CustomAttributes.Any(
2ce53fc
-                                 ca => ca.GetDeclaringType() ==
2ce53fc
-                                       "System.Diagnostics.Contracts.ContractInvariantMethodAttribute"
2ce53fc
-                                       || ca.GetDeclaringType() ==
2ce53fc
-                                       Consts.CompilerGeneratedAttribute))
2ce53fc
-                            && AppendVisibility(new StringBuilder(), method) != null;
2ce53fc
+                MethodDefinition method = (MethodDefinition)mref;
2ce53fc
+                return !(method.HasCustomAttributes && method.CustomAttributes.Any(
2ce53fc
+                              ca => ca.GetDeclaringType() ==
2ce53fc
+                                    "System.Diagnostics.Contracts.ContractInvariantMethodAttribute"
2ce53fc
+                                    || ca.GetDeclaringType() ==
2ce53fc
+                                    Consts.CompilerGeneratedAttribute))
2ce53fc
+                        && AppendVisibility(new StringBuilder(), method) != null;
2ce53fc
             }
2ce53fc
 
2ce53fc
             return true;
2ce53fc
diff --git a/mdoc/Mono.Documentation/Updater/Formatters/JsFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/JsFormatter.cs
2ce53fc
index f8b2f04..92b8f3c 100644
2ce53fc
--- a/mdoc/Mono.Documentation/Updater/Formatters/JsFormatter.cs
2ce53fc
+++ b/mdoc/Mono.Documentation/Updater/Formatters/JsFormatter.cs
2ce53fc
@@ -68,23 +68,22 @@ namespace mdoc.Mono.Documentation.Updater.Formatters
2ce53fc
 
2ce53fc
         public override bool IsSupported(MemberReference mref)
2ce53fc
         {
2ce53fc
-            switch (mref)
2ce53fc
+            if (mref is PropertyDefinition)
2ce53fc
             {
2ce53fc
-                case PropertyDefinition propertyDefinition:
2ce53fc
-                    if (!IsPropertySupported(propertyDefinition))
2ce53fc
-                        return false;
2ce53fc
-                    break;
2ce53fc
-                case MethodDefinition methodDefinition:
2ce53fc
-                    if (!IsMethodSupported(methodDefinition))
2ce53fc
-                        return false;
2ce53fc
-                    break;
2ce53fc
-                case FieldDefinition _:
2ce53fc
-                    return false;// In WinRT fields can be exposed only by structures.
2ce53fc
-                case AttachedEventDefinition _:
2ce53fc
+                PropertyDefinition propertyDefinition = (PropertyDefinition)mref;
2ce53fc
+                if (!IsPropertySupported(propertyDefinition))
2ce53fc
                     return false;
2ce53fc
-                case AttachedPropertyDefinition _:
2ce53fc
+            }
2ce53fc
+            else if (mref is MethodDefinition)
2ce53fc
+            {
2ce53fc
+                MethodDefinition methodDefinition = (MethodDefinition)mref;
2ce53fc
+                if (!IsMethodSupported(methodDefinition))
2ce53fc
                     return false;
2ce53fc
             }
2ce53fc
+            else if (mref is FieldDefinition // In WinRT fields can be exposed only by structures.
2ce53fc
+                || mref is AttachedEventDefinition
2ce53fc
+                || mref is AttachedPropertyDefinition)
2ce53fc
+                return false;
2ce53fc
 
2ce53fc
             var member = mref.Resolve();
2ce53fc
             return member != null
2ce53fc
@@ -169,4 +168,4 @@ namespace mdoc.Mono.Documentation.Updater.Formatters
2ce53fc
             return fullName;
2ce53fc
         }
2ce53fc
     }
2ce53fc
-}
2ce53fc
\ No newline at end of file
2ce53fc
+}
2ce53fc
diff --git a/mdoc/Mono.Documentation/Updater/Formatters/JsMemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/JsMemberFormatter.cs
2ce53fc
index 6bc6995..f6c8af6 100644
2ce53fc
--- a/mdoc/Mono.Documentation/Updater/Formatters/JsMemberFormatter.cs
2ce53fc
+++ b/mdoc/Mono.Documentation/Updater/Formatters/JsMemberFormatter.cs
2ce53fc
@@ -58,12 +58,9 @@ namespace mdoc.Mono.Documentation.Updater.Formatters
2ce53fc
 
2ce53fc
         public override bool IsSupported(MemberReference mref)
2ce53fc
         {
2ce53fc
-            switch (mref)
2ce53fc
+            if (mref is PropertyDefinition || mref is EventDefinition)
2ce53fc
             {
2ce53fc
-                case PropertyDefinition _:
2ce53fc
-                    return false;
2ce53fc
-                case EventDefinition _:
2ce53fc
-                    return false;
2ce53fc
+                return false;
2ce53fc
             }
2ce53fc
             return base.IsSupported(mref);
2ce53fc
         }
2ce53fc
@@ -82,4 +79,4 @@ namespace mdoc.Mono.Documentation.Updater.Formatters
2ce53fc
             return base.IsSupported(tref);
2ce53fc
         }
2ce53fc
     }
2ce53fc
-}
2ce53fc
\ No newline at end of file
2ce53fc
+}
2ce53fc
-- 
2ce53fc
2.24.1
2ce53fc