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


C# System.Attribute类代码示例

本文整理汇总了C#中System.Attribute的典型用法代码示例。如果您正苦于以下问题:C# Attribute类的具体用法?C# Attribute怎么用?C# Attribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Attribute类属于System命名空间,在下文中一共展示了Attribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

 public static int Main()
 {
     Attribute[]
     attr_array
     =
     new
     Attribute
     [1];
     object
     obj
     =
     (object)
     attr_array;
     object
     []
     obj_array
     =
     (object[])
     obj;
     obj_array
     =
     obj
     as
     object[];
     if
     (obj_array
     ==
     null)
     return
     1;
     return
     0;
 }
开发者ID:robertmichaelwalsh,项目名称:CSharpFrontEnd,代码行数:33,代码来源:array-cast.cs

示例2: GetProperties

        /// <summary>
        /// Returns the property descriptors for this instance.
        /// </summary>
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            Guard.NotNull(() => context, context);

            var descriptors = base.GetProperties(context, value, attributes).Cast<PropertyDescriptor>();

            // Remove descriptors for the data type of this property (string)
            descriptors = descriptors.Where(descriptor => descriptor.ComponentType != typeof(string));

            // Get the model element being described
            var selection = context.Instance;
            ModelElement mel = selection as ModelElement;
            var pel = selection as PresentationElement;
            if (pel != null)
            {
                mel = pel.Subject;
            }

            var element = ExtensionElement.GetExtension<ArtifactExtension>(mel);
            if (element != null)
            {
                // Copy descriptors from owner (make Browsable)
                var descriptor1 = new DelegatingPropertyDescriptor(element, TypedDescriptor.CreateProperty(element, extension => extension.OnArtifactActivation),
                    new BrowsableAttribute(true), new DefaultValueAttribute(element.GetPropertyDefaultValue<ArtifactExtension, ArtifactActivatedAction>(e => e.OnArtifactActivation)));
                var descriptor2 = new DelegatingPropertyDescriptor(element, TypedDescriptor.CreateProperty(element, extension => extension.OnArtifactDeletion),
                    new BrowsableAttribute(true), new DefaultValueAttribute(element.GetPropertyDefaultValue<ArtifactExtension, ArtifactDeletedAction>(e => e.OnArtifactDeletion)));
                descriptors = descriptors.Concat(new[] { descriptor1, descriptor2 });
            }

            return new PropertyDescriptorCollection(descriptors.ToArray());
        }
开发者ID:NuPattern,项目名称:NuPattern,代码行数:34,代码来源:AssociatedArtifactsTypeConverter.cs

示例3: IsPlatformSupported

		/// <summary>
		/// Tests to determine if the current platform is supported
		/// based on a platform attribute.
		/// </summary>
		/// <param name="platformAttribute">The attribute to examine</param>
		/// <returns></returns>
		public bool IsPlatformSupported( Attribute platformAttribute )
		{
			//Use reflection to avoid dependency on a particular framework version
			string include = (string)Reflect.GetPropertyValue( 
				platformAttribute, "Include", 
				BindingFlags.Public | BindingFlags.Instance );

			string exclude = (string)Reflect.GetPropertyValue(
				platformAttribute, "Exclude", 
				BindingFlags.Public | BindingFlags.Instance );

			try
			{
				if (include != null && !IsPlatformSupported(include))
				{
					reason = string.Format("Only supported on {0}", include);
					return false;
				}

				if (exclude != null && IsPlatformSupported(exclude))
				{
					reason = string.Format("Not supported on {0}", exclude);
					return false;
				}
			}
			catch( ArgumentException ex )
			{
				reason = string.Format( "Invalid platform name: {0}", ex.ParamName );
				return false; 
			}

			return true;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:39,代码来源:PlatformHelper.cs

示例4: GetProperties

        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            var props = base.GetProperties(attributes);
            var allProperties = new List<PropertyDescriptor>();

            TypeProviderHelper.AddDefaultProperties(allProperties,props);

            TypeProviderHelper.AddTextBasedProperties(allProperties,props);

            var prop = props.Find("Text", true);
            allProperties.Add(prop);

            prop = props.Find("DrawBorder",true);
            allProperties.Add(prop);

            prop = props.Find("FrameColor",true);
            allProperties.Add(prop);

            prop = props.Find("ForeColor",true);
            allProperties.Add(prop);

            prop = props.Find("Visible",true);
            allProperties.Add(prop);

            prop = props.Find("Expression",true);
            allProperties.Add(prop);

            return new PropertyDescriptorCollection(allProperties.ToArray());
        }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:29,代码来源:TextItemTypeProvider.cs

示例5: 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

示例6: 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

示例7: AddProperty

        public PropertyDescriptorCollection AddProperty(PropertyDescriptorCollection pdc, string propertyName, Type propertyType, TypeConverter converter,
            Attribute[] attributes)
        {
            List<PropertyDescriptor> properties = new List<PropertyDescriptor>(pdc.Count);

            for (int i = 0; i < pdc.Count; i++)
            {
                PropertyDescriptor pd = pdc[i];

                if (pd.Name != propertyName)
                {
                    properties.Add(pd);
                }
            }

            InstanceSavePropertyDescriptor ppd = new InstanceSavePropertyDescriptor(
                propertyName, propertyType, attributes);

            ppd.TypeConverter = converter;

            properties.Add(ppd);

            //PropertyDescriptor propertyDescriptor;

            return new PropertyDescriptorCollection(properties.ToArray());
        }
开发者ID:jiailiuyan,项目名称:Gum,代码行数:26,代码来源:PropertyDescriptorHelper.cs

示例8: PreFilterProperties

        protected override void PreFilterProperties(IDictionary properties)
        {
            base.PreFilterProperties(properties);
            string[] ta = new string[] { "PasswordChar" };
            Attribute[] aa = new Attribute[0];
            for (int num1 = 0; num1 < ta.Length; num1++)
            {
                PropertyDescriptor desc = (PropertyDescriptor)properties[ta[num1]];
                if (desc != null)
                {
                    properties[ta[num1]] = TypeDescriptor.CreateProperty(typeof(TextBoxXDesigner), desc, aa);
                }
            }

            ta = new string[] { "Text" };
            aa = new Attribute[0];
            for (int num1 = 0; num1 < ta.Length; num1++)
            {
                PropertyDescriptor desc = (PropertyDescriptor)properties[ta[num1]];
                if (desc != null)
                {
                    properties[ta[num1]] = TypeDescriptor.CreateProperty(typeof(TextBoxXDesigner), desc, aa);
                }
            }

        }
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:26,代码来源:TextBoxXDesigner.cs

示例9: GetProperties

        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
        {
            List<PropertyDescriptor> propList = new List<PropertyDescriptor>();

            PropertyInfo interactionsProperty = component.GetType().GetProperty("Interactions");
            if (interactionsProperty != null)
            {
                Interactions interactions = (Interactions)interactionsProperty.GetValue(component, null);
                for (int i = 0; i < interactions.FunctionSuffixes.Length; i++)
                {
                    string eventName = interactions.DisplayNames[i];
                    if (UpdateEventName != null)
                    {
                        eventName = UpdateEventName(eventName);
                    }
                    if (eventName.IndexOf("$$") < 0)
                    {
                        // Only add the event if the cursor mode exists
                        propList.Add(new InteractionPropertyDescriptor(component, i, interactions.FunctionSuffixes[i], eventName));
                    }
                }
            }

            return new PropertyDescriptorCollection(propList.ToArray());
        }
开发者ID:CisBetter,项目名称:ags,代码行数:25,代码来源:PropertyTabInteractions.cs

示例10: LambdaPropertyDescriptor

 public LambdaPropertyDescriptor(string propertyName, Type propertyType, Attribute[] attrs,
                                 Type componentType = null)
     : base(propertyName, attrs)
 {
     _propertyType = propertyType;
     _componentType = componentType;
 }
开发者ID:nenadvicentic,项目名称:CustomTypeDescriptors,代码行数:7,代码来源:LambdaPropertyDescriptor.cs

示例11: GetProperties

		public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
		{
			PropertyDescriptorCollection props = base.GetProperties(attributes);
			List<PropertyDescriptor> allProperties = new List<PropertyDescriptor>();

			TypeProviderHelper.AddDefaultProperties(allProperties,props);
			
			PropertyDescriptor prop = null;
			
			prop = props.Find("DrawBorder",true);
			allProperties.Add(prop);
			
			prop = props.Find("ForeColor",true);
			allProperties.Add(prop);
			
			prop = props.Find("Visible",true);
			allProperties.Add(prop);
			
			prop = props.Find("FrameColor",true);
			allProperties.Add(prop);
			
			prop = props.Find("Controls",true);
			allProperties.Add(prop);
	
//			prop = props.Find("AlternateBackColor",true);
//			allProperties.Add(prop);
//			
//			prop = props.Find("ChangeBackColorEveryNRow",true);
//			allProperties.Add(prop);
			
			return new PropertyDescriptorCollection(allProperties.ToArray());
		}
开发者ID:dgrunwald,项目名称:SharpDevelop,代码行数:32,代码来源:RowItemTypeProvider.cs

示例12: GetProperties

		public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
		{
			PropertyDescriptorCollection props = base.GetProperties(attributes);
			List<PropertyDescriptor> allProperties = new List<PropertyDescriptor>();
			
			DesignerHelper.AddDefaultProperties(allProperties,props);
			
			PropertyDescriptor prop = null;
			prop = props.Find("ForeColor",true);
			allProperties.Add(prop);
			
			prop = props.Find("FromPoint",true);
			allProperties.Add(prop);
			
			prop = props.Find("ToPoint",true);
			allProperties.Add(prop);
			
			prop = props.Find("StartLineCap",true);
			allProperties.Add(prop);
			
			prop = props.Find("EndLineCap",true);
			allProperties.Add(prop);
			
			prop = props.Find("dashLineCap",true);
			allProperties.Add(prop);
			
			prop = props.Find("DashStyle",true);
			allProperties.Add(prop);
			
			prop = props.Find("Thickness",true);
			allProperties.Add(prop);
			
			return new PropertyDescriptorCollection(allProperties.ToArray());
		}
开发者ID:Rpinski,项目名称:SharpDevelop,代码行数:34,代码来源:LineItemTypeDescriptor.cs

示例13: CreateObject

        private JObject CreateObject(Type type, Attribute[] attributes, object instance)
        {
            var jObject = CreateEmptyObject(instance);

            var properties = new JArray();
            jObject.Add("properties", properties);
            var hypermediaObject = instance as HypermediaType ?? new HypermediaObject();

            var addedProperties = new Dictionary<string, string>();

            foreach (var propertyInfo in type.GetProperties()) {
                if (PropertyIgnoreList.Contains(propertyInfo.Name)) {
                    continue;
                }

                var property = GetProperty(propertyInfo, instance, hypermediaObject);

                addedProperties.Add(propertyInfo.Name, propertyInfo.Name);
                property.Add("name", ToCamelCase(propertyInfo.Name));
                properties.Add(property);
            }

            foreach (var hypermediaProperty in hypermediaObject.Properties) {
                if (addedProperties.ContainsKey(hypermediaProperty.Key)) {
                    continue;
                }

                var property = SerializeValueType(hypermediaProperty.Value);
                property.Add("name", ToCamelCase(hypermediaProperty.Key));
                properties.Add(property);
            }

            return jObject;
        }
开发者ID:cignium,项目名称:hypermedia-dotnet,代码行数:34,代码来源:HypermediaTypeSerializer.cs

示例14: GetProperties

        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            //var cols = base.GetProperties();
            var props = new PropertyDescriptorCollection(null);

            foreach (FieldInfo fi in value.GetType().GetFields())
            {
                var prop = new WsdlFieldDescriptor(fi, attributes);
                props.Add(prop);
                if (fi.FieldType.BaseType.FullName == "System.Array")
                {
                    TypeDescriptor.AddAttributes(fi.FieldType, new TypeConverterAttribute(typeof(ArrayConverter)));
                    Type elemType = fi.FieldType.GetElementType();
                    TypeDescriptorModifier.modifyType(elemType);
                }
                else if (fi.FieldType.BaseType.FullName == "System.Enum")
                {
                }
                else
                {
                    TypeDescriptorModifier.modifyType(fi.FieldType);
                }
            }

            if (props.Count > 0)
                return props;

            return base.GetProperties(context, value, attributes);
        }
开发者ID:nkarastamatis,项目名称:WebServiceTestStudio_Winforms,代码行数:29,代码来源:WsdlObjectConverter.cs

示例15: GetProperties

 public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
 {
     var pdl = propertyDescriptorList.FindAll(pd => pd.Attributes.Contains(attributes));
     PreProcess(pdl);
     var pdcReturn = new PropertyDescriptorCollection(pdl.ToArray());
     return pdcReturn;
 }
开发者ID:ssuing8825,项目名称:ServiceBusExplorer,代码行数:7,代码来源:DynamicCustomTypeDescriptor.cs


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