提交 769d5554 编写于 作者: S Stephen Toub

Add System.CodeDom to corefx

This ports the type model and C#/VB code generators to corefx; compilation to assemblies is currently not supported (we could potentially layer that on top of Roslyn subsequently).  I also ported a bunch of tests, though there's lots of room for improvement on the test suite.


Commit migrated from https://github.com/dotnet/corefx/commit/91bc9da917d184c5579f66b4512462d8f3064b90
上级 19cd42c5

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{350C956A-B4ED-4376-9B04-2908528D10FF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.CodeDom", "ref\System.CodeDom.csproj", "{14FAFC3A-8266-45C7-8604-8C2CB567E50D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{827B5CCD-073A-4A75-9661-73D54F0A3528}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.CodeDom", "src\System.CodeDom.csproj", "{53D09AF4-0C13-4197-B8AD-9746F0374E88}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{096E7AD0-17A2-4EAF-9AC5-2F0FC67A4112}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.CodeDom.Tests", "tests\System.CodeDom.Tests.csproj", "{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
net46_Debug|Any CPU = net46_Debug|Any CPU
net46_Release|Any CPU = net46_Release|Any CPU
netstandard1.7_Debug|Any CPU = netstandard1.7_Debug|Any CPU
netstandard1.7_Release|Any CPU = netstandard1.7_Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{14FAFC3A-8266-45C7-8604-8C2CB567E50D}.net46_Debug|Any CPU.ActiveCfg = netstandard1.7_Release|Any CPU
{14FAFC3A-8266-45C7-8604-8C2CB567E50D}.net46_Debug|Any CPU.Build.0 = netstandard1.7_Release|Any CPU
{14FAFC3A-8266-45C7-8604-8C2CB567E50D}.net46_Release|Any CPU.ActiveCfg = netstandard1.7_Release|Any CPU
{14FAFC3A-8266-45C7-8604-8C2CB567E50D}.net46_Release|Any CPU.Build.0 = netstandard1.7_Release|Any CPU
{14FAFC3A-8266-45C7-8604-8C2CB567E50D}.netstandard1.7_Debug|Any CPU.ActiveCfg = netstandard1.7_Debug|Any CPU
{14FAFC3A-8266-45C7-8604-8C2CB567E50D}.netstandard1.7_Debug|Any CPU.Build.0 = netstandard1.7_Debug|Any CPU
{14FAFC3A-8266-45C7-8604-8C2CB567E50D}.netstandard1.7_Release|Any CPU.ActiveCfg = netstandard1.7_Release|Any CPU
{14FAFC3A-8266-45C7-8604-8C2CB567E50D}.netstandard1.7_Release|Any CPU.Build.0 = netstandard1.7_Release|Any CPU
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.net46_Debug|Any CPU.ActiveCfg = net463_Release|Any CPU
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.net46_Debug|Any CPU.Build.0 = net463_Release|Any CPU
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.net46_Release|Any CPU.ActiveCfg = net463_Release|Any CPU
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.net46_Release|Any CPU.Build.0 = net463_Release|Any CPU
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.netstandard1.7_Debug|Any CPU.ActiveCfg = netstandard1.7_Debug|Any CPU
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.netstandard1.7_Debug|Any CPU.Build.0 = netstandard1.7_Debug|Any CPU
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.netstandard1.7_Release|Any CPU.ActiveCfg = netstandard1.7_Release|Any CPU
{53D09AF4-0C13-4197-B8AD-9746F0374E88}.netstandard1.7_Release|Any CPU.Build.0 = netstandard1.7_Release|Any CPU
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.net46_Debug|Any CPU.ActiveCfg = netstandard1.7_Release|Any CPU
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.net46_Debug|Any CPU.Build.0 = netstandard1.7_Release|Any CPU
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.net46_Release|Any CPU.ActiveCfg = netstandard1.7_Release|Any CPU
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.net46_Release|Any CPU.Build.0 = netstandard1.7_Release|Any CPU
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.netstandard1.7_Debug|Any CPU.ActiveCfg = netstandard1.7_Debug|Any CPU
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.netstandard1.7_Debug|Any CPU.Build.0 = netstandard1.7_Debug|Any CPU
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.netstandard1.7_Release|Any CPU.ActiveCfg = netstandard1.7_Release|Any CPU
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726}.netstandard1.7_Release|Any CPU.Build.0 = netstandard1.7_Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{14FAFC3A-8266-45C7-8604-8C2CB567E50D} = {350C956A-B4ED-4376-9B04-2908528D10FF}
{53D09AF4-0C13-4197-B8AD-9746F0374E88} = {827B5CCD-073A-4A75-9661-73D54F0A3528}
{0D1E2954-A5C7-4B8C-932A-31EB4A96A726} = {096E7AD0-17A2-4EAF-9AC5-2F0FC67A4112}
EndGlobalSection
EndGlobal
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</PropertyGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<Project Include="System.CodeDom.pkgproj"/>
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.traversal.targets))\dir.traversal.targets" />
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<ItemGroup>
<ProjectReference Include="..\ref\System.CodeDom.csproj">
<SupportedFramework>net463;netcoreapp1.1;$(AllXamarinFrameworks)</SupportedFramework>
</ProjectReference>
<ProjectReference Include="..\src\System.CodeDom.builds" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
此差异已折叠。
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<PropertyGroup>
<OutputType>Library</OutputType>
<NuGetTargetMoniker>.NETStandard,Version=v1.7</NuGetTargetMoniker>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.7_Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard1.7_Release|AnyCPU'" />
<ItemGroup>
<Compile Include="System.CodeDom.cs" />
</ItemGroup>
<ItemGroup>
<None Include="project.json" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
{
"dependencies": {
"System.Collections.Specialized": "4.3.0-beta-24522-03",
"System.ComponentModel.TypeConverter": "4.3.0-beta-24522-03",
"System.Collections.NonGeneric": "4.3.0-beta-24522-03",
"System.Collections.Specialized": "4.3.0-beta-24522-03",
"System.IO": "4.3.0-beta-24522-03",
"System.Reflection": "4.3.0-beta-24522-03",
"System.Runtime": "4.3.0-beta-24522-03",
"System.Security.Permissions": "4.3.0-beta-24522-03",
"System.Text.Encoding": "4.3.0-beta-24522-03"
},
"frameworks": {
"netstandard1.7": {
"imports": [
"dotnet5.8"
]
}
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using System.ComponentModel;
using System.Reflection;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
namespace Microsoft.CSharp
{
public class CSharpCodeProvider : CodeDomProvider
{
private readonly CSharpCodeGenerator _generator;
public CSharpCodeProvider()
{
_generator = new CSharpCodeGenerator();
}
public CSharpCodeProvider(IDictionary<string, string> providerOptions)
{
if (providerOptions == null)
{
throw new ArgumentNullException(nameof(providerOptions));
}
_generator = new CSharpCodeGenerator(providerOptions);
}
public override string FileExtension => "cs";
[Obsolete("Callers should not use the ICodeGenerator interface and should instead use the methods directly on the CodeDomProvider class.")]
public override ICodeGenerator CreateGenerator() => _generator;
[Obsolete("Callers should not use the ICodeCompiler interface and should instead use the methods directly on the CodeDomProvider class.")]
public override ICodeCompiler CreateCompiler() => _generator;
public override TypeConverter GetConverter(Type type) =>
type == typeof(MemberAttributes) ? CSharpMemberAttributeConverter.Default :
type == typeof(TypeAttributes) ? CSharpTypeAttributeConverter.Default :
base.GetConverter(type);
public override void GenerateCodeFromMember(CodeTypeMember member, TextWriter writer, CodeGeneratorOptions options) =>
_generator.GenerateCodeFromMember(member, writer, options);
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.CodeDom;
namespace Microsoft.CSharp
{
internal class CSharpMemberAttributeConverter : CSharpModifierAttributeConverter
{
private CSharpMemberAttributeConverter() { } // no need to create an instance; use Default
public static CSharpMemberAttributeConverter Default { get; } = new CSharpMemberAttributeConverter();
protected override string[] Names { get; } = new[] { "Public", "Protected", "Protected Internal", "Internal", "Private" };
protected override object[] Values { get; } =
new object[] { MemberAttributes.Public, MemberAttributes.Family, MemberAttributes.FamilyOrAssembly, MemberAttributes.Assembly, MemberAttributes.Private };
protected override object DefaultValue => MemberAttributes.Private;
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.ComponentModel;
using System.Globalization;
namespace Microsoft.CSharp
{
internal abstract class CSharpModifierAttributeConverter : TypeConverter
{
protected abstract object[] Values { get; }
protected abstract string[] Names { get; }
protected abstract object DefaultValue { get; }
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) =>
sourceType == typeof(string) ? true : base.CanConvertFrom(context, sourceType);
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string name = value as string;
if (name != null)
{
string[] names = Names;
for (int i = 0; i < names.Length; i++)
{
if (names[i].Equals(name))
{
return Values[i];
}
}
}
return DefaultValue;
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == null)
{
throw new ArgumentNullException(nameof(destinationType));
}
if (destinationType == typeof(string))
{
object[] modifiers = Values;
for (int i = 0; i < modifiers.Length; i++)
{
if (modifiers[i].Equals(value))
{
return Names[i];
}
}
return SR.toStringUnknown;
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => true;
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) => new StandardValuesCollection(Values);
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Reflection;
namespace Microsoft.CSharp
{
internal class CSharpTypeAttributeConverter : CSharpModifierAttributeConverter
{
private CSharpTypeAttributeConverter() { } // no need to create an instance; use Default
public static CSharpTypeAttributeConverter Default { get; } = new CSharpTypeAttributeConverter();
protected override string[] Names { get; } = new[] { "Public", "Internal" };
protected override object[] Values { get; } = new object[] { TypeAttributes.Public, TypeAttributes.NotPublic };
protected override object DefaultValue => TypeAttributes.NotPublic;
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using System.ComponentModel;
using System.Reflection;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
namespace Microsoft.VisualBasic
{
public class VBCodeProvider : CodeDomProvider
{
private VBCodeGenerator _generator;
public VBCodeProvider()
{
_generator = new VBCodeGenerator();
}
public VBCodeProvider(IDictionary<string, string> providerOptions)
{
if (providerOptions == null)
{
throw new ArgumentNullException(nameof(providerOptions));
}
_generator = new VBCodeGenerator(providerOptions);
}
public override string FileExtension => "vb";
public override LanguageOptions LanguageOptions => LanguageOptions.CaseInsensitive;
[Obsolete("Callers should not use the ICodeGenerator interface and should instead use the methods directly on the CodeDomProvider class.")]
public override ICodeGenerator CreateGenerator() => _generator;
[Obsolete("Callers should not use the ICodeCompiler interface and should instead use the methods directly on the CodeDomProvider class.")]
public override ICodeCompiler CreateCompiler() => _generator;
public override TypeConverter GetConverter(Type type) =>
type == typeof(MemberAttributes) ? VBMemberAttributeConverter.Default :
type == typeof(TypeAttributes) ? VBTypeAttributeConverter.Default :
base.GetConverter(type);
public override void GenerateCodeFromMember(CodeTypeMember member, TextWriter writer, CodeGeneratorOptions options) =>
_generator.GenerateCodeFromMember(member, writer, options);
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册