Ifdef to make stuff compile on both platforms.

This commit is contained in:
David Fowler 2014-01-24 02:20:46 -08:00
parent b0933fdd35
commit a0de7048b5
19 changed files with 59 additions and 25 deletions

View File

@ -1,4 +1,4 @@
#if NET45 #if OWIN
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;

View File

@ -1,4 +1,5 @@
using System; #if VIEWMETADATA
using System;
using System.Collections.Generic; using System.Collections.Generic;
public class ViewMetadata public class ViewMetadata
@ -21,3 +22,4 @@ public class ViewMetadata
} }
} }
} }
#endif

View File

@ -1,4 +1,5 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #if NET45
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
@ -52,3 +53,4 @@ namespace Microsoft.AspNet.Mvc
} }
} }
} }
#endif

View File

@ -1,6 +1,7 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System; using System;
using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
@ -67,8 +68,7 @@ namespace Microsoft.AspNet.Mvc
if (htmlAttributes != null) if (htmlAttributes != null)
{ {
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(htmlAttributes); foreach (var prop in htmlAttributes.GetType().GetRuntimeProperties())
foreach (PropertyDescriptor prop in properties)
{ {
object val = prop.GetValue(htmlAttributes); object val = prop.GetValue(htmlAttributes);
result.Add(prop.Name, val); result.Add(prop.Name, val);

View File

@ -1,4 +1,5 @@
using System; #if NET45
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -170,3 +171,4 @@ namespace Microsoft.AspNet.Mvc
} }
} }
} }
#endif

View File

@ -1,4 +1,5 @@
using System; #if NET45
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@ -110,4 +111,4 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
} }
#endif

View File

@ -66,6 +66,10 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140124091736\lib\k10\Microsoft.AspNet.Abstractions.dll</HintPath> <HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140124091736\lib\k10\Microsoft.AspNet.Abstractions.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.AspNet.DependencyInjection, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.DependencyInjection.0.1-alpha-t140123020341\lib\k10\Microsoft.AspNet.DependencyInjection.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNet.Mvc\Microsoft.AspNet.Mvc.k10.csproj"> <ProjectReference Include="..\..\src\Microsoft.AspNet.Mvc\Microsoft.AspNet.Mvc.k10.csproj">

View File

@ -46,6 +46,10 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140124091736\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath> <HintPath>..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140124091736\lib\net45\Microsoft.AspNet.Abstractions.dll</HintPath>
</Reference> </Reference>
<Reference Include="Microsoft.AspNet.DependencyInjection, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.DependencyInjection.0.1-alpha-t140123020341\lib\net45\Microsoft.AspNet.DependencyInjection.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"> <Reference Include="System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.Razor.3.1.0\lib\net45\System.Web.Razor.dll</HintPath> <HintPath>..\..\packages\Microsoft.AspNet.Razor.3.1.0\lib\net45\System.Web.Razor.dll</HintPath>

View File

@ -1,4 +1,5 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #if NET45
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System.CodeDom; using System.CodeDom;
using System.Web.Razor; using System.Web.Razor;
@ -27,3 +28,4 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
} }
} }
#endif

View File

@ -1,4 +1,5 @@
using System.Web.Razor; #if NET45
using System.Web.Razor;
using System.Web.Razor.Generator; using System.Web.Razor.Generator;
using System.Web.Razor.Parser; using System.Web.Razor.Parser;
@ -51,3 +52,4 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
} }
} }
#endif

View File

@ -1,4 +1,5 @@
using System.CodeDom.Compiler; #if NET45
using System.CodeDom.Compiler;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -59,3 +60,4 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
} }
} }
#endif

View File

@ -1,4 +1,5 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. #if NET45
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
using System; using System;
using System.Globalization; using System.Globalization;
@ -25,3 +26,4 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
} }
} }
#endif

View File

@ -71,7 +71,9 @@ namespace Microsoft.AspNet.Mvc.Razor
} }
else else
{ {
#if NET45
WebUtility.HtmlEncode(content.ToString(), writer); WebUtility.HtmlEncode(content.ToString(), writer);
#endif
} }
} }
} }

View File

@ -15,17 +15,19 @@ namespace Microsoft.AspNet.Mvc.Razor
var metadataType = assembly.GetType("ViewMetadata"); var metadataType = assembly.GetType("ViewMetadata");
if (metadataType != null) if (metadataType != null)
{ {
object metadata = metadataType.GetProperty("Metadata", BindingFlags.Static | BindingFlags.Public) object metadata = metadataType.GetRuntimeProperties().First(prop => prop.Name == "Metadata")
.GetValue(obj: null); .GetValue(obj: null);
_viewMetadata = new Dictionary<string, Type>((Dictionary<string, Type>)metadata, StringComparer.OrdinalIgnoreCase); _viewMetadata = new Dictionary<string, Type>((Dictionary<string, Type>)metadata, StringComparer.OrdinalIgnoreCase);
} }
else else
{ {
#if NET45
// Code to support precompiled views generated via RazorGenerator // Code to support precompiled views generated via RazorGenerator
_viewMetadata = assembly.GetExportedTypes() _viewMetadata = assembly.GetExportedTypes()
.Where(type => typeof(RazorView).IsAssignableFrom(type)) .Where(type => typeof(RazorView).IsAssignableFrom(type))
.ToDictionary(type => GetVirtualPath(type), StringComparer.OrdinalIgnoreCase); .ToDictionary(type => GetVirtualPath(type), StringComparer.OrdinalIgnoreCase);
#endif
} }
} }
@ -42,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.Razor
private static string GetVirtualPath(Type type) private static string GetVirtualPath(Type type)
{ {
VirtualPathAttribute attribute = type.GetCustomAttribute<VirtualPathAttribute>(); VirtualPathAttribute attribute = type.GetTypeInfo().GetCustomAttribute<VirtualPathAttribute>();
return attribute.VirtualPath; return attribute.VirtualPath;
} }
} }

View File

@ -3,6 +3,7 @@
"dependencies": { "dependencies": {
"Microsoft.AspNet.FileSystems": "0.1-alpha-*", "Microsoft.AspNet.FileSystems": "0.1-alpha-*",
"Microsoft.AspNet.Abstractions": "0.1-alpha-*", "Microsoft.AspNet.Abstractions": "0.1-alpha-*",
"Microsoft.AspNet.DependencyInjection": "0.1-alpha-*",
"Microsoft.AspNet.Razor" : "3.1.0", "Microsoft.AspNet.Razor" : "3.1.0",
"Microsoft.AspNet.Mvc" : "", "Microsoft.AspNet.Mvc" : "",
"Microsoft.AspNet.Mvc.Forms" : "" "Microsoft.AspNet.Mvc.Forms" : ""

View File

@ -17,7 +17,11 @@ namespace Microsoft.AspNet.Mvc
HttpResponse response = context.HttpContext.Response; HttpResponse response = context.HttpContext.Response;
#if NET45
response.StatusCode = (int)HttpStatusCode.NoContent; response.StatusCode = (int)HttpStatusCode.NoContent;
#else
response.StatusCode = 204;
#endif
await Task.FromResult(false); await Task.FromResult(false);

View File

@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Mvc
Initialize(controller); Initialize(controller);
var method = controller.GetType().GetMethod(_descriptor.ActionName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); var method = controller.GetType().GetRuntimeMethods().FirstOrDefault(m => m.Name.Equals(_descriptor.ActionName, StringComparison.OrdinalIgnoreCase));
if (method == null) if (method == null)
{ {
@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Mvc
{ {
var controllerType = controller.GetType(); var controllerType = controller.GetType();
foreach (var prop in controllerType.GetProperties()) foreach (var prop in controllerType.GetRuntimeProperties())
{ {
if (prop.Name == "Context") if (prop.Name == "Context")
{ {
@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Mvc
} }
} }
var method = controllerType.GetMethod("Initialize"); var method = controllerType.GetTypeInfo().GetDeclaredMethod("Initialize");
if (method == null) if (method == null)
{ {

View File

@ -24,8 +24,10 @@ namespace Microsoft.AspNet.Mvc
foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{ {
var type = a.GetType(controllerName) ?? var type = a.GetType(controllerName) ??
a.GetType(a.GetName().Name + "." + controllerName) ?? a.GetType(a.GetName().Name + "." + controllerName);
a.GetTypes().FirstOrDefault(t => t.Name.Equals(controllerName, StringComparison.OrdinalIgnoreCase)); #if NET45
type = type ?? a.GetTypes().FirstOrDefault(t => t.Name.Equals(controllerName, StringComparison.OrdinalIgnoreCase));
#endif
if (type != null) if (type != null)
{ {

View File

@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Mvc
{ {
internal static class TypeExtensions internal static class TypeExtensions
{ {
#if NETFX_CORE #if NETFX_CORE || K10
private static bool EqualTo(this Type[] t1, Type[] t2) private static bool EqualTo(this Type[] t1, Type[] t2)
{ {
if (t1.Length != t2.Length) if (t1.Length != t2.Length)
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc
return (matchesInterface(queryType)) ? queryType : queryType.GetInterfaces().FirstOrDefault(matchesInterface); return (matchesInterface(queryType)) ? queryType : queryType.GetInterfaces().FirstOrDefault(matchesInterface);
} }
#if NETFX_CORE #if NETFX_CORE || K10
public static Type[] GetGenericArguments(this Type type) public static Type[] GetGenericArguments(this Type type)
{ {
return type.GetTypeInfo().GenericTypeArguments; return type.GetTypeInfo().GenericTypeArguments;
@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Mvc
} }
#endif #endif
#if NETFX_CORE #if NETFX_CORE || K10
public static bool IsAssignableFrom(this Type type, Type c) public static bool IsAssignableFrom(this Type type, Type c)
{ {
return type.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo()); return type.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo());
@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Mvc
public static bool IsGenericType(this Type type) public static bool IsGenericType(this Type type)
{ {
#if NETFX_CORE #if NETFX_CORE || K10
return type.GetTypeInfo().IsGenericType; return type.GetTypeInfo().IsGenericType;
#else #else
return type.IsGenericType; return type.IsGenericType;
@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Mvc
public static bool IsInterface(this Type type) public static bool IsInterface(this Type type)
{ {
#if NETFX_CORE #if NETFX_CORE || K10
return type.GetTypeInfo().IsInterface; return type.GetTypeInfo().IsInterface;
#else #else
return type.IsInterface; return type.IsInterface;
@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Mvc
public static bool IsValueType(this Type type) public static bool IsValueType(this Type type)
{ {
#if NETFX_CORE #if NETFX_CORE || K10
return type.GetTypeInfo().IsValueType; return type.GetTypeInfo().IsValueType;
#else #else
return type.IsValueType; return type.IsValueType;