當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。