Skip to content

Commit

Permalink
Added missing type converters.
Browse files Browse the repository at this point in the history
  • Loading branch information
jperson_cp authored and jperson_cp committed Jul 29, 2009
1 parent 96177bd commit c1d170f
Show file tree
Hide file tree
Showing 4 changed files with 365 additions and 9 deletions.
23 changes: 14 additions & 9 deletions GPS.NET (VS2008 Designers).csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>GeoFrameworks.snk</AssemblyOriginatorKeyFile>
<SccProjectName>SurroundSCMScci</SccProjectName>
<SccLocalPath>.</SccLocalPath>
<AssemblyOriginatorKeyFile>CodePlex.snk</AssemblyOriginatorKeyFile>
<SccProjectName>
</SccProjectName>
<SccLocalPath>
</SccLocalPath>
<SccAuxPath>
</SccAuxPath>
<SccProvider>MSSCCI:Surround SCM</SccProvider>
<SccProvider>
</SccProvider>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -43,10 +46,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="GeoFramework.Design, Version=1.0.50727.0, Culture=neutral, PublicKeyToken=3ed3cdf4fdda3400, processorArchitecture=MSIL">
<HintPath>..\..\GeoFramework\1.4.7\bin\Debug\VS2008 Designers\GeoFramework.Design.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
Expand All @@ -57,7 +56,13 @@
<Compile Include="Type Converters\SignalToNoiseRatioConverter.cs" />
</ItemGroup>
<ItemGroup>
<None Include="GeoFrameworks.snk" />
<None Include="CodePlex.snk" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GeoFramework\2.0.0 Open Source\GeoFramework %28VS2008 Designers%29.csproj">
<Project>{7F9F4CB4-F86D-45F0-8FA0-00C5E19B72A0}</Project>
<Name>GeoFramework %28VS2008 Designers%29</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
162 changes: 162 additions & 0 deletions Type Converters/DilutionOfPrecisionConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#if !PocketPC || DesignTime
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System;
using System.Globalization;
using System.Text;
using System.Reflection;
using System.Windows.Forms;

#if !Framework20
using GeoFramework.Gps;
#endif

namespace GeoFramework.Design
{
/// <summary>
/// Provides functionality to convert string values to and from DilutionOfPrecision objects at design time.
/// </summary>
#if Framework20
public sealed class DilutionOfPrecisionConverter : GpsNumericObjectConverter
{
protected override string HandledTypeName
{
get
{
return "GeoFramework.Gps.DilutionOfPrecision";
}
}


public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
// What is the destination type?
if (destinationType == typeof(string) && value == null)
{
return "0°";
}
else if (destinationType == typeof(InstanceDescriptor))
{
// Instance descriptor. Used during Windows Forms serialization.

// Get the type of the object (probably an Angle)
Type DilutionOfPrecisionType = value.GetType();
// Is the value null?
if (value == null)
{
// Yes. Return the "Empty" static value
return new InstanceDescriptor(DilutionOfPrecisionType.GetField("Empty"), null);
}
else
{
// Build the parameters for the type converter
object[] ConstructorParameters = new object[] { DilutionOfPrecisionType.GetProperty("Value").GetValue(value, null) };
Type[] ConstructorTypes = new Type[] { typeof(double) };

// Now activate the constructor
ConstructorInfo Constructor = DilutionOfPrecisionType.GetConstructor(ConstructorTypes);
return new InstanceDescriptor(Constructor, ConstructorParameters);
}
}

// Defer to the base class
return base.ConvertTo(context, culture, value, destinationType);
}

public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}

public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(new string[] {
"Ideal",
"Excellent",
"Good",
"Moderate",
"Fair",
"Poor"
});
}

public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
}
#else
public class DilutionOfPrecisionConverter : ExpandableObjectConverter
{
#region ConvertFrom: Converts an object to an DilutionOfPrecision

// Indicates if the type can be converted
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType.Equals(typeof(string))
|| sourceType.Equals(typeof(double))
|| sourceType.Equals(typeof(InstanceDescriptor))
|| sourceType.Equals(typeof(DilutionOfPrecision)))
return true;
// Defer to the base class
return base.CanConvertFrom(context, sourceType);
}

// Converts an object of one type to an DilutionOfPrecision
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
Type ValueType = value.GetType();
if (ValueType.Equals(typeof(string)))
return new DilutionOfPrecision((string)value, culture);
else if (ValueType.Equals(typeof(double)))
return new DilutionOfPrecision((double)value);
else if (ValueType.Equals(typeof(DilutionOfPrecision)))
return value;
// Defer to the base class
return base.ConvertFrom(context, culture, value);
}

#endregion

#region ConvertTo: Converts an DilutionOfPrecision to another type

public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType.Equals(typeof(string))
|| destinationType.Equals(typeof(double))
|| destinationType.Equals(typeof(InstanceDescriptor))
|| destinationType.Equals(typeof(DilutionOfPrecision)))
return true;
// Defer to the base class
return base.CanConvertTo(context, destinationType);
}


public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if(destinationType.Equals(value.GetType()))
return value;
else if (destinationType.Equals(typeof(string)))
return value.ToString();
else if (destinationType.Equals(typeof(double)))
return ((SignalToNoiseRatio)value).Value;
else if (destinationType.Equals(typeof(SignalToNoiseRatio)))
return value;
else if(destinationType == typeof(InstanceDescriptor))
{
ConstructorInfo Constructor = typeof(DilutionOfPrecision).GetConstructor(
new Type[] {typeof(double)});
DilutionOfPrecision dilutionOfPrecision = (DilutionOfPrecision)value;
return new InstanceDescriptor(Constructor, new object[] { dilutionOfPrecision.Value });
}
// Defer to the base class
return base.ConvertTo(context, culture, value, destinationType);
}

#endregion
}
#endif
}
#endif
30 changes: 30 additions & 0 deletions Type Converters/GpsNumericObjectConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace GeoFramework.Design
{
public abstract class GpsNumericObjectConverter : GeoFrameworkNumericObjectConverter
{

protected override Version HandledAssemblyVersion
{
get
{
return new Version("2.3.1.0");
}
}

protected override string HandledAssemblyName
{
get
{
#if PocketPC
return "GeoFramework.Gps.PocketPC, Culture=neutral, Version=" + HandledAssemblyVersion.ToString(4) + ", PublicKeyToken=3ed3cdf4fdda3400";
#else
return "GeoFramework.Gps, Culture=neutral, Version=" + HandledAssemblyVersion.ToString(4) + ", PublicKeyToken=3ed3cdf4fdda3400";
#endif
}
}
}
}
Loading

0 comments on commit c1d170f

Please sign in to comment.