这个是什么语法?

小公鸡卡哇伊呀~ 2018-08-22 10:00:04


using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using QC.QTMDotNetKernelInterface;
using ENV = QC.QTMDotNetKernelInterface.Environment;

namespace QSEQ_DOTNETTest
{
[QTMTestClass] //////// <- 这一行,没见过
public class QSEQ_DOTNETTests : ENV.QSPRTest, IDisposable
{
public QSEQ_DOTNETTests(ENV.QSPREnvironment qsprEnv)
: base(qsprEnv)
{
qsprEnv.DebugMessage.Write("Constructor", "SchedulerID=" + qsprEnv.SchedulerID);
}
// QSEQ core dll filename
const string qseqDLLName = "QSEQ_CORE_DLL.dll";

// QSEQ max string buffer size
const Int32 qseqMaxStringBufferSize = 1024;

[DllImport(qseqDLLName, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
static extern byte fnQSEQ_SetUUTID(
UInt32 _iDeviceGroupID,
string _sUUTID,
string _sUUTType);

}
}
...全文
194 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
我看了几篇关于Attribute的文章,最好理解好用的应该就是 ObsoleteAttribute
对于自定义属性,有些看着就像是高级一点的comment,我上面贴的第一段, 我就不知道代码为什么要这样写,这个自定义Attribute写在这里做什么?

正怒月神 2018-08-22
  • 打赏
  • 举报
回复
的确叫特性更恰当,
因为属性已经有对应的含义了。
我只是习惯性直译Attribute的叫法。
我把上面改一下吧
  • 打赏
  • 举报
回复
引用 2 楼 hanjun0612 的回复:
这是一个属性,可能是自定义属性
你可以f12导航到合格属性的实现。一般都是继承自 attribute,然后实现一下内部逻辑。
说白了是一个过滤器。


真的是, QTMTestClass 的定义:

#region 程序集 QTMDotNetKernelInterface.dll, v4.0.30319
// E:\tmp\QTMDotNetKernelInterface.dll
#endregion

using System;

namespace QC.QTMDotNetKernelInterface
{
[AttributeUsage(AttributeTargets.Class)]
public class QTMTestClass : Attribute
{
public QTMTestClass();
}
}
全栈极简 2018-08-22
  • 打赏
  • 举报
回复
[QTMParameter(ArgumentName = "Technology", DefaultValue = "3", Description = "Technology being used in the sequence")]

这个也是特性,不是属性。其中ArgumentName、DefaultValue 、Description 这些都是QTMParameter特性里的属性。
  • 打赏
  • 举报
回复
这个也是属性或特性吗?写法更复杂:

[QTMParameter(ArgumentName = "Technology", DefaultValue = "3", Description = "Technology being used in the sequence")]
[QTMParameter(ArgumentName = "Rx0Device", DefaultValue = "0", Description = "Device used for Primary Rx measurements")]
[QTMParameter(ArgumentName = "Rx0SignalPath", DefaultValue = "0", Description = "Signal Path used for Primary Rx measurements")]
[QTMParameter(ArgumentName = "Rx0AntennaPath", DefaultValue = "0", Description = "Antenna Path used for Primary Rx measurements")]
[QTMParameter(ArgumentName = "Rx1Device", DefaultValue = "0", Description = "Device used for Diversity Rx measurements")]
[QTMParameter(ArgumentName = "Rx1SignalPath", DefaultValue = "0", Description = "Signal Path used for Diversity Rx measurements")]
[QTMParameter(ArgumentName = "Rx1AntennaPath", DefaultValue = "0", Description = "Antenna Path used for Diversity Rx measurements")]
[QTMParameter(ArgumentName = "TxDevice", DefaultValue = "0", Description = "Device used for Tx routing")]
[QTMParameter(ArgumentName = "TxSignalPath", DefaultValue = "0", Description = "Signal Path used for Tx routing")]
[QTMParameter(ArgumentName = "TxAntennaPath", DefaultValue = "0", Description = "Antenna Path used for Tx routing")]
public bool SetRadioAllocation(
Technology Technology,
UInt16 Rx0Device,
UInt16 Rx0SignalPath,
UInt16 Rx0AntennaPath,
UInt16 Rx1Device,
UInt16 Rx1SignalPath,
UInt16 Rx1AntennaPath,
UInt16 TxDevice,
UInt16 TxSignalPath,
UInt16 TxAntennaPath
)
{
byte[] errMsg = new byte[qseqMaxStringBufferSize];
return (fnQSEQ_SetRadioAllocation( Technology,
Rx0Device,
Rx0SignalPath,
Rx0AntennaPath,
Rx1Device,
Rx1SignalPath,
Rx1AntennaPath,
TxDevice,
TxSignalPath,
TxAntennaPath,
errMsg,
qseqMaxStringBufferSize) == 0);
}
游北亮 2018-08-22
  • 打赏
  • 举报
回复
嗯,C#里一般叫特性,类似于Java的注解,
可以给一些类或方法上添加这个特性,可以完成aop切入 或 ioc依赖注入等功能,
对业务拆分有很大的用途
正怒月神 2018-08-22
  • 打赏
  • 举报
回复
这是一个特性,可能是自定义特性
你可以f12导航到合格属性的实现。一般都是继承自 attribute,然后实现一下内部逻辑。
说白了是一个过滤器。
stherix 2018-08-22
  • 打赏
  • 举报
回复
就是Attribute啊
和下面的[DllImport]一样的语法,只是功能不同
Attribute可以通过反射获取,为类/字段等提供附加信息,让代码可以针对其主体进行各种操作

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧