set up code generator project ahead of new features (xml, cancelation tokens, more verbs) because # of extension methods is about to explode
This commit is contained in:
parent
38dd670f06
commit
5567bcad94
6
Flurl.Http.CodeGen/App.config
Normal file
6
Flurl.Http.CodeGen/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
75
Flurl.Http.CodeGen/CodeWriter.cs
Normal file
75
Flurl.Http.CodeGen/CodeWriter.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Flurl.Http.CodeGen
|
||||
{
|
||||
/// <summary>
|
||||
/// Wraps a StreamWriter. Mainly just keeps track of indentation.
|
||||
/// </summary>
|
||||
public class CodeWriter : IDisposable
|
||||
{
|
||||
private readonly StreamWriter _sw;
|
||||
private int _indent = 0;
|
||||
private bool _wrapping = false;
|
||||
|
||||
public CodeWriter(string filePath) {
|
||||
_sw = new StreamWriter(filePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// use @0, @1, @2, etc for tokens. ({0} would be a pain because you'd alway need to escape "{" and "}")
|
||||
/// </summary>
|
||||
public CodeWriter WriteLine(string line, params object[] args) {
|
||||
line = line.Trim();
|
||||
|
||||
for (int i = 0; i < args.Length; i++) {
|
||||
var val = (args[i] == null) ? "" : args[i].ToString();
|
||||
line = line.Replace("@" + i, val);
|
||||
}
|
||||
|
||||
if (line == "}" || line == "{") {
|
||||
_indent--;
|
||||
}
|
||||
|
||||
_sw.Write(new String('\t', _indent));
|
||||
_sw.WriteLine(line);
|
||||
|
||||
if (line == "" || line.StartsWith("//") || line.EndsWith("]")) {
|
||||
_wrapping = false;
|
||||
}
|
||||
else if (line.EndsWith(";") || line.EndsWith("}")) {
|
||||
if (_wrapping) _indent--;
|
||||
_wrapping = false;
|
||||
}
|
||||
else if (line.EndsWith("{")) {
|
||||
_indent++;
|
||||
_wrapping = false;
|
||||
}
|
||||
else {
|
||||
if (!_wrapping) _indent++;
|
||||
_wrapping = true;
|
||||
}
|
||||
|
||||
return this; // fluent!
|
||||
}
|
||||
|
||||
public CodeWriter WriteLine() {
|
||||
_sw.WriteLine();
|
||||
return this;
|
||||
}
|
||||
|
||||
public CodeWriter WriteLines(IEnumerable<string> lines) {
|
||||
foreach (var line in lines)
|
||||
WriteLine(line);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
_sw.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
59
Flurl.Http.CodeGen/Flurl.Http.CodeGen.csproj
Normal file
59
Flurl.Http.CodeGen/Flurl.Http.CodeGen.csproj
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{0571F8FF-1649-433C-97F3-7341942AC886}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Flurl.Http.CodeGen</RootNamespace>
|
||||
<AssemblyName>Flurl.Http.CodeGen</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CodeWriter.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
35
Flurl.Http.CodeGen/Program.cs
Normal file
35
Flurl.Http.CodeGen/Program.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Flurl.Http.CodeGen
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args) {
|
||||
if (args.Length == 0)
|
||||
throw new ArgumentException("Must provide a path to the .cs output file.");
|
||||
|
||||
var codePath = args[0];
|
||||
using (var writer = new CodeWriter(codePath)) {
|
||||
writer
|
||||
.WriteLine("using System.Net.Http;")
|
||||
.WriteLine("using System.Threading.Tasks;")
|
||||
.WriteLine("using Flurl.Http.Content;")
|
||||
.WriteLine("")
|
||||
.WriteLine("namespace Flurl.Http")
|
||||
.WriteLine("{")
|
||||
.WriteLine("public static class HttpExtensions")
|
||||
.WriteLine("{");
|
||||
|
||||
writer.WriteLine("// extension methods here");
|
||||
|
||||
writer
|
||||
.WriteLine("}")
|
||||
.WriteLine("}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
36
Flurl.Http.CodeGen/Properties/AssemblyInfo.cs
Normal file
36
Flurl.Http.CodeGen/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Flurl.Http.CodeGen")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Flurl.Http.CodeGen")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("ad34a4a2-e63a-492e-9b24-8907c1da92c8")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
@ -67,6 +67,9 @@
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>"$(SolutionDir)Flurl.Http.CodeGen\bin\$(ConfigurationName)\Flurl.Http.CodeGen.exe" "$(SolutionDir)Flurl.Http.Shared\HttpExtensions.cs"</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
|
@ -25,6 +25,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)GetExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HeadExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HttpCall.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)HttpExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)PostExtensions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)PutExtensions.cs" />
|
||||
|
11
Flurl.Http.Shared/HttpExtensions.cs
Normal file
11
Flurl.Http.Shared/HttpExtensions.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl.Http.Content;
|
||||
|
||||
namespace Flurl.Http
|
||||
{
|
||||
public static class HttpExtensions
|
||||
{
|
||||
// extension methods here
|
||||
}
|
||||
}
|
32
Flurl.sln
32
Flurl.sln
@ -15,10 +15,16 @@ EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Flurl.Http.Shared", "Flurl.Http.Shared\Flurl.Http.Shared.shproj", "{734E6962-97E2-4318-9A2D-C87E76921AFB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flurl.Http.NET45", "Flurl.Http.NET45\Flurl.Http.NET45.csproj", "{E7001E27-E952-4E1A-A391-B14ADAE2A1A9}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886} = {0571F8FF-1649-433C-97F3-7341942AC886}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flurl", "Flurl\Flurl.csproj", "{70A34167-759E-4902-82E0-E6A84C2CE46F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flurl.Http.PCL", "Flurl.Http.PCL\Flurl.Http.PCL.csproj", "{4C163DD1-318A-42C0-ACF2-9E0D766D8900}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886} = {0571F8FF-1649-433C-97F3-7341942AC886}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{CF0659E1-9C0D-4D35-8FBA-CC5E94619853}"
|
||||
EndProject
|
||||
@ -30,6 +36,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flurl.Test.PCL", "Test\Flur
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PackageTester.PCL", "PackageTester.PCL\PackageTester.PCL.csproj", "{0A32978C-BC48-4DFB-B1F7-B88541B0D686}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flurl.Http.CodeGen", "Flurl.Http.CodeGen\Flurl.Http.CodeGen.csproj", "{0571F8FF-1649-433C-97F3-7341942AC886}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
Test\Flurl.Test.Shared\Flurl.Test.Shared.projitems*{4c7c0861-84f6-436e-8fa6-4c318b336a7b}*SharedItemsImports = 13
|
||||
@ -226,6 +234,30 @@ Global
|
||||
{0A32978C-BC48-4DFB-B1F7-B88541B0D686}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{0A32978C-BC48-4DFB-B1F7-B88541B0D686}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{0A32978C-BC48-4DFB-B1F7-B88541B0D686}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Ad-Hoc|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Ad-Hoc|Any CPU.Build.0 = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Ad-Hoc|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Ad-Hoc|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.AppStore|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.AppStore|Any CPU.Build.0 = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.AppStore|iPhone.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.AppStore|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.AppStore|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.AppStore|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
|
||||
{0571F8FF-1649-433C-97F3-7341942AC886}.Release|Mixed Platforms.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
x
Reference in New Issue
Block a user