Exemple #1
0
        private static AttributeUsageContent GetAttributeUsage([NotNull] IClass attributeClass)
        {
            AttributeTargets targets;
            bool             allowMultiple;
            bool             inherited;

            var attributeUsage = attributeClass.GetAttributeInstances(PredefinedType.ATTRIBUTE_USAGE_ATTRIBUTE_CLASS, true).FirstOrDefault();

            if (attributeUsage == null)
            {
                targets       = AttributeTargets.All;
                allowMultiple = attributeClass.HasAttributeInstance(PredefinedType.WINRT_ALLOW_MULTIPLE_ATTRIBUTE_CLASS, true);
                inherited     = true;
            }
            else
            {
                targets       = ((AttributeTargets?)(attributeUsage.PositionParameter(0).ConstantValue.Value as int?)) ?? AttributeTargets.All;
                allowMultiple = attributeUsage.NamedParameter(nameof(AttributeUsageAttribute.AllowMultiple)).ConstantValue.Value as bool? ?? false;
                inherited     = attributeUsage.NamedParameter(nameof(AttributeUsageAttribute.Inherited)).ConstantValue.Value as bool? ?? true;
            }

            return(new AttributeUsageContent(targets.ToHumanReadableString(), allowMultiple, inherited));
        }
        protected bool ExistsSerializableAttribute(IClass @class)
        {
            //		TODO Check ISerializable end Deserializable constructor

            IList<IAttributeInstance> instances = @class.GetAttributeInstances(false);
            if (instances == null)
                return false;
            IList<IAttributeInstance> found = CollectionUtil.FindAll(instances, delegate(IAttributeInstance obj)
                                                                                    {
                                                                                        return
                                                                                            obj.AttributeType.GetCLRName
                                                                                                () ==
                                                                                            "System.SerializableAttribute";
                                                                                    });
            return found.Count > 0;
        }
 public IEnumerable <IAttributeInfo> GetCustomAttributes(Type attributeType)
 {
     return(from attribute in psiType.GetAttributeInstances(true)
            where attributeType.IsAssignableFrom(attribute.GetAttributeType())
            select attribute.AsAttributeInfo());
 }