public static bool AttributeExists(IEnumerable attributes, ITypeId attributeType)
        {
            bool flag;

            if (attributes != null)
            {
                IEnumerator enumerator = attributes.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        if (!PlatformNeutralAttributeHelper.IsAssignableFrom(attributeType, enumerator.Current))
                        {
                            continue;
                        }
                        flag = true;
                        return(flag);
                    }
                    return(false);
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                return(flag);
            }
            return(false);
        }
        public static KeyValuePair <bool, object> GetDefaultValue(PlatformTypes platformTypes, MemberInfo memberInfo, Type valueType)
        {
            object result;

            if (PlatformNeutralAttributeHelper.TryGetAttributeValue <object>((IEnumerable)platformTypes.GetCustomAttributes(memberInfo), PlatformTypes.DefaultValueAttribute, "Value", out result) && (!valueType.IsValueType && (result == null || valueType.IsAssignableFrom(result.GetType())) || valueType.IsValueType && result != null && valueType.IsAssignableFrom(result.GetType())))
            {
                return(new KeyValuePair <bool, object>(true, result));
            }
            return(PlatformTypeHelper.GetDefaultValue(valueType));
        }
        internal static DesignerSerializationVisibility GetSerializationVisibility(PlatformTypes platformTypes, MemberInfo memberInfo)
        {
            DesignerSerializationVisibility result;

            if (PlatformNeutralAttributeHelper.TryGetAttributeValue <DesignerSerializationVisibility>((IEnumerable)platformTypes.GetCustomAttributes(memberInfo), PlatformTypes.DesignerSerializationVisibilityAttribute, "Visibility", out result))
            {
                return(result);
            }
            return(DesignerSerializationVisibility.Visible);
        }
 public static bool TryGetAttributeValues <T>(IEnumerable attributes, ITypeId attributeType, string propertyName, out List <T> results)
 {
     results = new List <T>();
     if (attributes != null)
     {
         foreach (object attribute in attributes)
         {
             if (!PlatformNeutralAttributeHelper.IsAssignableFrom(attributeType, attribute))
             {
                 continue;
             }
             results.Add(PlatformNeutralAttributeHelper.GetValue <T>(attribute, propertyName));
         }
     }
     return(results.Count > 0);
 }
        public static bool TryGetAttributeValue <T>(IEnumerable attributes, ITypeId attributeType, string propertyName, out T result)
        {
            bool flag;

            if (attributes != null)
            {
                IEnumerator enumerator = attributes.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object current = enumerator.Current;
                        if (!PlatformNeutralAttributeHelper.IsAssignableFrom(attributeType, current))
                        {
                            continue;
                        }
                        result = PlatformNeutralAttributeHelper.GetValue <T>(current, propertyName);
                        flag   = true;
                        return(flag);
                    }
                    result = default(T);
                    return(false);
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
                return(flag);
            }
            result = default(T);
            return(false);
        }
Exemple #6
0
 protected virtual void InitializeAlternateContentPropertiesIfNecessary()
 {
     if (!this.alternateContentPropertiesAreInitialized)
     {
         List <IPropertyId> propertyIds = new List <IPropertyId>();
         Type type = typeof(AlternateContentPropertyAttribute);
         foreach (IProperty property in this.Properties)
         {
             ReferenceStep referenceStep = property as ReferenceStep;
             if (referenceStep == null || referenceStep.Attributes == null || referenceStep.Attributes[type] == null && !PlatformNeutralAttributeHelper.AttributeExists(referenceStep.Attributes, PlatformTypes.AlternateContentPropertyAttribute))
             {
                 continue;
             }
             propertyIds.Add(property);
         }
         this.alternateContentProperties = new ReadOnlyCollection <IPropertyId>(propertyIds);
     }
     this.alternateContentPropertiesAreInitialized = true;
 }
 public static bool TryGetAttributeValues <T>(Type type, ITypeId attributeType, string propertyName, out List <T> results)
 {
     return(PlatformNeutralAttributeHelper.TryGetAttributeValues <T>(TypeUtilities.GetAttributes(type), attributeType, propertyName, out results));
 }