本文整理汇总了C#中AttributeTargets类的典型用法代码示例。如果您正苦于以下问题:C# AttributeTargets类的具体用法?C# AttributeTargets怎么用?C# AttributeTargets使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttributeTargets类属于命名空间,在下文中一共展示了AttributeTargets类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAttributeUsage
private void GetAttributeUsage()
{
if (analyzedType.HasCustomAttributes) {
foreach (CustomAttribute ca in analyzedType.CustomAttributes) {
TypeReference t = ca.AttributeType;
if (t.Name == "AttributeUsageAttribute" && t.Namespace == "System") {
this.usage = (AttributeTargets)ca.ConstructorArguments[0].Value;
if (ca.ConstructorArguments.Count > 1) {
this.allowMutiple = (bool)ca.ConstructorArguments[1].Value;
this.inherited = (bool)ca.ConstructorArguments[2].Value;
}
if (ca.HasProperties) {
foreach (var namedArgument in ca.Properties) {
switch (namedArgument.Name) {
case "AllowMultiple":
this.allowMutiple = (bool)namedArgument.Argument.Value;
break;
case "Inherited":
this.inherited = (bool)namedArgument.Argument.Value;
break;
}
}
}
}
}
}
}
示例2: AttributeGen
internal AttributeGen(AttributeTargets target, AttributeType attributeType, object[] args)
{
if (args != null)
{
foreach (object arg in args)
{
CheckValue(arg);
}
}
// TODO: target validation
this.attributeType = attributeType;
Operand[] argOperands;
if (args == null || args.Length == 0)
{
this.args = EmptyArray<object>.Instance;
argOperands = Operand.EmptyArray;
}
else
{
this.args = args;
argOperands = new Operand[args.Length];
for (int i = 0; i < args.Length; i++)
{
argOperands[i] = GetOperand(args[i]);
}
}
this.ctor = TypeInfo.FindConstructor(attributeType, argOperands);
}
示例3: GetAttributeUsage
void GetAttributeUsage() {
if (analyzedType.HasCustomAttributes) {
foreach (CustomAttribute ca in analyzedType.CustomAttributes) {
ITypeDefOrRef t = ca.AttributeType;
if (t != null && t.Name == "AttributeUsageAttribute" && t.Namespace == "System" &&
ca.ConstructorArguments.Count > 0 &&
ca.ConstructorArguments[0].Value is int) {
usage = (AttributeTargets)ca.ConstructorArguments[0].Value;
if (ca.ConstructorArguments.Count > 2) {
if (ca.ConstructorArguments[1].Value is bool)
allowMutiple = (bool)ca.ConstructorArguments[1].Value;
if (ca.ConstructorArguments[2].Value is bool)
inherited = (bool)ca.ConstructorArguments[2].Value;
}
foreach (var namedArgument in ca.Properties) {
switch (namedArgument.Name) {
case "AllowMultiple":
if (namedArgument.Argument.Value is bool)
allowMutiple = (bool)namedArgument.Argument.Value;
break;
case "Inherited":
if (namedArgument.Argument.Value is bool)
inherited = (bool)namedArgument.Argument.Value;
break;
}
}
}
}
}
}
示例4: AttributeBlockNode
public AttributeBlockNode(Token token,
AttributeTargets location,
ParseNodeList attributes)
: base(ParseNodeType.AttributeBlock, token) {
_location = location;
_attributes = GetParentedNodeList(attributes);
}
示例5: AttributeUsageAttribute
internal AttributeUsageAttribute(AttributeTargets validOn, bool allowMultiple, bool inherited)
{
this.m_attributeTarget = AttributeTargets.All;
this.m_inherited = true;
this.m_attributeTarget = validOn;
this.m_allowMultiple = allowMultiple;
this.m_inherited = inherited;
}
示例6: AttributeUsageTest
public AttributeUsageTest(MemberInfo member,
AttributeTargets validOn,
bool allowMultiple,
bool inherited)
: base(member)
{
ValidOn = validOn;
AllowMultiple = allowMultiple;
Inherited = inherited;
}
示例7: AttributeCanBeAppliedToCodeElementsSupportedBySubstituteAttributeRelay
public void AttributeCanBeAppliedToCodeElementsSupportedBySubstituteAttributeRelay(AttributeTargets expectedTarget)
{
// Fixture setup
var attributeUsage = typeof(SubstituteAttribute).GetCustomAttributes(false)
.OfType<AttributeUsageAttribute>().Single();
// Exercise system
Assert.Equal(expectedTarget, attributeUsage.ValidOn & expectedTarget);
// Verify outcome
// Teardown
}
示例8: AttributeUsageInfo
internal AttributeUsageInfo(AttributeTargets validTargets, bool allowMultiple, bool inherited)
{
// NOTE: VB allows AttributeUsageAttribute with no valid target, i.e. <AttributeUsageAttribute(0)>, and doesn't generate any diagnostics.
// We use use PackedAttributeUsage.Initialized field to differentiate between uninitialized AttributeUsageInfo and initialized AttributeUsageInfo with no valid targets.
flags = (PackedAttributeUsage)validTargets | PackedAttributeUsage.Initialized;
if (allowMultiple)
{
flags |= PackedAttributeUsage.AllowMultiple;
}
if (inherited)
{
flags |= PackedAttributeUsage.Inherited;
}
}
示例9: AttributeUsageAttribute
public AttributeUsageAttribute (AttributeTargets validOn)
{
valid_on = validOn;
}
示例10: GetAttributeTargetName
public virtual string GetAttributeTargetName(AttributeTargets targets) {
if (this.ErrorHandler == null) return "";
return this.ErrorHandler.GetAttributeTargetName(targets);
}
示例11: AttributeUsageAttribute
public AttributeUsageAttribute(AttributeTargets validOn)
{
this.validOn = validOn;
}
示例12: AttributeUsageAttribute
public AttributeUsageAttribute(AttributeTargets validOn) { }
示例13: InvalidAttributeTarget
public static CompilerError InvalidAttributeTarget(Node node, Type attrType, AttributeTargets validOn)
{
return new CompilerError("BCE0153", SafeLexicalInfo(node), attrType, validOn);
}
示例14: ParseAttributeUsageAttribute
[System.Security.SecurityCritical] // auto-generated
private static void ParseAttributeUsageAttribute(
ConstArray ca, out AttributeTargets targets, out bool inherited, out bool allowMultiple)
{
int _targets;
_ParseAttributeUsageAttribute(ca.Signature, ca.Length, out _targets, out inherited, out allowMultiple);
targets = (AttributeTargets)_targets;
}
示例15: NonInheritedAttribute
public NonInheritedAttribute(Type type, string str, int i, AttributeTargets e):
this(type, str)
{
}