當前位置: 首頁>>代碼示例>>C#>>正文


C# Attribute.Any方法代碼示例

本文整理匯總了C#中System.Attribute.Any方法的典型用法代碼示例。如果您正苦於以下問題:C# Attribute.Any方法的具體用法?C# Attribute.Any怎麽用?C# Attribute.Any使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Attribute的用法示例。


在下文中一共展示了Attribute.Any方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IsAsync

 public bool IsAsync(MethodInfo method, Attribute[] attributes)
 {
     return attributes != null && attributes.Any(attribute => attribute is AsyncAttribute);
 }
開發者ID:joefeser,項目名稱:Burrow.NET,代碼行數:4,代碼來源:IMethodFilter.cs

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

示例3: 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.Any方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。