当前位置: 首页>>代码示例>>C#>>正文


C# Attribute.GetType方法代码示例

本文整理汇总了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";
 }
开发者ID:mikkelfish,项目名称:ServiceStack,代码行数:7,代码来源:MetadataTypesHandler.cs

示例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()));
            }
        }
开发者ID:DBailey635,项目名称:C1-CMS,代码行数:28,代码来源:StandardClientValidationRuleTranslator.cs

示例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;
        }
开发者ID:valdisiljuconoks,项目名称:LocalizationProvider,代码行数:11,代码来源:ResourceKeyBuilder.cs

示例4: CompareTo

 public int CompareTo(Attribute t)
 {
     if (t.GetType() == typeof(DateAttribute))
         return this._date.CompareTo((DateTime)t.Value);
     else
         return -1;
 }
开发者ID:tomgud,项目名称:Memorize,代码行数:7,代码来源:dateattribute.cs

示例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;
        }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:34,代码来源:AttributeGeneratorHelper.cs

示例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);
			}
		}
开发者ID:rajgit31,项目名称:MetroUnitTestsDemoApp,代码行数:28,代码来源:AttributeDisassembler.cs

示例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);
        }
开发者ID:ncipollina,项目名称:mongo-csharp-driver,代码行数:36,代码来源:ArraySerializationOptions.cs

示例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;
			}
		}
开发者ID:pallmall,项目名称:WCell,代码行数:31,代码来源:CustomAttributeUtil.cs

示例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));
            }
        }
开发者ID:mpielikis,项目名称:nhibernate-contrib,代码行数:32,代码来源:DefaultMessageInterpolator.cs

示例10: Contains

		public bool Contains (Attribute attr)
		{
			Attribute at = this [attr.GetType ()];
			if (at != null)
				return attr.Equals (at);
			else
				return false;
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:8,代码来源:AttributeCollection.cs

示例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);
     }
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:8,代码来源:DelegatingProcessor.cs

示例12: GetActionFilters

        private IEnumerable GetActionFilters(Attribute attribute)
        {
            var filterType = typeof(IActionFilter<>).MakeGenericType(attribute.GetType());

            var filters = this.container.Invoke(filterType);

            return filters;
        }
开发者ID:plamenyovchev,项目名称:Bloggable,代码行数:8,代码来源:ActionFilterDispatcher.cs

示例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;
 }
开发者ID:kevinjpluck,项目名称:Passenger,代码行数:8,代码来源:NavigationTypeNotSupportedException.cs

示例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);
     }
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:8,代码来源:DelegatingProcessor.cs

示例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);
     }
 }
开发者ID:ivandrofly,项目名称:nodatime,代码行数:8,代码来源:DelegatingProcessor.cs


注:本文中的System.Attribute.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。