コード例 #1
0
        internal static bool HasObservableProperties([NotNull] ObservableObject observableObject)
        {
            var type = observableObject.GetType();

            var propertyAccessors = ObservableObjectTypeCache.TryGet(type);

            if (propertyAccessors != null)
            {
                return(propertyAccessors.Count > 0);
            }

            return(GetPropertiesAnnotatedAsObservable(type).Any(property => property.GetIndexParameters().Length == 0));
        }
コード例 #2
0
        public ObservableObjectInfo([NotNull] ObservableObject observableObject)
        {
            var type = observableObject.GetType();

            var propertyAccessors = ObservableObjectTypeCache.Register(
                type,
                () =>
            {
                var list = new List <PropertyAccessor>();

                var objectTypeName = type.Name;

                foreach (var property in GetPropertiesAnnotatedAsObservable(type))
                {
                    if (property.GetIndexParameters().Length == 0)
                    {
                        var propertyType = property.PropertyType;

                        if (propertyType.IsSubclassOf(typeof(CommandBase)))
                        {
                            if (propertyType.IsSubclassOf(typeof(ParameterlessCommand)) || propertyType == typeof(ParameterlessCommand))
                            {
                                list.Add(
                                    new ParameterlessCommandPropertyAccessor(
                                        property.Name,
                                        objectTypeName,
                                        CreateParameterlessCommandPropertyGetMethod(property)));
                            }
                            else
                            {
                                Debug.Assert(propertyType.IsGenericType);
                                Debug.Assert(
                                    propertyType.GetGenericTypeDefinition() == typeof(Command <>) ||
                                    propertyType.GetGenericTypeDefinition() == typeof(AsyncCommand <>) ||
                                    propertyType.GetGenericTypeDefinition() == typeof(ParameterizedCommand <>));

                                list.Add(
                                    new ParameterizedCommandPropertyAccessor(
                                        property.Name,
                                        objectTypeName,
                                        CreateParameterizedCommandPropertyGetMethod(property)));
                            }
                        }
                        else
                        {
                            list.Add(
                                new PropertyPropertyAccessor(
                                    property.Name,
                                    objectTypeName,
                                    CreatePropertyGetMethod(property),
                                    !propertyType.IsValueType));
                        }
                    }
                }

                return(list);
            });

            observableObjectReference = new WeakReference <ObservableObject>(observableObject);
            valueBags = propertyAccessors.ConvertAll(propertyAccessor => propertyAccessor.CreateValueBag(observableObject));
        }