I have an annoyance that has been occurring for quite some time with Visual Studio 2010. I have a class file that I have made which VS saves as type "Component" for no reason I can discern. If I forget and try to open the file, it looks for a designer which doesn't exist.
I have looked on Google and found some similar issues for VS 2005, but the problems seemed to be related to deriving from GUI component classes (listbox, combobox, etc). Th开发者_如何学运维is class does not do that.
The file is GpsUtilities.cs. It appears in the csproj file as follows, with SubType
of Component
. No other references to the file exist, i.e. nothing claims it as DependentUpon
.
<Compile Include="Utilities\GpsUtilities.cs">
<SubType>Component</SubType>
</Compile>
Even if I remove the SubType
tag, and even if I explicitly set it to Code
instead of Component
, it still saves it as SubType
of Component
.
Here is the class structure (all the code stripped out). As I said, it does not inherit, or even import the namespace of, anything GUI-related.
using System;
using System.ComponentModel;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Timers;
using System.Xml.Serialization;
namespace AppNamespace
{
public class GpsUtil : INotifyPropertyChanged
{
public GpsUtil() { }
public static GpsUtil CreateInstance() { }
public bool IsGpsReady { get; }
public GPSPort GpsSerialPort { get; private set; }
public Timer GpsTimer { get; set; }
private CircularArray<GpsPositionData> PositionBuffer { get; set; }
private GpsPositionData m_GpsCurLoc;
public GpsPositionData MyLocation { }
public string GpggaPattern { get; set; }
public Regex GpggaRegEx { get; set; }
public GpsPositionData GpsPosDataFromRegExMatch(Match gpsRegExMatch) { }
public void SetGpsPosition(double latitude, double longitude) { }
private void gpsTimer_Elapsed(object sender, ElapsedEventArgs e) { }
private bool InitializeGpsPort() { }
public bool TestGpsPort() { }
public double ComputeSquaredDistance(double startLat, double startLon, double endLat, double endLon) { }
public event PropertyChangedEventHandler PropertyChanged;
}
public class GPSPort : SerialPort
{
public GPSPort(string portName, int baudRate = 9600) : base(portName, baudRate)
{
}
private bool TestResult { get; set; }
public bool Test(int interval = 3000, bool leavePortOpen = false) {}
}
public enum GpsFixQuality { Invalid = 0, GpsFix = 1, DgpsFix = 2 }
[Serializable]
public class GpsPositionData
{
public GpsPositionData() { }
public GpsPositionData(double latitude, double longitude) {}
public override string ToString() {}
public bool IsCloseTo(GpsPositionData otherPoint, double tolerance = 0.0001) {}
public GpsPositionData(DateTime time, double latitude, double longitude, GpsFixQuality fixQuality, int numberOfSatellites, double hdop, double altitude, double geodialSeparation, int ageOfDgps, string dgpsRefStationId){}
[XmlIgnore]
public DateTime Time { get; private set; }
[XmlElement("Latitude", typeof(double))]
public double Latitude { get; set; }
[XmlElement("Longitude", typeof(double))]
public double Longitude { get; set; }
[XmlIgnore]
public GpsFixQuality FixQuality { get; private set; }
[XmlIgnore]
public int NumberOfSatellites { get; private set; }
[XmlIgnore]
public double Hdop { get; private set; }
[XmlIgnore]
public double Altitude { get; private set; }
[XmlIgnore]
public double GeodialSeparation { get; private set; }
[XmlIgnore]
public int AgeOfDgps { get; private set; }
[XmlIgnore]
public string DgpsRefStationId { get; private set; }
}
}
Thanks in advance.
If you want to keep all the classes in one file, you can use the [System.ComponentModel.DesignerCategory("Code")]
attribute on the GPSPort
class to override the default behavior. Details here, note that you must use the fully qualified attribute even if you have a using System.ComponentModel
statement or VS will ignore it.
At a guess, I'd say it's due to your GPSPort
class, which extends SerialPort
, which extends Component
. Try removing that (or moving it into a separate file) and see if it fixes the problem.
精彩评论