Пример #1
0
        protected override void PopulateObject()
        {
            TypeDescription typeDescription = null;
            object          targetObject;

            try
            {
                targetObject = TargetObjectGetter();
            }
            catch (Exception)
            {
                targetObject = null;
                // Items from property getters that throw exceptions are not added to the object hierarchy
                // Ignore silently
            }
            _targetObject = targetObject;
            if (targetObject != null)
            {
                WoopsaVisibilityAttribute woopsaVisibilityAttribute =
                    WoopsaReflection.GetCustomAttribute <WoopsaVisibilityAttribute>(targetObject.GetType());
                if (woopsaVisibilityAttribute != null)
                {
                    Visibility = woopsaVisibilityAttribute.Visibility;
                }
                else
                {
                    Visibility = DefaultVisibility;
                }
            }
            else
            {
                Visibility = DefaultVisibility;
            }
            Type exposedType;

            if (targetObject != null)
            {
                exposedType = ExposedType(targetObject);
            }
            else
            {
                exposedType = null;
            }
            OnTargetObjectChange(targetObject, exposedType);
            base.PopulateObject();
            if (targetObject != null)
            {
                typeDescription = GetTypeDescription(exposedType);
                PopulateProperties(targetObject, exposedType, typeDescription.Properties);
                PopulateMethods(targetObject, exposedType, typeDescription.Methods);
                PopulateItems(targetObject, exposedType, typeDescription.Items);
                if (targetObject is IEnumerable && Visibility.HasFlag(WoopsaVisibility.IEnumerableObject))
                {
                    IEnumerable enumerable = (IEnumerable)targetObject;
                    PopulateEnumerableItems(enumerable, DeclaredExposedType);
                }
            }
        }
Пример #2
0
 public TypeDescription GetTypeDescription(Type type)
 {
     if (type != null)
     {
         TypeDescription result;
         if (!_typeDescriptions.TryGetValue(type, out result))
         {
             result = WoopsaReflection.ReflectType(type, CustomTypeConverters);
             _typeDescriptions[type] = result;
         }
         return(result);
     }
     else
     {
         return(null);
     }
 }
        protected virtual bool IsMemberWoopsaVisible(object targetObject, MemberInfo memberInfo)
        {
            var  woopsaVisibleAttribute = WoopsaReflection.GetCustomAttribute <WoopsaVisibleAttribute>(memberInfo);
            bool isVisible;
            Type targetType = targetObject.GetType();

            if (woopsaVisibleAttribute != null)
            {
                isVisible = woopsaVisibleAttribute.Visible;
            }
            else
            {
                isVisible = Visibility.HasFlag(WoopsaVisibility.DefaultIsVisible);
            }
            if (isVisible)
            {
                if (memberInfo.DeclaringType != targetType)
                {
                    isVisible = Visibility.HasFlag(WoopsaVisibility.Inherited);
                }
            }
            if (isVisible)
            {
                if (memberInfo.DeclaringType == typeof(object))
                {
                    isVisible = Visibility.HasFlag(WoopsaVisibility.ObjectClassMembers);
                }
            }
            if (isVisible)
            {
                if (memberInfo.DeclaringType == typeof(ArrayList) ||
                    (memberInfo.DeclaringType.IsGenericType &&
                     (memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(List <>) ||
                      memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(Collection <>) ||
                      memberInfo.DeclaringType.GetGenericTypeDefinition() == typeof(ObservableCollection <>)))
                    )
                {
                    isVisible = Visibility.HasFlag(WoopsaVisibility.ListClassMembers);
                }
            }
            if (isVisible)
            {
                if (memberInfo is MethodBase)
                {
                    if ((memberInfo as MethodBase).IsSpecialName)
                    {
                        isVisible = Visibility.HasFlag(WoopsaVisibility.MethodSpecialName);
                    }
                }
            }
            if (isVisible)
            {
                if (memberInfo is PropertyInfo)
                {
                    PropertyInfo property = (PropertyInfo)memberInfo;
                    if (typeof(IEnumerable <object>).IsAssignableFrom(property.PropertyType))
                    {
                        isVisible = Visibility.HasFlag(WoopsaVisibility.IEnumerableObject);
                    }
                }
            }
            EventArgsMemberVisibilityCheck e = new EventArgsMemberVisibilityCheck(memberInfo);

            e.IsVisible = isVisible;
            OnMemberWoopsaVisibilityCheck(e);
            isVisible = e.IsVisible;
            return(isVisible);
        }