diff --git a/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj b/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj index e3fb154d5ff1..68c60384f67b 100644 --- a/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj +++ b/fcs/FSharp.Compiler.Service/FSharp.Compiler.Service.fsproj @@ -153,6 +153,9 @@ Utilities/bytes.fs + + Utilities\XmlAdapters.fs + Utilities/lib.fs diff --git a/src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj b/src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj index da4ec9b90daf..cf5da21fbfc8 100644 --- a/src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj +++ b/src/fsharp/FSharp.Compiler.Private/FSharp.Compiler.Private.fsproj @@ -151,6 +151,9 @@ Utilities\bytes.fs + + Utilities\XmlAdapters.fs + Utilities\InternalCollections.fsi diff --git a/src/fsharp/XmlAdapters.fs b/src/fsharp/XmlAdapters.fs new file mode 100644 index 000000000000..4f48955945a7 --- /dev/null +++ b/src/fsharp/XmlAdapters.fs @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace Microsoft.FSharp.Core +open System.Reflection + +//Replacement for: System.Security.SecurityElement.Escape(line) All platforms +module internal XmlAdapters = + open System.Text + open Microsoft.FSharp.Collections + + let s_escapeChars = [| '<'; '>'; '\"'; '\''; '&' |] + + let getEscapeSequence c = + match c with + | '<' -> "<" + | '>' -> ">" + | '\"' -> """ + | '\'' -> "'" + | '&' -> "&" + | _ as ch -> ch.ToString() + + let escape str = String.collect getEscapeSequence str + diff --git a/src/utils/CompilerLocationUtils.fs b/src/utils/CompilerLocationUtils.fs index a2861bf6d5f3..da626b54c5e1 100644 --- a/src/utils/CompilerLocationUtils.fs +++ b/src/utils/CompilerLocationUtils.fs @@ -187,7 +187,7 @@ module internal FSharpEnvironment = #else // Check for an app.config setting to redirect the default compiler location // Like fsharp-compiler-location - try + try // FSharp.Compiler support setting an appkey for compiler location. I've never seen this used. let result = tryAppConfig "fsharp-compiler-location" match result with diff --git a/src/utils/reshapedmsbuild.fs b/src/utils/reshapedmsbuild.fs index 75859f44765a..20b5cd6f9617 100644 --- a/src/utils/reshapedmsbuild.fs +++ b/src/utils/reshapedmsbuild.fs @@ -21,41 +21,45 @@ type ITaskItem = abstract member CopyMetadataTo : ITaskItem -> unit abstract member CloneCustomMetadata : IDictionary -namespace Microsoft.Build.Utilities -open Microsoft.Build.Framework -open Microsoft.FSharp.Core.ReflectionAdapters -open System -open System.Collections -open System.Reflection - -type TaskItem (itemSpec:string) = - let assembly = Assembly.Load(new AssemblyName("Microsoft.Build.Utilities.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")) - let buildUtilitiesTaskType = assembly.GetType("Microsoft.Build.Utilities.Task") - let instance = Activator.CreateInstance(buildUtilitiesTaskType, [|itemSpec|]) - - interface ITaskItem with - member this.ItemSpec - with get () :string = (instance.GetPropertyValue("ItemSpec") :?> string) - and set (value:string) = (instance.SetPropertyValue("ItemSpec", value)); () - member this.MetadataNames - with get () :ICollection = (instance.GetPropertyValue("MetadataNames") :?> ICollection) - member this.MetadataCount - with get () :int = (instance.GetPropertyValue("MetadataCount") :?> int) - member this.CopyMetadataTo(iTaskItem) = - let m = buildUtilitiesTaskType.GetMethod("CopyMetadataTo", [| typeof |]) - m.Invoke(instance, [|iTaskItem :>obj|]) |> ignore - member this.CloneCustomMetadata = - let m = buildUtilitiesTaskType.GetMethod("CloneCustomMetadata", [||]) - (m.Invoke(instance,[||])) :?>IDictionary - member this.GetMetadata(metadataName) = - let m = buildUtilitiesTaskType.GetMethod("GetMetadata", [|typeof|]) - (m.Invoke(instance,[|metadataName|])) :?>string - member this.RemoveMetadata(metadataName) = - let m = buildUtilitiesTaskType.GetMethod("RemoveMetadata", [|typeof|]) - (m.Invoke(instance,[|metadataName|])) :?>string |>ignore - member this.SetMetadata(metadataName, metadataValue) = - let m = buildUtilitiesTaskType.GetMethod("SetMetadata", [|typeof;typeof|]) - (m.Invoke(instance,[|metadataName; metadataValue|])) |>ignore +module Utilities = + open Microsoft.Build.Framework + open System + open System.Collections + open System.Reflection + + type System.Object with + member this.GetPropertyValue(propName) = this.GetType().GetProperty(propName, BindingFlags.Public).GetValue(this, null) + member this.SetPropertyValue(propName, propValue) = this.GetType().GetProperty(propName, BindingFlags.Public).SetValue(this, propValue, null) + member this.GetMethod(methodName, argTypes) = this.GetType().GetMethod(methodName, argTypes, [||]) + + type TaskItem (itemSpec:string) = + let assembly = Assembly.Load(new AssemblyName("Microsoft.Build.Utilities.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")) + let buildUtilitiesTaskType = assembly.GetType("Microsoft.Build.Utilities.Task") + let instance = Activator.CreateInstance(buildUtilitiesTaskType, [|itemSpec|]) + + interface ITaskItem with + member this.ItemSpec + with get () :string = (instance.GetPropertyValue("ItemSpec") :?> string) + and set (value:string) = (instance.SetPropertyValue("ItemSpec", value)); () + member this.MetadataNames + with get () :ICollection = (instance.GetPropertyValue("MetadataNames") :?> ICollection) + member this.MetadataCount + with get () :int = (instance.GetPropertyValue("MetadataCount") :?> int) + member this.CopyMetadataTo(iTaskItem) = + let m = buildUtilitiesTaskType.GetMethod("CopyMetadataTo", [| typeof |]) + m.Invoke(instance, [|iTaskItem :>obj|]) |> ignore + member this.CloneCustomMetadata = + let m = buildUtilitiesTaskType.GetMethod("CloneCustomMetadata", [||]) + (m.Invoke(instance,[||])) :?>IDictionary + member this.GetMetadata(metadataName) = + let m = buildUtilitiesTaskType.GetMethod("GetMetadata", [|typeof|]) + (m.Invoke(instance,[|metadataName|])) :?>string + member this.RemoveMetadata(metadataName) = + let m = buildUtilitiesTaskType.GetMethod("RemoveMetadata", [|typeof|]) + (m.Invoke(instance,[|metadataName|])) :?>string |>ignore + member this.SetMetadata(metadataName, metadataValue) = + let m = buildUtilitiesTaskType.GetMethod("SetMetadata", [|typeof;typeof|]) + (m.Invoke(instance,[|metadataName; metadataValue|])) |>ignore namespace FSharp.Compiler open System @@ -66,11 +70,10 @@ open System.Linq open System.Runtime.Versioning open FSComp open Microsoft.Win32 +open Microsoft.Build.Framework.Utilities module internal MsBuildAdapters = - open Microsoft.FSharp.Core.ReflectionAdapters - /// /// Used to specify the targeted version of the .NET Framework for some methods of ToolLocationHelper. This is meant to mimic /// the official version here: https://source.dot.net/#q=TargetDotNetFrameworkVersion. @@ -102,7 +105,6 @@ module internal MsBuildAdapters = module internal ToolLocationHelper = open Microsoft.Build.Framework - open Microsoft.FSharp.Core.ReflectionAdapters open System.Linq open System.Reflection open MsBuildAdapters diff --git a/src/utils/sformat.fs b/src/utils/sformat.fs index 9d4508f4a94a..0c8cc5fc2f4f 100644 --- a/src/utils/sformat.fs +++ b/src/utils/sformat.fs @@ -1144,9 +1144,9 @@ namespace Microsoft.FSharp.Text.StructuredPrintfImpl // massively reign in deep printing of properties let nDepth = depthLim/10 #if NETSTANDARD - Array.Sort((propsAndFields),{ new IComparer with member this.Compare(p1,p2) = compare (p1.Name) (p2.Name) } ); + Array.Sort((propsAndFields),{ new IComparer with member this.Compare(p1,p2) = compare (p1.Name) (p2.Name) } ) #else - Array.Sort((propsAndFields :> Array),{ new System.Collections.IComparer with member this.Compare(p1,p2) = compare ((p1 :?> MemberInfo).Name) ((p2 :?> MemberInfo).Name) } ); + Array.Sort((propsAndFields :> Array),{ new System.Collections.IComparer with member this.Compare(p1,p2) = compare ((p1 :?> MemberInfo).Name) ((p2 :?> MemberInfo).Name) } ) #endif if propsAndFields.Length = 0 || (nDepth <= 0) then basicL