VS 2010将非GUI类文件设置为Component

dyt*_*him 29 c# wpf visual-studio-2010

我对Visual Studio 2010已经发生了很长一段时间的烦恼.我有一个类文件,我将VS保存为类型"组件",我无法辨别.如果我忘记并尝试打开文件,它会查找不存在的设计器.

我查看了Google并发现了VS 2005的一些类似问题,但问题似乎与从GUI组件类(listbox,combobox等)派生有关.这个课不这样做.

该文件是GpsUtilities.cs.它如下,出现在的csproj文件SubTypeComponent.没有其他对该文件的引用,即没有任何声称它DependentUpon.

<Compile Include="Utilities\GpsUtilities.cs">
  <SubType>Component</SubType>
</Compile>
Run Code Online (Sandbox Code Playgroud)

即使我删除SubType标记,即使我明确地将其设置为Code替代Component,它仍然将其保存为SubTypeComponent.

这是类结构(所有代码都被删除).正如我所说,它不会继承,甚至不导入与GUI相关的任何名称空间.

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; }
    }
}
Run Code Online (Sandbox Code Playgroud)

提前致谢.

jus*_*mer 32

如果要将所有类保留在一个文件中,可以使用该类[System.ComponentModel.DesignerCategory("Code")]上的属性GPSPort来覆盖默认行为. 详细信息请注意,即使您有语句,您也必须使用完全限定属性,using System.ComponentModel否则VS将忽略它.


Ken*_*art 15

猜测一下,我会说这是由于你的GPSPort课程延伸SerialPort而来的Component.尝试删除它(或将其移动到单独的文件中),看看它是否解决了问题.

  • 我遇到了类似的问题,其中 `&lt;SubType&gt;Component&lt;/SubType&gt;` 不断从 .csproj 文件中添加和删除 - 似乎在同一文件中具有与派生自 `System.ComponentModel.Component 的类型相同的其他类型` 是原因。我将这些类型分成单独的文件(按照自然意图,并且按照您的建议),现在看起来更快乐。 (2认同)