本文整理汇总了C#中System.Attribute.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Attribute.GetType方法的具体用法?C# Attribute.GetType怎么用?C# Attribute.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Attribute
的用法示例。
在下文中一共展示了Attribute.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExcludeKnownAttrsFilter
public static bool ExcludeKnownAttrsFilter(Attribute x)
{
return x.GetType() != typeof(RouteAttribute)
&& x.GetType() != typeof(DescriptionAttribute)
&& x.GetType().Name != "DataContractAttribute" //Type equality issues with Mono .NET 3.5/4
&& x.GetType().Name != "DataMemberAttribute";
}
示例2: Translate
public ClientValidationRule Translate(Attribute attribute)
{
Type type = attribute.GetType();
if (type == typeof(RegexValidatorAttribute))
{
return new RegexClientValidationRule((attribute as RegexValidatorAttribute).Pattern);
}
#pragma warning disable 0612
else if (type == typeof(StringLengthValidatorAttribute))
{
return new StringLengthClientValidationRule((attribute as StringLengthValidatorAttribute).LowerBound, (attribute as StringLengthValidatorAttribute).UpperBound);
}
#pragma warning restore 0612
else if (type == typeof(StringSizeValidatorAttribute))
{
return new StringLengthClientValidationRule((attribute as StringSizeValidatorAttribute).LowerBound, (attribute as StringSizeValidatorAttribute).UpperBound);
}
else if (type == typeof(Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidatorAttribute))
{
return new NotNullClientValidationRule();
}
else
{
throw new InvalidOperationException(string.Format("The attribute type '{0}' is not supported", attribute.GetType()));
}
}
示例3: BuildResourceKey
internal static string BuildResourceKey(string keyPrefix, Attribute attribute)
{
if(attribute == null)
throw new ArgumentNullException(nameof(attribute));
var result = BuildResourceKey(keyPrefix, attribute.GetType());
if(attribute.GetType().IsAssignableFrom(typeof(DataTypeAttribute)))
result += ((DataTypeAttribute) attribute).DataType;
return result;
}
示例4: CompareTo
public int CompareTo(Attribute t)
{
if (t.GetType() == typeof(DateAttribute))
return this._date.CompareTo((DateTime)t.Value);
else
return -1;
}
示例5: GetAttributeDeclaration
public static AttributeDeclaration GetAttributeDeclaration(Attribute attribute, ClientCodeGenerator textTemplateClientCodeGenerator, bool forcePropagation)
{
Type attributeType = attribute.GetType();
// Check if this attribute should be blocked
if (IsAttributeBlocked(attributeType))
{
return null;
}
ICustomAttributeBuilder cab = GetCustomAttributeBuilder(attributeType);
AttributeDeclaration attributeDeclaration = null;
if (cab != null)
{
try
{
attributeDeclaration = cab.GetAttributeDeclaration(attribute);
}
catch (AttributeBuilderException)
{
return null;
}
if (attributeDeclaration != null)
{
if (!forcePropagation)
{
// Verify attribute's shared type|property|method requirements are met
ValidateAttributeDeclarationRequirements(attributeDeclaration, textTemplateClientCodeGenerator);
}
}
}
return attributeDeclaration;
}
示例6: Disassemble
public CustomAttributeBuilder Disassemble(Attribute attribute)
{
var type = attribute.GetType();
try
{
IConstructorInfo ctor;
var ctorArgs = GetConstructorAndArgs(type, attribute, out ctor);
var replicated = (Attribute)Activator.CreateInstance(type, ctorArgs);
IPropertyInfo[] properties;
var propertyValues = GetPropertyValues(type, out properties, attribute, replicated);
IFieldInfo[] fields;
var fieldValues = GetFieldValues(type, out fields, attribute, replicated);
#if !NETFX_CORE
return new CustomAttributeBuilder(ctor.AsConstructorInfo(), ctorArgs,
DotNetFixup.AsPropertyInfos(properties).ToArray(), propertyValues,
DotNetFixup.AsFieldInfos(fields).ToArray(), fieldValues);
#else
return new CustomAttributeBuilder(ctor, ctorArgs, properties, propertyValues, fields, fieldValues);
#endif
}
catch (Exception ex)
{
// there is no real way to log a warning here...
return HandleError(type, ex);
}
}
示例7: ApplyAttribute
// public methods
/// <summary>
/// Apply an attribute to these serialization options and modify the options accordingly.
/// </summary>
/// <param name="serializer">The serializer that these serialization options are for.</param>
/// <param name="attribute">The serialization options attribute.</param>
public override void ApplyAttribute(IBsonSerializer serializer, Attribute attribute)
{
EnsureNotFrozen();
var itemSerializer = serializer.GetItemSerializationInfo().Serializer;
if (_itemSerializationOptions == null)
{
var itemDefaultSerializationOptions = itemSerializer.GetDefaultSerializationOptions();
// special case for legacy collections: allow BsonRepresentation on object
if (itemDefaultSerializationOptions == null &&
(serializer.GetType() == typeof(EnumerableSerializer) || serializer.GetType() == typeof(QueueSerializer) || serializer.GetType() == typeof(StackSerializer)) &&
attribute.GetType() == typeof(BsonRepresentationAttribute))
{
itemDefaultSerializationOptions = new RepresentationSerializationOptions(BsonType.Null); // will be modified later by ApplyAttribute
}
if (itemDefaultSerializationOptions == null)
{
var message = string.Format(
"A serialization options attribute of type {0} cannot be used when the serializer is of type {1} and the item serializer is of type {2}.",
BsonUtils.GetFriendlyTypeName(attribute.GetType()),
BsonUtils.GetFriendlyTypeName(serializer.GetType()),
BsonUtils.GetFriendlyTypeName(itemSerializer.GetType()));
throw new NotSupportedException(message);
}
_itemSerializationOptions = itemDefaultSerializationOptions.Clone();
}
_itemSerializationOptions.ApplyAttribute(itemSerializer, attribute);
}
示例8: CreateCustomAttribute
public static CustomAttributeBuilder CreateCustomAttribute(Attribute attribute)
{
Type attType = attribute.GetType();
ConstructorInfo ci;
object[] ctorArgs = GetConstructorAndArgs(attType, attribute, out ci);
PropertyInfo[] properties;
object[] propertyValues = GetPropertyValues(attType, out properties, attribute);
FieldInfo[] fields;
object[] fieldValues = GetFieldValues(attType, out fields, attribute);
// here we are going to try to initialize the attribute with the collected arguments
// if we are good (created successfuly) we return it, otherwise, it is ignored.
try
{
Activator.CreateInstance(attType, ctorArgs);
return new CustomAttributeBuilder(ci, ctorArgs, properties, propertyValues, fields, fieldValues);
}
catch
{
// there is no real way to log a warning here...
Trace.WriteLine(@"Dynamic Proxy 2: Unable to find matching parameters for replicating attribute " + attType.FullName +
".");
return null;
}
}
示例9: Initialize
public void Initialize(Attribute attribute)
{
//Get all parametters of the Attribute: the name and their values.
//For example:
//In LengthAttribute the parametter are Min and Max.
System.Type clazz = attribute.GetType();
IRuleArgs ruleArgs = attribute as IRuleArgs;
if (ruleArgs == null)
{
throw new ArgumentException("Attribute " + clazz + " doesn't implement IRuleArgs interface.");
}
else
{
if (ruleArgs.Message == null)
{
throw new ArgumentException(string.Format("The value of the message in {0} attribute is null (nothing for VB.Net Users). Add some message ", clazz) +
"on the attribute to solve this issue. For Example:\n" +
"- private string message = \"Error on property Foo\";\n" +
"Or you can use interpolators with resources files:\n" +
"-private string message = \"{validator.MyValidatorMessage}\";");
}
attributeMessage = ruleArgs.Message;
}
foreach (PropertyInfo property in clazz.GetProperties())
{
attributeParameters.Add(property.Name.ToLowerInvariant(), property.GetValue(attribute, null));
}
}
示例10: Contains
public bool Contains (Attribute attr)
{
Attribute at = this [attr.GetType ()];
if (at != null)
return attr.Equals (at);
else
return false;
}
示例11: ProcessMethod
internal override void ProcessMethod(XElement element, MethodInfo method, Attribute annotation)
{
ProcessorBase processor;
if (processors.TryGetValue(annotation.GetType().Name, out processor))
{
processor.ProcessMethod(element, method, annotation);
}
}
示例12: GetActionFilters
private IEnumerable GetActionFilters(Attribute attribute)
{
var filterType = typeof(IActionFilter<>).MakeGenericType(attribute.GetType());
var filters = this.container.Invoke(filterType);
return filters;
}
示例13: NavigationTypeNotSupportedException
public NavigationTypeNotSupportedException(Attribute attribute, string elementName)
: base(string.Format(@"A navigation attribute of '{0}' was found on your page object, " +
"but your driver doesn't currently support this navigation method.\r\n" +
"Navigating to the element identified by the property '{1}' failed.",
attribute.GetType().Name, elementName))
{
Attribute = attribute;
}
示例14: ProcessType
internal override void ProcessType(XElement element, Type type, Attribute annotation)
{
ProcessorBase processor;
if (processors.TryGetValue(annotation.GetType().Name, out processor))
{
processor.ProcessType(element, type, annotation);
}
}
示例15: ProcessParameter
internal override void ProcessParameter(XElement parent, ParameterInfo parameter, Attribute annotation)
{
ProcessorBase processor;
if (processors.TryGetValue(annotation.GetType().Name, out processor))
{
processor.ProcessParameter(parent, parameter, annotation);
}
}