提交 5fa04d67 编写于 作者: D Dustin Campbell

Update much of Features to build under portable

上级 90001ddc
......@@ -5,11 +5,12 @@
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis.CodeFixes
{
using TypeInfo = System.Reflection.TypeInfo;
internal partial class CodeFixService
{
private class ProjectCodeFixProvider
......@@ -44,21 +45,21 @@ private ImmutableArray<CodeFixProvider> CreateFixers(string language)
return ImmutableArray<CodeFixProvider>.Empty;
}
Type[] types = null;
IEnumerable<TypeInfo> typeInfos = null;
ImmutableArray<CodeFixProvider>.Builder builder = null;
try
{
Assembly analyzerAssembly = analyzerFileReference.GetAssembly();
types = analyzerAssembly.GetTypes();
typeInfos = analyzerAssembly.DefinedTypes;
foreach (var type in types)
foreach (var typeInfo in typeInfos)
{
if (type.GetTypeInfo().IsSubclassOf(typeof(CodeFixProvider)))
if (typeInfo.IsSubclassOf(typeof(CodeFixProvider)))
{
try
{
var attribute = type.GetCustomAttribute<ExportCodeFixProviderAttribute>();
var attribute = typeInfo.GetCustomAttribute<ExportCodeFixProviderAttribute>();
if (attribute != null)
{
if (attribute.Languages == null ||
......@@ -66,7 +67,7 @@ private ImmutableArray<CodeFixProvider> CreateFixers(string language)
attribute.Languages.Contains(language))
{
builder = builder ?? ImmutableArray.CreateBuilder<CodeFixProvider>();
builder.Add((CodeFixProvider)Activator.CreateInstance(type));
builder.Add((CodeFixProvider)Activator.CreateInstance(typeInfo.AsType()));
}
}
}
......
......@@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Composition;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
......
......@@ -2,6 +2,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
......@@ -53,10 +55,10 @@ protected override async Task<IEnumerable<CodeActionOperation>> ComputeOperation
private static bool IsInternalCodeFixProvider(CodeFixProvider fixer)
{
var exportAttributes = fixer.GetType().GetCustomAttributes(typeof(ExportCodeFixProviderAttribute), false);
if (exportAttributes != null && exportAttributes.Length > 0)
var exportAttributes = fixer.GetType().GetTypeInfo().GetCustomAttributes(typeof(ExportCodeFixProviderAttribute), false);
if (exportAttributes?.Any() == true)
{
var exportAttribute = (ExportCodeFixProviderAttribute)exportAttributes[0];
var exportAttribute = (ExportCodeFixProviderAttribute)exportAttributes.First();
return s_predefinedCodeFixProviderNames.Contains(exportAttribute.Name);
}
......@@ -67,12 +69,12 @@ private static HashSet<string> GetPredefinedCodeFixProviderNames()
{
var names = new HashSet<string>();
var fields = typeof(PredefinedCodeFixProviderNames).GetFields();
var fields = typeof(PredefinedCodeFixProviderNames).GetTypeInfo().DeclaredFields;
foreach (var field in fields)
{
if (field.IsStatic)
{
names.Add((string)field.GetRawConstantValue());
names.Add((string)field.GetValue(null));
}
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes.Suppression;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CodeFixes
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -28,12 +29,12 @@ internal abstract partial class AbstractSuppressionCodeFixProvider : ISuppressio
private static bool IsNotConfigurableDiagnostic(Diagnostic diagnostic)
{
return diagnostic.Descriptor.CustomTags.Any(c => string.Equals(c, WellKnownDiagnosticTags.NotConfigurable, System.StringComparison.InvariantCulture));
return diagnostic.Descriptor.CustomTags.Any(c => CultureInfo.InvariantCulture.CompareInfo.Compare(c, WellKnownDiagnosticTags.NotConfigurable) == 0);
}
private static bool IsCompilerDiagnostic(Diagnostic diagnostic)
{
return diagnostic.Descriptor.CustomTags.Any(c => string.Equals(c, WellKnownDiagnosticTags.Compiler, System.StringComparison.InvariantCulture));
return diagnostic.Descriptor.CustomTags.Any(c => CultureInfo.InvariantCulture.CompareInfo.Compare(c, WellKnownDiagnosticTags.Compiler) == 0);
}
public bool CanBeSuppressed(Diagnostic diagnostic)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Reflection;
using Microsoft.CodeAnalysis.ErrorReporting;
using Roslyn.Utilities;
......@@ -50,8 +48,8 @@ public static bool IsCompilerAnalyzer(this DiagnosticAnalyzer analyzer)
public static string GetAnalyzerAssemblyName(this DiagnosticAnalyzer analyzer)
{
var type = analyzer.GetType();
return type.Assembly.GetName().Name;
var typeInfo = analyzer.GetType().GetTypeInfo();
return typeInfo.Assembly.GetName().Name;
}
private static string GetAssemblyQualifiedName(Type type)
......@@ -117,12 +115,12 @@ internal static Diagnostic CreateAnalyzerExceptionDiagnostic(DiagnosticAnalyzer
private static VersionStamp GetAnalyzerVersion(string path)
{
if (path == null || !File.Exists(path))
if (path == null || !PortableShim.File.Exists(path))
{
return VersionStamp.Default;
}
return VersionStamp.Create(File.GetLastWriteTimeUtc(path));
return VersionStamp.Create(PortableShim.File.GetLastWriteTimeUtc(path));
}
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.Diagnostics
{
internal sealed class DiagnosticData
{
public static readonly CultureInfo USCultureInfo = CultureInfo.GetCultureInfo("en-US");
public static readonly CultureInfo USCultureInfo = new CultureInfo("en-US");
public readonly string Id;
public readonly string Category;
......
......@@ -9,8 +9,9 @@ namespace Microsoft.CodeAnalysis.EditAndContinue
/// Fixed size rolling tracing log.
/// </summary>
/// <remarks>
/// Recent entries are captured in a memory dump.
/// All entries are printed out to <see cref="Trace"/> output or <see cref="Debug"/> output.
/// Recent entries are captured in a memory dump.
/// If DEBUG is defined, all entries written to <see cref="DebugWrite(string)"/> or
/// <see cref="DebugWrite(string, object[])"/> are print to <see cref="Debug"/> output.
/// </remarks>
internal sealed class TraceLog
{
......@@ -33,7 +34,6 @@ private void Append(string str)
public void Write(string str)
{
Append(str);
Trace.WriteLine(str, _id);
}
[Conditional("DEBUG")]
......
......@@ -371,7 +371,7 @@ private IList<ISymbol> CreateInterfaceMembers(IEnumerable<ISymbol> includedMembe
isIndexer: property.IsIndexer));
break;
default:
Debug.Assert(false, FeaturesResources.UnexpectedInterfaceMemberKind, member.Kind.ToString());
Debug.Assert(false, string.Format(FeaturesResources.UnexpectedInterfaceMemberKind, member.Kind.ToString()));
break;
}
}
......@@ -487,7 +487,7 @@ private bool DoesMemberReferenceTypeParameter(ISymbol member, ITypeParameterSymb
return property.Parameters.Any(t => DoesTypeReferenceTypeParameter(t.Type, typeParameter, checkedTypes)) ||
DoesTypeReferenceTypeParameter(property.Type, typeParameter, checkedTypes);
default:
Debug.Assert(false, FeaturesResources.UnexpectedInterfaceMemberKind, member.Kind.ToString());
Debug.Assert(false, string.Format(FeaturesResources.UnexpectedInterfaceMemberKind, member.Kind.ToString()));
return false;
}
}
......
......@@ -7,7 +7,6 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Formatting.Rules;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.ExtractMethod
......@@ -159,7 +158,7 @@ public async Task<ExtractMethodResult> ExtractMethodAsync(CancellationToken canc
internal static string MakeMethodName(string prefix, string originalName)
{
var startingWithLetter = originalName.SkipWhile(c => !char.IsLetter(c)).ToArray();
var startingWithLetter = originalName.ToCharArray().SkipWhile(c => !char.IsLetter(c)).ToArray();
var name = startingWithLetter.Length == 0 ? originalName : new string(startingWithLetter);
return char.IsUpper(name[0]) ?
......
......@@ -10,6 +10,7 @@
namespace Microsoft.CodeAnalysis {
using System;
using System.Reflection;
/// <summary>
......@@ -39,7 +40,7 @@ internal class FeaturesResources {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.CodeAnalysis.FeaturesResources", typeof(FeaturesResources).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.CodeAnalysis.FeaturesResources", typeof(FeaturesResources).GetTypeInfo().Assembly);
resourceMan = temp;
}
return resourceMan;
......
......@@ -522,7 +522,7 @@
<data name="UpdatingStateMachineMethodAroundActive" xml:space="preserve">
<value>Updating async or iterator modifier around an active statement will prevent the debug session from continuing.</value>
<comment>{Locked="async"}{Locked="iterator"} "async" and "iterator" are C#/VB keywords and should not be localized.</comment>
</data>
</data>
<data name="ModifyingAGenericMethodWillPrevent" xml:space="preserve">
<value>Modifying a generic method will prevent the debug session from continuing.</value>
</data>
......
......@@ -52,7 +52,7 @@ protected AbstractGenerateVariableService()
// prefer fields over properties (and vice versa) depending on the casing of the member.
// lowercase -> fields. title case -> properties.
var name = state.IdentifierToken.ValueText;
if (char.IsUpper(name.FirstOrDefault()))
if (char.IsUpper(name.ToCharArray().FirstOrDefault()))
{
if (canGenerateMember)
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
......@@ -25,7 +22,7 @@ internal abstract class AbstractIntroduceVariableCodeAction : CodeAction
private readonly TService _service;
private readonly string _title;
private static readonly Regex s_newlinePattern = new Regex(@"[\r\n]+", RegexOptions.Compiled);
private static readonly Regex s_newlinePattern = new Regex(@"[\r\n]+");
internal AbstractIntroduceVariableCodeAction(
TService service,
......
......@@ -10,7 +10,7 @@ namespace Microsoft.CodeAnalysis.MetadataAsSource
{
internal partial class AbstractMetadataAsSourceService
{
protected abstract class AbstractFormattingRule : Microsoft.CodeAnalysis.Formatting.Rules.AbstractFormattingRule
protected abstract class AbstractFormattingRule : Formatting.Rules.AbstractFormattingRule
{
protected abstract AdjustNewLinesOperation GetAdjustNewLinesOperationBetweenMembersAndUsings(SyntaxToken token1, SyntaxToken token2);
protected abstract bool IsNewLine(char c);
......@@ -52,7 +52,7 @@ protected int GetNumberOfLines(IEnumerable<SyntaxTrivia> triviaList)
}
inElasticTriviaRun = false;
count += trivia.ToFullString().Replace("\r\n", "\r").Count(IsNewLine);
count += trivia.ToFullString().Replace("\r\n", "\r").ToCharArray().Count(IsNewLine);
}
return count;
......
......@@ -3,8 +3,8 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Organizing.Organizers;
......@@ -40,7 +40,7 @@ public Task<Document> OrganizeAsync(Document document, IEnumerable<ISyntaxOrgani
{
return (from o in organizers
where !o.SyntaxNodeTypes.Any() ||
o.SyntaxNodeTypes.Any(t2 => t1 == t2 || t1.IsSubclassOf(t2))
o.SyntaxNodeTypes.Any(t2 => t1 == t2 || t1.GetTypeInfo().IsSubclassOf(t2))
select o).Distinct();
};
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.ComponentModel.Composition;
using System.Composition;
namespace Microsoft.CodeAnalysis.Organizing.Organizers
{
......
......@@ -6,12 +6,7 @@
using System.Collections.Immutable;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Shared.Extensions
......@@ -82,7 +77,7 @@ private static INamedTypeSymbol GetNamedType(ITypeSymbol type)
return xParam.IsParams ? 1 : -1;
}
diff = string.Compare(xTypeNames[i], yTypeNames[i], CultureInfo.CurrentUICulture, CompareOptions.StringSort);
diff = CultureInfo.CurrentUICulture.CompareInfo.Compare(xTypeNames[i], yTypeNames[i], CompareOptions.StringSort);
if (diff != 0)
{
return diff;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.ComponentModel.Composition;
using System.Composition;
namespace Microsoft.CodeAnalysis.Shared.TestHooks
{
......
......@@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Microsoft.CodeAnalysis.Text;
......@@ -79,7 +78,7 @@ private static TextChunk[] BreakPatternIntoTextChunks(string pattern, bool verba
if (partCount == 0)
{
return Array.Empty<TextChunk>();
return SpecializedCollections.EmptyArray<TextChunk>();
}
var result = new TextChunk[partCount];
......@@ -169,7 +168,7 @@ public PatternMatcher(string pattern, CultureInfo culture, bool verbatimIdentifi
if (pattern.IndexOf('.') < 0)
{
// PERF: Avoid string.Split allocations when the pattern doesn't contain a dot.
_dotSeparatedSegments = pattern.Length > 0 ? new Segment[1] { _fullPatternSegment } : Array.Empty<Segment>();
_dotSeparatedSegments = pattern.Length > 0 ? new Segment[1] { _fullPatternSegment } : SpecializedCollections.EmptyArray<Segment>();
}
else
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.SolutionCrawler
{
......@@ -25,7 +17,8 @@ public static string ToBase64(this string data)
public static string DecodeBase64(this string data)
{
return Encoding.UTF8.GetString(Convert.FromBase64String(data));
var bytes = Convert.FromBase64String(data);
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册