Skip to content

Commit

Permalink
#371 Extract Caliburn.Micro.Platform.Core
Browse files Browse the repository at this point in the history
  • Loading branch information
nigel-sampson committed Jun 1, 2017
1 parent b77c6bb commit caf6634
Show file tree
Hide file tree
Showing 22 changed files with 121 additions and 208 deletions.
Expand Up @@ -5,11 +5,6 @@
using System.ComponentModel;
using System.Linq;
using System.Reflection;
#if !WINDOWS_UWP
using System.Windows;
#else
using Windows.UI.Xaml;
#endif

/// <summary>
/// A source of assemblies that are inspectable by the framework.
Expand All @@ -29,7 +24,7 @@ public static class AssemblySource {
}
var type = names
.Join(Instance.SelectMany(a => a.GetExportedTypes()), n => n, t => t.FullName, (n, t) => t)
.Join(Instance.SelectMany(a => a.ExportedTypes), n => n, t => t.FullName, (n, t) => t)
.FirstOrDefault();
return type;
};
Expand All @@ -46,12 +41,9 @@ public static class AssemblySourceCache {
/// Extracts the types from the spezified assembly for storing in the cache.
/// </summary>
public static Func<Assembly, IEnumerable<Type>> ExtractTypes = assembly =>
assembly.GetExportedTypes()
assembly.ExportedTypes
.Where(t =>
#if !CORE
typeof(UIElement).IsAssignableFrom(t) ||
#endif
typeof(INotifyPropertyChanged).IsAssignableFrom(t));
typeof(INotifyPropertyChanged).GetTypeInfo().IsAssignableFrom(t.GetTypeInfo()));

/// <summary>
/// Installs the caching subsystem.
Expand Down
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
<AssemblyName>Caliburn.Micro.Platform.Core</AssemblyName>
<RootNamespace>Caliburn.Micro</RootNamespace>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\..\bin\netstandard\Debug</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\..\bin\netstandard\Release</OutputPath>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Caliburn.Micro.Core\Caliburn.Micro.Core.csproj" />
</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions src/Caliburn.Micro.Platform.Core/ExtensionMethods.cs
@@ -0,0 +1,33 @@
namespace Caliburn.Micro {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

/// <summary>
/// Generic extension methods used by the framework.
/// </summary>
public static class ExtensionMethods {
/// <summary>
/// Get's the name of the assembly.
/// </summary>
/// <param name="assembly">The assembly.</param>
/// <returns>The assembly's name.</returns>
public static string GetAssemblyName(this Assembly assembly) {
return assembly.FullName.Remove(assembly.FullName.IndexOf(','));
}

/// <summary>
/// Gets the value for a key. If the key does not exist, return default(TValue);
/// </summary>
/// <typeparam name="TKey">The type of the keys in the dictionary.</typeparam>
/// <typeparam name="TValue">The type of the values in the dictionary.</typeparam>
/// <param name="dictionary">The dictionary to call this method on.</param>
/// <param name="key">The key to look up.</param>
/// <returns>The key value. default(TValue) if this key is not in the dictionary.</returns>
public static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key) {
TValue result;
return dictionary.TryGetValue(key, out result) ? result : default(TValue);
}
}
}
Expand Up @@ -9,11 +9,8 @@
/// </summary>
public class NameTransformer : BindableCollection<NameTransformer.Rule> {

#if NET
private const RegexOptions options = RegexOptions.Compiled;
#else
private const RegexOptions options = RegexOptions.None;
#endif


bool useEagerRuleSelection = true;

Expand Down
File renamed without changes.
Expand Up @@ -24,12 +24,8 @@ public static string[] Split(string message, char separator)
var builder = new StringBuilder();

int squareBrackets = 0;
#if WINDOWS_UWP
foreach (var current in message.ToCharArray())
{
#else

foreach (var current in message) {
#endif
//Square brackets are used as delimiters, so only separators outside them count...
if (current == '[')
{
Expand Down
Expand Up @@ -59,10 +59,11 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Caliburn.Micro.Core\Caliburn.Micro.Core.csproj">
<Project>{026678e0-a3e4-4760-a277-87352392fb6e}</Project>
<Name>Caliburn.Micro.Core</Name>
</ProjectReference>
<ProjectReference Include="Caliburn.Micro.Platform.Core.csproj">
<Project>{0ecbe3d9-aed4-419d-a6e3-c53d5ce2a02a}</Project>
<ProjectReference Include="..\Caliburn.Micro.Platform.Core\Caliburn.Micro.Platform.Core.csproj">
<Project>{04c6555d-50be-40be-9b3f-74fac0f73fa2}</Project>
<Name>Caliburn.Micro.Platform.Core</Name>
</ProjectReference>
</ItemGroup>
Expand Down
74 changes: 0 additions & 74 deletions src/Caliburn.Micro.Platform/Caliburn.Micro.Platform.Core.csproj

This file was deleted.

Expand Up @@ -100,8 +100,8 @@
<Project>{026678e0-a3e4-4760-a277-87352392fb6e}</Project>
<Name>Caliburn.Micro.Core</Name>
</ProjectReference>
<ProjectReference Include="Caliburn.Micro.Platform.Core.csproj">
<Project>{0ecbe3d9-aed4-419d-a6e3-c53d5ce2a02a}</Project>
<ProjectReference Include="..\Caliburn.Micro.Platform.Core\Caliburn.Micro.Platform.Core.csproj">
<Project>{04c6555d-50be-40be-9b3f-74fac0f73fa2}</Project>
<Name>Caliburn.Micro.Platform.Core</Name>
</ProjectReference>
</ItemGroup>
Expand Down
Expand Up @@ -121,8 +121,8 @@
<Project>{026678e0-a3e4-4760-a277-87352392fb6e}</Project>
<Name>Caliburn.Micro.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Caliburn.Micro.Platform\Caliburn.Micro.Platform.Core.csproj">
<Project>{0ecbe3d9-aed4-419d-a6e3-c53d5ce2a02a}</Project>
<ProjectReference Include="..\Caliburn.Micro.Platform.Core\Caliburn.Micro.Platform.Core.csproj">
<Project>{04c6555d-50be-40be-9b3f-74fac0f73fa2}</Project>
<Name>Caliburn.Micro.Platform.Core</Name>
</ProjectReference>
</ItemGroup>
Expand Down
Expand Up @@ -82,8 +82,8 @@
<Project>{026678e0-a3e4-4760-a277-87352392fb6e}</Project>
<Name>Caliburn.Micro.Core</Name>
</ProjectReference>
<ProjectReference Include="Caliburn.Micro.Platform.Core.csproj">
<Project>{0ecbe3d9-aed4-419d-a6e3-c53d5ce2a02a}</Project>
<ProjectReference Include="..\Caliburn.Micro.Platform.Core\Caliburn.Micro.Platform.Core.csproj">
<Project>{04c6555d-50be-40be-9b3f-74fac0f73fa2}</Project>
<Name>Caliburn.Micro.Platform.Core</Name>
</ProjectReference>
</ItemGroup>
Expand Down
Expand Up @@ -52,8 +52,8 @@
<Project>{026678e0-a3e4-4760-a277-87352392fb6e}</Project>
<Name>Caliburn.Micro.Core</Name>
</ProjectReference>
<ProjectReference Include="Caliburn.Micro.Platform.Core.csproj">
<Project>{0ecbe3d9-aed4-419d-a6e3-c53d5ce2a02a}</Project>
<ProjectReference Include="..\Caliburn.Micro.Platform.Core\Caliburn.Micro.Platform.Core.csproj">
<Project>{04c6555d-50be-40be-9b3f-74fac0f73fa2}</Project>
<Name>Caliburn.Micro.Platform.Core</Name>
</ProjectReference>
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Caliburn.Micro.Platform/ChildResolver.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
#if WINDOWS_UWP
using Windows.UI.Xaml;
#else
Expand Down
73 changes: 0 additions & 73 deletions src/Caliburn.Micro.Platform/ExtensionMethods.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Caliburn.Micro.Platform/MessageBinder.cs
Expand Up @@ -102,7 +102,7 @@ public static class MessageBinder {
}

var providedType = providedValue.GetType();
if (destinationType.IsAssignableFrom(providedType)) {
if (destinationType.GetTypeInfo().IsAssignableFrom(providedType.GetTypeInfo())) {
return providedValue;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ public static class MessageBinder {
return Enum.ToObject(destinationType, providedValue);
}

if (typeof (Guid).IsAssignableFrom(destinationType)) {
if (typeof (Guid).GetTypeInfo().IsAssignableFrom(destinationType.GetTypeInfo())) {
var stringValue = providedValue as string;
if (stringValue != null) {
return new Guid(stringValue);
Expand Down
6 changes: 4 additions & 2 deletions src/Caliburn.Micro.Platform/View.cs
Expand Up @@ -234,7 +234,8 @@ public static class View {
.GetValue(dependencyObject, null);
#else
var type = dependencyObject.GetType();
var contentProperty = type.GetAttributes<ContentPropertyAttribute>(true)
var contentProperty = type.GetCustomAttributes(typeof(ContentPropertyAttribute), true)
.OfType<ContentPropertyAttribute>()
.FirstOrDefault() ?? DefaultContentProperty;
return type.GetProperty(contentProperty.Name)
Expand Down Expand Up @@ -390,7 +391,8 @@ public static class View {
static bool SetContentPropertyCore(object targetLocation, object view) {
try {
var type = targetLocation.GetType();
var contentProperty = type.GetAttributes<ContentPropertyAttribute>(true)
var contentProperty = type.GetCustomAttributes(typeof(ContentPropertyAttribute), true)
.OfType<ContentPropertyAttribute>()
.FirstOrDefault() ?? DefaultContentProperty;

type.GetProperty(contentProperty?.Name ?? DefaultContentProperty.Name)
Expand Down
2 changes: 1 addition & 1 deletion src/Caliburn.Micro.Platform/ViewModelBinder.cs
Expand Up @@ -179,7 +179,7 @@ public static class ViewModelBinder {
};

static bool IsAsyncMethod(MethodInfo method) {
return typeof(Task).IsAssignableFrom(method.ReturnType) &&
return typeof(Task).GetTypeInfo().IsAssignableFrom(method.ReturnType.GetTypeInfo()) &&
method.Name.EndsWith(AsyncSuffix, StringComparison.OrdinalIgnoreCase);
}

Expand Down

0 comments on commit caf6634

Please sign in to comment.