VS 2010设置非GUI类文件的组件 [英] VS 2010 setting non-GUI class file as Component

查看:147
本文介绍了VS 2010设置非GUI类文件的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与Visual Studio 2010中发生的很长一段时间我有我做了哪些VS保存为没有理由,我可以辨别型分量一类文件的烦恼。如果我忘了,并尝试打开该文件,它会寻找不存在的设计师。



我已经看过在谷歌和发现了一些类似的问题对VS 2005,但似乎存在的问题,涉及到从GUI组件类(列表框,组合框等)导出。此类不做到这一点。



该文件的 GpsUtilities.cs 的。它如下, 组件亚型出现在的csproj文件中。该文件引用不存在,即没有要求它为 DependentUpon





<预类=郎咸平的XML prettyprint-覆盖> <编译包括=Utilities\GpsUtilities.cs>
<亚型GT;元件与LT; /亚型GT;
< /编译>



即使我删除子类型标签,即使我明确地将其设置为代码而不是组件,但仍然将其保存为子类型 组件



下面是类结构(所有的代码剥离出来)。正如我说的,不继承,甚至是进口的,任何GUI相关的命名空间。



 使用系统; 
使用System.ComponentModel;使用System.IO.Ports
;使用System.Text.RegularExpressions
;使用System.Timers
;
使用的System.Xml.Serialization;

命名空间AppNamespace
{
公共类GpsUtil:INotifyPropertyChanged的
{
公共GpsUtil(){}

公共静态GpsUtil的CreateInstance(){}

公共BOOL IsGpsReady {搞定; }

公共GPSPort GpsSerialPort {搞定;私人集; }

公共定时器GpsTimer {搞定;组; }

私人CircularArray< GpsPositionData> PositionBuffer {搞定;组; }

私人GpsPositionData m_GpsCurLoc;

公共GpsPositionData MyLocation {}

公共字符串GpggaPattern {搞定;组; }

公众正则表达式GpggaRegEx {搞定;组; }

公共GpsPositionData GpsPosDataFromRegExMatch(匹配gpsRegExMatch){}

公共无效SetGpsPosition(双纬,双经度){}

私人无效gpsTimer_Elapsed(对象发件人,ElapsedEventArgs E){}

私人布尔InitializeGpsPort(){}

公共BOOL TestGpsPort(){}

公共双ComputeSquaredDistance(双startLat,双startLon,双endLat,双endLon){}

公共事件PropertyChangedEventHandler的PropertyChanged;
}

公共类GPSPort:的SerialPort
{
公共GPSPort(字符串PORTNAME,INT波特率= 9600):基地(PORTNAME,波特率)
{
}

私人布尔的TestResult {搞定;组; }

公共BOOL测试(INT间隔= 3000,布尔leavePortOpen = FALSE){}
}

公共枚举GpsFixQuality {无效= 0,GpsFix = 1, DgpsFix = 2}

[Serializable接口]
公共类GpsPositionData
{
公共GpsPositionData(){}

公共GpsPositionData(双纬双经度){}

公共重写字符串的ToString(){}

公共BOOL IsCloseTo(GpsPositionData otherPoint,双公差= 0.0001){}

公共GpsPositionData(DateTime的时间,双纬,双经度,GpsFixQuality fixQuality,INT numberOfSatellites,双HDOP,双层高度,双geodialSeparation,诠释ageOfDgps,串dgpsRefStationId){}

[XmlIgnore]
公共DateTime的时间{搞定;私人集; }

[的XmlElement(纵横中的typeof(双))]
公共双纬度{搞定;组; }

[的XmlElement(经度的typeof(双))]
公共双经度{搞定;组; }

[XmlIgnore]
公共GpsFixQuality FixQuality {搞定;私人集; }

[XmlIgnore]
公众诠释NumberOfSatellites {搞定;私人集; }

[XmlIgnore]
公共双HDOP {搞定;私人集; }

[XmlIgnore]
公共双海拔{搞定;私人集; }

[XmlIgnore]
公共双GeodialSeparation {搞定;私人集; }

[XmlIgnore]
公众诠释AgeOfDgps {搞定;私人集; }

[XmlIgnore]
公共字符串DgpsRefStationId {搞定;私人集; }
}
}提前



感谢。


解决方案

如果你想保留的所有类在一个文件中,你可以使用 [System.ComponentModel.DesignerCategory(代码)] GPSPort 类重写默认行为属性。 详细信息这里,请注意您的必须的使用完全合格的属性,即使你有一个使用System.ComponentModel 陈述或VS会忽略它。


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). This 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.

这篇关于VS 2010设置非GUI类文件的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆