From a0de7048b5fea3e4cb30034e2723c299485954c5 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 24 Jan 2014 02:20:46 -0800 Subject: [PATCH] Ifdef to make stuff compile on both platforms. --- samples/MvcSample/Startup.cs | 2 +- samples/MvcSample/ViewMetadata.cs | 4 +++- src/Microsoft.AspNet.Mvc.Forms/CryptoUtil.cs | 4 +++- src/Microsoft.AspNet.Mvc.Forms/Html/HtmlHelper.cs | 4 ++-- src/Microsoft.AspNet.Mvc.Forms/TypeHelpers.cs | 4 +++- .../Compilation/CscBasedCompilationService.cs | 5 +++-- .../Microsoft.AspNet.Mvc.Razor.k10.csproj | 4 ++++ .../Microsoft.AspNet.Mvc.Razor.net45.csproj | 4 ++++ .../Razor/MvcCSharpRazorCodeGenerator.cs | 4 +++- src/Microsoft.AspNet.Mvc.Razor/Razor/MvcRazorHost.cs | 4 +++- .../Razor/RazorCompilationService.cs | 4 +++- .../Razor/SetModelTypeCodeGenerator.cs | 4 +++- src/Microsoft.AspNet.Mvc.Razor/RazorView.cs | 2 ++ .../ViewEngine/MetadataVirtualPathViewFactory.cs | 6 ++++-- src/Microsoft.AspNet.Mvc.Razor/project.json | 1 + .../ActionResults/NoContentResult.cs | 4 ++++ src/Microsoft.AspNet.Mvc/ControllerActionInvoker.cs | 6 +++--- src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs | 6 ++++-- .../Extensions/TypeExtensions.cs | 12 ++++++------ 19 files changed, 59 insertions(+), 25 deletions(-) diff --git a/samples/MvcSample/Startup.cs b/samples/MvcSample/Startup.cs index e754bf689e..9696a04544 100644 --- a/samples/MvcSample/Startup.cs +++ b/samples/MvcSample/Startup.cs @@ -1,4 +1,4 @@ -#if NET45 +#if OWIN using System; using System.Threading.Tasks; using Microsoft.AspNet.Mvc; diff --git a/samples/MvcSample/ViewMetadata.cs b/samples/MvcSample/ViewMetadata.cs index 1050f363b7..dc11624a2b 100644 --- a/samples/MvcSample/ViewMetadata.cs +++ b/samples/MvcSample/ViewMetadata.cs @@ -1,4 +1,5 @@ -using System; +#if VIEWMETADATA +using System; using System.Collections.Generic; public class ViewMetadata @@ -21,3 +22,4 @@ public class ViewMetadata } } } +#endif \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Forms/CryptoUtil.cs b/src/Microsoft.AspNet.Mvc.Forms/CryptoUtil.cs index 134af5003c..9619c0dc59 100644 --- a/src/Microsoft.AspNet.Mvc.Forms/CryptoUtil.cs +++ b/src/Microsoft.AspNet.Mvc.Forms/CryptoUtil.cs @@ -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.Diagnostics.CodeAnalysis; @@ -52,3 +53,4 @@ namespace Microsoft.AspNet.Mvc } } } +#endif \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Forms/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Forms/Html/HtmlHelper.cs index 87a176c51b..91d2588804 100644 --- a/src/Microsoft.AspNet.Mvc.Forms/Html/HtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Forms/Html/HtmlHelper.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information. using System; +using System.Reflection; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; @@ -67,8 +68,7 @@ namespace Microsoft.AspNet.Mvc if (htmlAttributes != null) { - PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(htmlAttributes); - foreach (PropertyDescriptor prop in properties) + foreach (var prop in htmlAttributes.GetType().GetRuntimeProperties()) { object val = prop.GetValue(htmlAttributes); result.Add(prop.Name, val); diff --git a/src/Microsoft.AspNet.Mvc.Forms/TypeHelpers.cs b/src/Microsoft.AspNet.Mvc.Forms/TypeHelpers.cs index b26a2b8446..291cf2957a 100644 --- a/src/Microsoft.AspNet.Mvc.Forms/TypeHelpers.cs +++ b/src/Microsoft.AspNet.Mvc.Forms/TypeHelpers.cs @@ -1,4 +1,5 @@ -using System; +#if NET45 +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -170,3 +171,4 @@ namespace Microsoft.AspNet.Mvc } } } +#endif \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CscBasedCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CscBasedCompilationService.cs index 20e50fc2e0..de94fea857 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CscBasedCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CscBasedCompilationService.cs @@ -1,4 +1,5 @@ -using System; +#if NET45 +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -110,4 +111,4 @@ namespace Microsoft.AspNet.Mvc.Razor } } - +#endif \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/Microsoft.AspNet.Mvc.Razor.k10.csproj b/src/Microsoft.AspNet.Mvc.Razor/Microsoft.AspNet.Mvc.Razor.k10.csproj index 342fbad60c..76cb84aa31 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Microsoft.AspNet.Mvc.Razor.k10.csproj +++ b/src/Microsoft.AspNet.Mvc.Razor/Microsoft.AspNet.Mvc.Razor.k10.csproj @@ -66,6 +66,10 @@ False ..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140124091736\lib\k10\Microsoft.AspNet.Abstractions.dll + + False + ..\..\packages\Microsoft.AspNet.DependencyInjection.0.1-alpha-t140123020341\lib\k10\Microsoft.AspNet.DependencyInjection.dll + diff --git a/src/Microsoft.AspNet.Mvc.Razor/Microsoft.AspNet.Mvc.Razor.net45.csproj b/src/Microsoft.AspNet.Mvc.Razor/Microsoft.AspNet.Mvc.Razor.net45.csproj index b758b106bd..ea90ba63bd 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Microsoft.AspNet.Mvc.Razor.net45.csproj +++ b/src/Microsoft.AspNet.Mvc.Razor/Microsoft.AspNet.Mvc.Razor.net45.csproj @@ -46,6 +46,10 @@ False ..\..\packages\Microsoft.AspNet.Abstractions.0.1-alpha-t140124091736\lib\net45\Microsoft.AspNet.Abstractions.dll + + False + ..\..\packages\Microsoft.AspNet.DependencyInjection.0.1-alpha-t140123020341\lib\net45\Microsoft.AspNet.DependencyInjection.dll + False ..\..\packages\Microsoft.AspNet.Razor.3.1.0\lib\net45\System.Web.Razor.dll diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/MvcCSharpRazorCodeGenerator.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/MvcCSharpRazorCodeGenerator.cs index b5ea2e668c..ca0af7aa0f 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/MvcCSharpRazorCodeGenerator.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/MvcCSharpRazorCodeGenerator.cs @@ -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.Web.Razor; @@ -27,3 +28,4 @@ namespace Microsoft.AspNet.Mvc.Razor } } } +#endif \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/MvcRazorHost.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/MvcRazorHost.cs index 3afe900732..25a5a347ec 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/MvcRazorHost.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/MvcRazorHost.cs @@ -1,4 +1,5 @@ -using System.Web.Razor; +#if NET45 +using System.Web.Razor; using System.Web.Razor.Generator; using System.Web.Razor.Parser; @@ -51,3 +52,4 @@ namespace Microsoft.AspNet.Mvc.Razor } } } +#endif \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs index c549708deb..6b75b043f8 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs @@ -1,4 +1,5 @@ -using System.CodeDom.Compiler; +#if NET45 +using System.CodeDom.Compiler; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -59,3 +60,4 @@ namespace Microsoft.AspNet.Mvc.Razor } } } +#endif \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/SetModelTypeCodeGenerator.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/SetModelTypeCodeGenerator.cs index b85c0b1d17..392e956fb1 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/SetModelTypeCodeGenerator.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/SetModelTypeCodeGenerator.cs @@ -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.Globalization; @@ -25,3 +26,4 @@ namespace Microsoft.AspNet.Mvc.Razor } } } +#endif \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs index 3b399aafa1..f57b3ef346 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs @@ -71,7 +71,9 @@ namespace Microsoft.AspNet.Mvc.Razor } else { +#if NET45 WebUtility.HtmlEncode(content.ToString(), writer); +#endif } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/MetadataVirtualPathViewFactory.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/MetadataVirtualPathViewFactory.cs index 824fe71733..6535c45574 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/MetadataVirtualPathViewFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/MetadataVirtualPathViewFactory.cs @@ -15,17 +15,19 @@ namespace Microsoft.AspNet.Mvc.Razor var metadataType = assembly.GetType("ViewMetadata"); if (metadataType != null) { - object metadata = metadataType.GetProperty("Metadata", BindingFlags.Static | BindingFlags.Public) + object metadata = metadataType.GetRuntimeProperties().First(prop => prop.Name == "Metadata") .GetValue(obj: null); _viewMetadata = new Dictionary((Dictionary)metadata, StringComparer.OrdinalIgnoreCase); } else { +#if NET45 // Code to support precompiled views generated via RazorGenerator _viewMetadata = assembly.GetExportedTypes() .Where(type => typeof(RazorView).IsAssignableFrom(type)) .ToDictionary(type => GetVirtualPath(type), StringComparer.OrdinalIgnoreCase); +#endif } } @@ -42,7 +44,7 @@ namespace Microsoft.AspNet.Mvc.Razor private static string GetVirtualPath(Type type) { - VirtualPathAttribute attribute = type.GetCustomAttribute(); + VirtualPathAttribute attribute = type.GetTypeInfo().GetCustomAttribute(); return attribute.VirtualPath; } } diff --git a/src/Microsoft.AspNet.Mvc.Razor/project.json b/src/Microsoft.AspNet.Mvc.Razor/project.json index 8136583267..5c14544655 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/project.json +++ b/src/Microsoft.AspNet.Mvc.Razor/project.json @@ -3,6 +3,7 @@ "dependencies": { "Microsoft.AspNet.FileSystems": "0.1-alpha-*", "Microsoft.AspNet.Abstractions": "0.1-alpha-*", + "Microsoft.AspNet.DependencyInjection": "0.1-alpha-*", "Microsoft.AspNet.Razor" : "3.1.0", "Microsoft.AspNet.Mvc" : "", "Microsoft.AspNet.Mvc.Forms" : "" diff --git a/src/Microsoft.AspNet.Mvc/ActionResults/NoContentResult.cs b/src/Microsoft.AspNet.Mvc/ActionResults/NoContentResult.cs index 90997bddc9..39318e0f68 100644 --- a/src/Microsoft.AspNet.Mvc/ActionResults/NoContentResult.cs +++ b/src/Microsoft.AspNet.Mvc/ActionResults/NoContentResult.cs @@ -17,7 +17,11 @@ namespace Microsoft.AspNet.Mvc HttpResponse response = context.HttpContext.Response; +#if NET45 response.StatusCode = (int)HttpStatusCode.NoContent; +#else + response.StatusCode = 204; +#endif await Task.FromResult(false); diff --git a/src/Microsoft.AspNet.Mvc/ControllerActionInvoker.cs b/src/Microsoft.AspNet.Mvc/ControllerActionInvoker.cs index 5cc017740f..d1612b7b39 100644 --- a/src/Microsoft.AspNet.Mvc/ControllerActionInvoker.cs +++ b/src/Microsoft.AspNet.Mvc/ControllerActionInvoker.cs @@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Mvc 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) { @@ -57,7 +57,7 @@ namespace Microsoft.AspNet.Mvc { var controllerType = controller.GetType(); - foreach (var prop in controllerType.GetProperties()) + foreach (var prop in controllerType.GetRuntimeProperties()) { 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) { diff --git a/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs b/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs index a56801db73..f55cea3a44 100644 --- a/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs +++ b/src/Microsoft.AspNet.Mvc/DefaultControllerFactory.cs @@ -24,8 +24,10 @@ namespace Microsoft.AspNet.Mvc foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) { var type = a.GetType(controllerName) ?? - a.GetType(a.GetName().Name + "." + controllerName) ?? - a.GetTypes().FirstOrDefault(t => t.Name.Equals(controllerName, StringComparison.OrdinalIgnoreCase)); + a.GetType(a.GetName().Name + "." + controllerName); +#if NET45 + type = type ?? a.GetTypes().FirstOrDefault(t => t.Name.Equals(controllerName, StringComparison.OrdinalIgnoreCase)); +#endif if (type != null) { diff --git a/src/Microsoft.AspNet.Mvc/Extensions/TypeExtensions.cs b/src/Microsoft.AspNet.Mvc/Extensions/TypeExtensions.cs index 9c0845d867..09e4c830ae 100644 --- a/src/Microsoft.AspNet.Mvc/Extensions/TypeExtensions.cs +++ b/src/Microsoft.AspNet.Mvc/Extensions/TypeExtensions.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Mvc { internal static class TypeExtensions { -#if NETFX_CORE +#if NETFX_CORE || K10 private static bool EqualTo(this Type[] t1, Type[] t2) { if (t1.Length != t2.Length) @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc return (matchesInterface(queryType)) ? queryType : queryType.GetInterfaces().FirstOrDefault(matchesInterface); } -#if NETFX_CORE +#if NETFX_CORE || K10 public static Type[] GetGenericArguments(this Type type) { return type.GetTypeInfo().GenericTypeArguments; @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Mvc } #endif -#if NETFX_CORE +#if NETFX_CORE || K10 public static bool IsAssignableFrom(this Type type, Type c) { return type.GetTypeInfo().IsAssignableFrom(c.GetTypeInfo()); @@ -63,7 +63,7 @@ namespace Microsoft.AspNet.Mvc public static bool IsGenericType(this Type type) { -#if NETFX_CORE +#if NETFX_CORE || K10 return type.GetTypeInfo().IsGenericType; #else return type.IsGenericType; @@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Mvc public static bool IsInterface(this Type type) { -#if NETFX_CORE +#if NETFX_CORE || K10 return type.GetTypeInfo().IsInterface; #else return type.IsInterface; @@ -81,7 +81,7 @@ namespace Microsoft.AspNet.Mvc public static bool IsValueType(this Type type) { -#if NETFX_CORE +#if NETFX_CORE || K10 return type.GetTypeInfo().IsValueType; #else return type.IsValueType;