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


C# Attribute.OfType方法代码示例

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


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

示例1: MetadataPropertyDescriptorWrapper

 public MetadataPropertyDescriptorWrapper(PropertyDescriptor descriptor, Attribute[] newAttributes)
     : base(descriptor, newAttributes)
 {
     _descriptor = descriptor;
     var readOnlyAttribute = newAttributes.OfType<ReadOnlyAttribute>().FirstOrDefault();
     _isReadOnly = (readOnlyAttribute != null ? readOnlyAttribute.IsReadOnly : false);
 }
开发者ID:expanz,项目名称:expanz-Microsoft-XAML-SDKs,代码行数:7,代码来源:MetadataPropertyDescriptorWrapper.cs

示例2: Extract

 public LoggingData[] Extract(Attribute[] attributes, string defaultName, object @object)
 {
     return
         attributes
             .OfType<LogAttribute>()
             .Select(x => new LoggingData
             {
                 Name = GetLogName(x, defaultName),
                 Value = @object.ToString()
             })
             .ToArray();
 }
开发者ID:ymassad,项目名称:AOPExamples,代码行数:12,代码来源:LogAttributeBasedLoggingDataExtractor.cs

示例3: CachedDataAnnotationsMetadataAttributes

        public CachedDataAnnotationsMetadataAttributes(Attribute[] attributes) {
            DataType = attributes.OfType<DataTypeAttribute>().FirstOrDefault();
            Display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
            DisplayColumn = attributes.OfType<DisplayColumnAttribute>().FirstOrDefault();
            DisplayFormat = attributes.OfType<DisplayFormatAttribute>().FirstOrDefault();
            DisplayName = attributes.OfType<DisplayNameAttribute>().FirstOrDefault();
            Editable = attributes.OfType<EditableAttribute>().FirstOrDefault();
            HiddenInput = attributes.OfType<HiddenInputAttribute>().FirstOrDefault();
            ReadOnly = attributes.OfType<ReadOnlyAttribute>().FirstOrDefault();
            Required = attributes.OfType<RequiredAttribute>().FirstOrDefault();
            ScaffoldColumn = attributes.OfType<ScaffoldColumnAttribute>().FirstOrDefault();

            var uiHintAttributes = attributes.OfType<UIHintAttribute>();
            UIHint = uiHintAttributes.FirstOrDefault(a => String.Equals(a.PresentationLayer, "MVC", StringComparison.OrdinalIgnoreCase))
                  ?? uiHintAttributes.FirstOrDefault(a => String.IsNullOrEmpty(a.PresentationLayer));

            if (DisplayFormat == null && DataType != null) {
                DisplayFormat = DataType.DisplayFormat;
            }
        }
开发者ID:adrianvallejo,项目名称:MVC3_Source,代码行数:20,代码来源:CachedDataAnnotationsMetadataAttributes.cs

示例4: GenericField

        //For generic automatic editors. Passing a MemberInfo will also check for attributes
        public static object GenericField(string name, object value, Type t, MemberInfo member = null, object instance = null)
        {
            if (t == null){
                GUILayout.Label("NO TYPE PROVIDED!");
                return value;
            }

            //Preliminary Hides
            if (typeof(Delegate).IsAssignableFrom(t)){
                return value;
            }

            name = name.SplitCamelCase();

            //

            IEnumerable<Attribute> attributes = new Attribute[0];
            if (member != null){

                //Hide class?
                if (t.GetCustomAttributes(typeof(HideInInspector), true ).FirstOrDefault() != null){
                    return value;
                }

                attributes = member.GetCustomAttributes(true).Cast<Attribute>();

                //Hide field?
                if (attributes.Any(a => a is HideInInspector) ){
                    return value;
                }

                //Is required?
                if (attributes.Any(a => a is RequiredFieldAttribute)){
                    if ( (value == null || value.Equals(null) ) ||
                        (t == typeof(string) && string.IsNullOrEmpty((string)value) ) ||
                        (typeof(BBParameter).IsAssignableFrom(t) && (value as BBParameter).isNull) )
                    {
                        GUI.backgroundColor = lightRed;
                    }
                }
            }

            if (member != null){
                var nameAtt = attributes.FirstOrDefault(a => a is NameAttribute) as NameAttribute;
                if (nameAtt != null){
                    name = nameAtt.name;
                }

                if (instance != null){
                    var showAtt = attributes.FirstOrDefault(a => a is ShowIfAttribute) as ShowIfAttribute;
                    if (showAtt != null){
                        var targetField = instance.GetType().GetField(showAtt.fieldName);
                        if (targetField == null || targetField.FieldType != typeof(bool)){
                            GUILayout.Label(string.Format("[ShowIf] Error: bool \"{0}\" does not exist.", showAtt.fieldName));
                        } else {
                            if ((bool)targetField.GetValue(instance) != showAtt.show){
                                return value;
                            }
                        }
                    }
                }
            }

            //Before everything check BBParameter
            if (typeof(BBParameter).IsAssignableFrom(t)){
                return BBParameterField(name, (BBParameter)value, false, member);
            }

            //Cutstom object drawers
            var objectDrawer = GetCustomDrawer(t);
            if (objectDrawer != null && !(objectDrawer is NoDrawer) ){
                return objectDrawer.DrawGUI(name, value, member as FieldInfo, null, instance);
            }

            //Cutstom attribute drawers
            foreach(CustomDrawerAttribute att in attributes.OfType<CustomDrawerAttribute>()){
                var attributeDrawer = GetCustomDrawer(att.GetType());
                if (attributeDrawer != null && !(attributeDrawer is NoDrawer)){
                    return attributeDrawer.DrawGUI(name, value, member as FieldInfo, att, instance);
                }
            }

            //Then check UnityObjects
            if ( typeof(UnityObject).IsAssignableFrom(t) ) {
                if (t == typeof(Component) && (Component)value != null)
                    return ComponentField(name, (Component)value, typeof(Component));
                return EditorGUILayout.ObjectField(name, (UnityObject)value, t, true);
            }

            //Force UnityObject field?
            if (member != null && attributes.Any(a => a is ForceObjectFieldAttribute)){
                return EditorGUILayout.ObjectField(name, value as UnityObject, t, true );
            }

            //Restricted popup values?
            if (member != null){
                var popAtt = attributes.FirstOrDefault(a => a is PopupFieldAttribute) as PopupFieldAttribute;
                if (popAtt != null){
                    if (popAtt.staticPath != null){
//.........这里部分代码省略.........
开发者ID:nemish,项目名称:cubematters,代码行数:101,代码来源:EditorUtils_GUI.cs

示例5: GetFormat

            static string GetFormat(Type propertyType, Attribute[] attributes)
            {
                var format = attributes.OfType<DisplayFormatAttribute>().Select(f => f.DataFormatString).FirstOrDefault();
                if (format == null && propertyType == typeof(int))
                    format = "N0";

                return format;
            }
开发者ID:vc3,项目名称:ExoModel,代码行数:8,代码来源:EntityFrameworkTypeProvider.cs

示例6: CreateValueProperty

        /// <summary>
        /// Overridden to allow the addition of buddy-class attributes to the list of attributes associated with the <see cref="ModelType"/>
        /// </summary>
        /// <param name="declaringType"></param>
        /// <param name="property"></param>
        /// <param name="name"></param>
        /// <param name="isStatic"></param>
        /// <param name="isBoundary"></param>
        /// <param name="propertyType"></param>
        /// <param name="isList"></param>
        /// <param name="attributes"></param>
        /// <returns></returns>
        protected override ModelValueProperty CreateValueProperty(ModelType declaringType, System.Reflection.PropertyInfo property, string name, string label, string helptext, string format, bool isStatic, Type propertyType, TypeConverter converter, bool isList, bool isReadOnly, bool isPersisted, Attribute[] attributes)
        {
            // Do not include entity reference properties in the model
            if (property.PropertyType.IsSubclassOf(typeof(EntityReference)))
                return null;

            // Fetch any attributes associated with a buddy-class
            attributes = attributes.Union(GetBuddyClassAttributes(declaringType, property)).ToArray();

            // Mark properties that are not mapped as not persisted
            isPersisted = !attributes.OfType<NotMappedAttribute>().Any();

            return new EntityValueProperty(declaringType, property, name, label, helptext, format, isStatic, propertyType, converter, isList, isReadOnly, isPersisted, attributes);
        }
开发者ID:vc3,项目名称:ExoModel,代码行数:26,代码来源:EntityFrameworkTypeProvider.cs

示例7: CreateReferenceProperty

        /// <summary>
        /// Overridden to allow the addition of buddy-class attributes to the list of attributes associated with the <see cref="ModelType"/>
        /// </summary>
        /// <param name="declaringType"></param>
        /// <param name="property"></param>
        /// <param name="name"></param>
        /// <param name="isStatic"></param>
        /// <param name="isBoundary"></param>
        /// <param name="propertyType"></param>
        /// <param name="isList"></param>
        /// <param name="attributes"></param>
        /// <returns></returns>
        protected override ModelReferenceProperty CreateReferenceProperty(ModelType declaringType, System.Reflection.PropertyInfo property, string name, string label, string helptext, string format, bool isStatic, ModelType propertyType, bool isList, bool isReadOnly, bool isPersisted, Attribute[] attributes)
        {
            // Fetch any attributes associated with a buddy-class
            attributes = attributes.Union(GetBuddyClassAttributes(declaringType, property)).ToArray();

            // Mark properties that are not mapped as not persisted
            isPersisted = !attributes.OfType<NotMappedAttribute>().Any();

            // Determine whether the property represents an actual entity framework navigation property or an custom property
            var context = GetObjectContext();
            var type = context.ObjectContext.MetadataWorkspace.GetItem<EntityType>(((EntityModelType)declaringType).UnderlyingType.FullName, DataSpace.CSpace);
            NavigationProperty navProp;
            type.NavigationProperties.TryGetValue(name, false, out navProp);
            return new EntityReferenceProperty(declaringType, navProp, property, name, label, helptext, format, isStatic, propertyType, isList, isReadOnly, isPersisted, attributes);
        }
开发者ID:vc3,项目名称:ExoModel,代码行数:27,代码来源:EntityFrameworkTypeProvider.cs

示例8: CreateValueProperty

 protected override ModelValueProperty CreateValueProperty(ModelType declaringType, PropertyInfo property, string name, string label, string helptext, string format, bool isStatic, Type propertyType, System.ComponentModel.TypeConverter converter, bool isList, bool isReadOnly, bool isPersisted, Attribute[] attributes)
 {
     format = format ?? attributes.OfType<DisplayFormatAttribute>().Select(f => f.DataFormatString).FirstOrDefault();
     return base.CreateValueProperty(declaringType, property, name, label, helptext, format, isStatic, propertyType, converter, isList, isReadOnly, isPersisted, attributes);
 }
开发者ID:vc3,项目名称:ExoModel,代码行数:5,代码来源:TestModelTypeProvider.cs

示例9: GetConstraints

        private static void GetConstraints(Attribute[] attributes, IConstraintsNode constraintsNode)
        {
            if (attributes != null)
            {
                if (attributes.Any(x => x is RequiredAttribute))
                {
                    constraintsNode.IsRequired = true;
                }

                var stringLengthAttribute = attributes.OfType<StringLengthAttribute>().FirstOrDefault();
                if (stringLengthAttribute != null)
                {
                    constraintsNode.MinimumLength = stringLengthAttribute.MinimumLength;
                    constraintsNode.MaximumLength = stringLengthAttribute.MaximumLength;
                }

                var minLengthAttribute = attributes.OfType<MaxLengthAttribute>().FirstOrDefault();
                if (minLengthAttribute != null)
                {
                    constraintsNode.MinimumLength = minLengthAttribute.Length;
                }

                var maxLengthAttribute = attributes.OfType<MaxLengthAttribute>().FirstOrDefault();
                if (maxLengthAttribute != null)
                {
                    constraintsNode.MaximumLength = maxLengthAttribute.Length;
                }

                var compareAttribute = attributes.OfType<CompareAttribute>().FirstOrDefault();
                if (compareAttribute != null)
                {
                    constraintsNode.CompareTo = StringHelpers.ToCamelCase(compareAttribute.OtherProperty);
                }

                var rangeAttribute = attributes.OfType<RangeAttribute>().FirstOrDefault();
                if (rangeAttribute != null)
                {
                    constraintsNode.Minimum = rangeAttribute.Minimum;
                    constraintsNode.Maximum = rangeAttribute.Maximum;
                }

                if (attributes.Any(x => x is EmailAddressAttribute))
                {
                    constraintsNode.Format = Format.Email;
                }
            }
        }
开发者ID:folkelib,项目名称:Folke.CsTsService,代码行数:47,代码来源:Converter.cs


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