Skip to content

Commit 096c0cf

Browse files
committed
Change PCL profile to 259 and fix compile errors
1 parent 830e11d commit 096c0cf

9 files changed

Lines changed: 80 additions & 79 deletions

File tree

Source/Examples/ExampleLibrary/Axes/DateTimeAxisExamples.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,8 @@ public static PlotModel DaylightSavingsBreak()
6363
var m = new PlotModel();
6464

6565
var xa = new DateTimeAxis { Position = AxisPosition.Bottom };
66-
#if PCL || SILVERLIGHT
6766
// TimeZone not available in PCL...
68-
#else
69-
xa.TimeZone = TimeZoneInfo.FindSystemTimeZoneById(
70-
"W. Europe Standard Time");
71-
#endif
67+
7268
m.Axes.Add(xa);
7369
m.Axes.Add(new LinearAxis { Position = AxisPosition.Left });
7470
var ls = new LineSeries { MarkerType = MarkerType.Circle };

Source/Examples/ExampleLibrary/ExampleLibrary.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>ExampleLibrary</RootNamespace>
1212
<AssemblyName>ExampleLibrary</AssemblyName>
13-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14-
<TargetFrameworkProfile>Profile328</TargetFrameworkProfile>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>Profile259</TargetFrameworkProfile>
1515
<FileAlignment>512</FileAlignment>
1616
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1717
<ProductVersion>8.0.30703</ProductVersion>
@@ -22,15 +22,15 @@
2222
<DebugType>full</DebugType>
2323
<Optimize>false</Optimize>
2424
<OutputPath>bin\PCL\Debug\</OutputPath>
25-
<DefineConstants>TRACE;DEBUG;PCL</DefineConstants>
25+
<DefineConstants>TRACE;DEBUG;UNIVERSAL</DefineConstants>
2626
<ErrorReport>prompt</ErrorReport>
2727
<WarningLevel>4</WarningLevel>
2828
</PropertyGroup>
2929
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3030
<DebugType>pdbonly</DebugType>
3131
<Optimize>true</Optimize>
3232
<OutputPath>bin\PCL\Release\</OutputPath>
33-
<DefineConstants>TRACE;PCL</DefineConstants>
33+
<DefineConstants>TRACE;UNIVERSAL</DefineConstants>
3434
<ErrorReport>prompt</ErrorReport>
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>

Source/Examples/ExampleLibrary/Examples.cs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,17 @@ namespace ExampleLibrary
1616
/// </summary>
1717
public static class Examples
1818
{
19-
/// <summary>
20-
/// Gets the first or default attribute of the specified type.
21-
/// </summary>
22-
/// <typeparam name="T">The attribute type.</typeparam>
23-
/// <param name="type">The type to reflect.</param>
24-
/// <returns>The attribute.</returns>
25-
public static T FirstOrDefault<T>(this Type type) where T : Attribute
19+
#if !UNIVERSAL
20+
public static IEnumerable<T> GetCustomAttributes<T>(this Type type) where T : Attribute
2621
{
27-
var attributes = type.GetCustomAttributes(typeof(T), true).ToArray();
28-
return attributes.Length == 0 ? null : (T)attributes[0];
22+
return type.GetCustomAttributes(typeof(T), true).Cast<T>();
2923
}
3024

31-
/// <summary>
32-
/// Gets the first or default attribute of the specified type.
33-
/// </summary>
34-
/// <typeparam name="T">The attribute type.</typeparam>
35-
/// <param name="info">The information.</param>
36-
/// <returns>
37-
/// The attribute.
38-
/// </returns>
39-
public static T FirstOrDefault<T>(this MethodInfo info) where T : Attribute
25+
public static IEnumerable<T> GetCustomAttributes<T>(this MethodInfo info) where T : Attribute
4026
{
41-
var attributes = info.GetCustomAttributes(typeof(T), true).ToArray();
42-
return attributes.Length == 0 ? null : (T)attributes[0];
27+
return info.GetCustomAttributes(typeof(T), true).Cast<T>();
4328
}
29+
#endif
4430

4531
/// <summary>
4632
/// Gets the list of examples.
@@ -57,13 +43,13 @@ public static List<ExampleInfo> GetList()
5743

5844
foreach (var type in assemblyTypes)
5945
{
60-
var examplesAttribute = type.FirstOrDefault<ExamplesAttribute>();
46+
var examplesAttribute = type.GetCustomAttributes<ExamplesAttribute>().FirstOrDefault();
6147
if (examplesAttribute == null)
6248
{
6349
continue;
6450
}
6551

66-
var examplesTags = type.FirstOrDefault<TagsAttribute>() ?? new TagsAttribute();
52+
var examplesTags = type.GetCustomAttributes<TagsAttribute>().FirstOrDefault() ?? new TagsAttribute();
6753

6854
var types = new List<Type>();
6955
var baseType = type;
@@ -90,10 +76,10 @@ public static List<ExampleInfo> GetList()
9076
{
9177
try
9278
{
93-
var exampleAttribute = method.FirstOrDefault<ExampleAttribute>();
79+
var exampleAttribute = method.GetCustomAttributes<ExampleAttribute>().FirstOrDefault();
9480
if (exampleAttribute != null)
9581
{
96-
var exampleTags = method.FirstOrDefault<TagsAttribute>() ?? new TagsAttribute();
82+
var exampleTags = method.GetCustomAttributes<TagsAttribute>().FirstOrDefault() ?? new TagsAttribute();
9783
var tags = new List<string>(examplesTags.Tags);
9884
tags.AddRange(exampleTags.Tags);
9985
list.Add(

Source/Examples/ExampleLibrary/Issues/Issues.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace ExampleLibrary
1313
using System.Collections.Generic;
1414
using System.Globalization;
1515
using System.Threading;
16+
using System.Threading.Tasks;
1617

1718
using OxyPlot;
1819
using OxyPlot.Annotations;
@@ -774,23 +775,29 @@ public static PlotModel LabelPlacementCategoryAxisWhenAxisAngleIs45()
774775
var textAnnotation = new TextAnnotation() { Text = "Hold mouse button here to increase angle", TextPosition = new DataPoint(0, 6), TextHorizontalAlignment = HorizontalAlignment.Left, TextVerticalAlignment = VerticalAlignment.Top };
775776
plotModel1.Annotations.Add(textAnnotation);
776777

777-
Timer t = new Timer(o =>
778-
{
779-
// Angles are the same for all axes.
780-
double angle = 0;
778+
var abort = new ManualResetEvent(false);
781779

782-
foreach (var axis in plotModel1.Axes)
780+
Action action = () =>
781+
{
782+
do
783783
{
784-
angle = (axis.Angle + 181) % 360 - 180;
785-
axis.Angle = angle;
786-
}
784+
// Angles are the same for all axes.
785+
double angle = 0;
787786

788-
plotModel1.Subtitle = string.Format("Current angle is {0}", angle);
789-
plotModel1.InvalidatePlot(false);
790-
}, null, -1, 50);
787+
foreach (var axis in plotModel1.Axes)
788+
{
789+
angle = (axis.Angle + 181) % 360 - 180;
790+
axis.Angle = angle;
791+
}
792+
793+
plotModel1.Subtitle = string.Format("Current angle is {0}", angle);
794+
plotModel1.InvalidatePlot(false);
795+
}
796+
while (!abort.WaitOne(50));
797+
};
791798

792-
textAnnotation.MouseDown += (o, e) => { t.Change(0, 50); };
793-
plotModel1.MouseUp += (o, e) => { t.Change(-1, 50); };
799+
textAnnotation.MouseDown += (o, e) => { abort.Reset(); Task.Factory.StartNew(action); };
800+
plotModel1.MouseUp += (o, e) => { abort.Set(); };
794801

795802
var columnSeries = new ColumnSeries();
796803
columnSeries.Items.Add(new ColumnItem(5));

Source/Examples/ExampleLibrary/Misc/MiscExamples.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace ExampleLibrary
1515
using System.IO;
1616
using System.Reflection;
1717
using System.Threading;
18+
using System.Threading.Tasks;
1819
using System.Xml.Serialization;
1920

2021
using OxyPlot;
@@ -2238,7 +2239,6 @@ public override void Render(IRenderContext rc)
22382239
int maxIterations = (int)this.ColorAxis.ActualMaximum + 1;
22392240
var pixels = new OxyColor[w, h];
22402241

2241-
#if !UNIVERSAL
22422242
ParallelFor(
22432243
0,
22442244
h,
@@ -2254,23 +2254,6 @@ public override void Render(IRenderContext rc)
22542254
pixels[j, i] = this.ColorAxis.GetColor((double)iterations);
22552255
}
22562256
});
2257-
#else
2258-
Parallel.For(
2259-
0,
2260-
h,
2261-
i =>
2262-
{
2263-
double y = this.YAxis.ActualMaximum - ((double)i / (h - 1) * (this.YAxis.ActualMaximum - this.YAxis.ActualMinimum));
2264-
for (int j = 0; j < w; j++)
2265-
{
2266-
double x = this.XAxis.ActualMinimum
2267-
+ ((double)j / (w - 1)
2268-
* (this.XAxis.ActualMaximum - this.XAxis.ActualMinimum));
2269-
var iterations = Solve(x, y, maxIterations);
2270-
pixels[j, i] = this.ColorAxis.GetColor((double)iterations);
2271-
}
2272-
});
2273-
#endif
22742257

22752258
var bitmap = OxyImage.Create(pixels, ImageFormat.Png);
22762259
rc.DrawImage(bitmap, p0.X, p1.Y, p1.X - p0.X, p0.Y - p1.Y, 1, true);
@@ -2322,7 +2305,6 @@ private static void SerialFor(int i0, int i1, Action<int> action)
23222305
}
23232306
}
23242307

2325-
#if !UNIVERSAL
23262308
/// <summary>
23272309
/// Executes a parallel for loop using ThreadPool.
23282310
/// </summary>
@@ -2359,7 +2341,11 @@ private static void ParallelFor(int i0, int i1, Action<int> action)
23592341
int k = i;
23602342
int j0 = i0 + (i * n);
23612343
var j1 = Math.Min(j0 + n, i1);
2362-
ThreadPool.QueueUserWorkItem(state => invokePartition(k, j0, j1));
2344+
Task.Factory.StartNew(
2345+
() => invokePartition(k, j0, j1),
2346+
CancellationToken.None,
2347+
TaskCreationOptions.LongRunning,
2348+
TaskScheduler.Default);
23632349
}
23642350

23652351
// Wait for the threads to finish
@@ -2368,7 +2354,6 @@ private static void ParallelFor(int i0, int i1, Action<int> action)
23682354
wh.WaitOne();
23692355
}
23702356
}
2371-
#endif
23722357
}
23732358

23742359

Source/OxyPlot/OxyPlot.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>OxyPlot</RootNamespace>
1212
<AssemblyName>OxyPlot</AssemblyName>
13-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14-
<TargetFrameworkProfile>Profile328</TargetFrameworkProfile>
13+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>Profile259</TargetFrameworkProfile>
1515
<FileAlignment>512</FileAlignment>
1616
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
1717
<ProductVersion>8.0.30703</ProductVersion>
@@ -24,15 +24,15 @@
2424
<DebugType>full</DebugType>
2525
<Optimize>false</Optimize>
2626
<OutputPath>bin\PCL\Debug\</OutputPath>
27-
<DefineConstants>TRACE;DEBUG;PCL</DefineConstants>
27+
<DefineConstants>TRACE;DEBUG;UNIVERSAL</DefineConstants>
2828
<ErrorReport>prompt</ErrorReport>
2929
<WarningLevel>4</WarningLevel>
3030
</PropertyGroup>
3131
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3232
<DebugType>pdbonly</DebugType>
3333
<Optimize>true</Optimize>
3434
<OutputPath>..\..\Output\PCL\</OutputPath>
35-
<DefineConstants>TRACE;PCL</DefineConstants>
35+
<DefineConstants>TRACE;UNIVERSAL</DefineConstants>
3636
<ErrorReport>prompt</ErrorReport>
3737
<WarningLevel>4</WarningLevel>
3838
<DocumentationFile>..\..\Output\PCL\OxyPlot.xml</DocumentationFile>

Source/OxyPlot/Rendering/OxyColorExtensions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace OxyPlot
1212
using System;
1313
using System.Globalization;
1414
using System.Linq;
15-
using System.Reflection;
1615

1716
/// <summary>
1817
/// Provides extension methods for <see cref="OxyColor" />.
@@ -176,12 +175,7 @@ public static string ToCode(this OxyColor color)
176175
public static string GetColorName(this OxyColor color)
177176
{
178177
var t = typeof(OxyColors);
179-
#if UNIVERSAL
180178
var colors = t.GetFields();
181-
#else
182-
var colors = t.GetFields(BindingFlags.Public | BindingFlags.Static);
183-
#endif
184-
185179
var colorField = colors.FirstOrDefault(field => color.Equals(field.GetValue(null)));
186180
return colorField != null ? colorField.Name : null;
187181
}

Source/OxyPlot/Utilities/ReflectionExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,48 @@ namespace OxyPlot
2323
public static class ReflectionExtensions
2424
{
2525
#if UNIVERSAL
26+
/// <summary>
27+
/// Gets a specific property of the current Type.
28+
/// </summary>
29+
/// <param name="type">The type.</param>
30+
/// <param name="name">The string containing the name of the public property to get.</param>
31+
/// <returns>An object representing the public property with the specified name, if found; otherwise, null.</returns>
2632
public static PropertyInfo GetProperty(this Type type, string name)
2733
{
2834
return type.GetRuntimeProperty(name);
2935
}
36+
37+
/// <summary>
38+
/// Returns the public set accessor for this property.
39+
/// </summary>
40+
/// <param name="pi">The property.</param>
41+
/// <returns>The MethodInfo object representing the Set method for this property, or null if the set accessor is not public.</returns>
3042
public static MethodInfo GetSetMethod(this PropertyInfo pi)
3143
{
3244
return pi.SetMethod;
3345
}
46+
47+
/// <summary>
48+
/// Returns all the public properties of the current Type.
49+
/// </summary>
50+
/// <param name="type">The type.</param>
51+
/// <returns>An array of PropertyInfo objects representing all public properties of the current Type.</returns>
3452
public static IEnumerable<PropertyInfo> GetProperties(this Type type)
3553
{
3654
return type.GetRuntimeProperties();
3755
}
56+
57+
/// <summary>
58+
/// Returns all the public fields of the current Type.
59+
/// </summary>
60+
/// <param name="type">The type.</param>
61+
/// <returns>An array of FieldInfo objects representing all the public fields defined for the current Type.</returns>
3862
public static IEnumerable<FieldInfo> GetFields(this Type type)
3963
{
4064
return type.GetRuntimeFields();
4165
}
4266
#endif
67+
4368
/// <summary>
4469
/// Fills a target by the specified property of a source target/enumerable.
4570
/// </summary>

Source/OxyPlot/Utilities/ReflectionPath.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public class ReflectionPath
2727
/// </summary>
2828
private readonly PropertyInfo[] infos;
2929

30+
/// <summary>
31+
/// The reflected types.
32+
/// </summary>
33+
private readonly Type[] reflectedTypes;
34+
3035
/// <summary>
3136
/// Initializes a new instance of the <see cref="ReflectionPath"/> class.
3237
/// </summary>
@@ -35,6 +40,7 @@ public ReflectionPath(string path)
3540
{
3641
this.items = path.Split('.');
3742
this.infos = new PropertyInfo[this.items.Length];
43+
this.reflectedTypes = new Type[this.items.Length];
3844
}
3945

4046
/// <summary>
@@ -53,11 +59,13 @@ public object GetValue(object instance)
5359
return null;
5460
}
5561

56-
var pi = this.infos[i];
5762
var currentType = current.GetType();
58-
if (pi == null || pi.ReflectedType != currentType)
63+
64+
var pi = this.infos[i];
65+
if (pi == null || this.reflectedTypes[i] != currentType)
5966
{
6067
pi = this.infos[i] = currentType.GetProperty(this.items[i]);
68+
this.reflectedTypes[i] = currentType;
6169
}
6270

6371
if (pi == null)

0 commit comments

Comments
 (0)