protected AbstractTextInputHandler(UIElement parentElement, SimplePropertyDataDescriptor textDataDescriptor,
     SimplePropertyDataDescriptor caretIndexDataDescriptor)
 {
   _parentElement = parentElement;
   _textDataDescriptor = textDataDescriptor;
   _caretIndexDataDescriptor = caretIndexDataDescriptor;
 }
Exemplo n.º 2
0
        public static bool FindDependencyProperty(object obj, ref string propertyName, out AbstractProperty prop)
        {
            prop = null;
            PropertyInfo pi;
            string       name;

            if (!SimplePropertyDataDescriptor.FindSimpleProperty(
                    obj.GetType(), name = (propertyName + "Property"), out pi))
            {
                if (!SimplePropertyDataDescriptor.FindSimpleProperty(obj.GetType(), name = propertyName, out pi))
                {
                    return(false);
                }
            }
            if (typeof(AbstractProperty).IsAssignableFrom(pi.PropertyType))
            {
                prop = pi.GetValue(obj, null) as AbstractProperty;
                if (prop == null)
                {
                    return(false);
                }
                propertyName = name;
                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Given the instance <paramref name="obj"/> and the <paramref name="memberName"/>,
        /// this method searches the best matching member on the instance. It first searches
        /// a property with name [PropertyName]Property, casts it to
        /// <see cref="AbstractProperty"/> and returns a <see cref="DependencyPropertyDataDescriptor"/>
        /// for it in the parameter <paramref name="dd"/>. If there is no such property, this method
        /// searches a simple property with the given name, returning a property descriptor for it.
        /// Then, the method will search for a field with the specified name, returning a
        /// <see cref="FieldDataDescriptor"/> for it.
        /// If there is no member found with the given name, this method returns false and a
        /// <c>null</c> value in <paramref name="dd"/>.
        /// </summary>
        /// <param name="obj">The object where to search the member with the
        /// specified <paramref name="memberName"/>.</param>
        /// <param name="memberName">The name of the member to be searched.</param>
        /// <param name="dd">Data descriptor which will be returned for the property or member,
        /// if it was found, else a <c>null</c> value will be returned.</param>
        /// <returns><c>true</c>, if a member with the specified name was found, else <c>false</c>.</returns>
        public static bool FindMemberDescriptor(object obj, string memberName, out IDataDescriptor dd)
        {
            if (obj == null)
            {
                throw new NullReferenceException("Property target object 'null' is not supported");
            }
            DependencyPropertyDataDescriptor dpdd;

            if (DependencyPropertyDataDescriptor.CreateDependencyPropertyDataDescriptor(
                    obj, memberName, out dpdd))
            {
                dd = dpdd;
                return(true);
            }
            SimplePropertyDataDescriptor spdd;

            if (SimplePropertyDataDescriptor.CreateSimplePropertyDataDescriptor(
                    obj, memberName, out spdd))
            {
                dd = spdd;
                return(true);
            }
            FieldDataDescriptor fdd;

            if (FieldDataDescriptor.CreateFieldDataDescriptor(obj, memberName, out fdd))
            {
                dd = fdd;
                return(true);
            }
            dd = null;
            return(false);
        }
Exemplo n.º 4
0
        public static bool CreateSimplePropertyDataDescriptor(object targetObj,
                                                              string propertyName, out SimplePropertyDataDescriptor result)
        {
            result = null;
            if (targetObj == null)
            {
                throw new NullReferenceException("Target object 'null' is not supported");
            }
            PropertyInfo pi;

            if (!FindSimpleProperty(targetObj.GetType(), propertyName, out pi))
            {
                return(false);
            }
            result = new SimplePropertyDataDescriptor(targetObj, pi);
            return(true);
        }
Exemplo n.º 5
0
        public IDataDescriptor Retarget(object newTarget)
        {
            if (newTarget == null)
            {
                throw new NullReferenceException("Target object 'null' is not supported");
            }
            if (!_prop.DeclaringType.IsAssignableFrom(newTarget.GetType()))
            {
                throw new InvalidOperationException(string.Format(
                                                        "Type of new target object is not compatible with this property descriptor (expected type: {0}, new target type: {1}",
                                                        _prop.DeclaringType.Name, newTarget.GetType().Name));
            }
            SimplePropertyDataDescriptor result = new SimplePropertyDataDescriptor(newTarget, _prop)
            {
                Indices = _indices
            };

            return(result);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Returns the information if the specified <paramref name="other"/> descriptor
 /// is targeted at the same property on the same object.
 /// </summary>
 /// <param name="other">Other descriptor whose target object and property should be compared.</param>
 public bool TargetEquals(SimplePropertyDataDescriptor other)
 {
     return(_obj.Equals(other._obj) && _prop.Equals(other._prop) && IndicesEquals(other._indices));
 }
Exemplo n.º 7
0
 public virtual bool FindContentProperty(out IDataDescriptor dd)
 {
   dd = new SimplePropertyDataDescriptor(this, GetType().GetProperty("BindingValue"));
   return true;
 }
Exemplo n.º 8
0
        public bool Evaluate(IDataDescriptor source, out IDataDescriptor result)
        {
            result = null;
            Type       type;
            object     obj;
            MemberInfo mi;

            if (!ExtractWorkingData(source, _memberName + "Property", out type, out obj, out mi))
            {
                if (!ExtractWorkingData(source, _memberName, out type, out obj, out mi))
                {
                    return(false);
                }
            }
            if (mi is FieldInfo)
            { // Field access
                result = new FieldDataDescriptor(obj, (FieldInfo)mi);
                return(true);
            }
            if (mi is PropertyInfo)
            { // Property access
                PropertyInfo pi = (PropertyInfo)mi;
                // Handle indexed property
                object[] convertedIndices = null;
                // Check property indexer
                bool indicesOnProperty = _indices != null && _indices.Length > 0 &&
                                         ReflectionHelper.ConsumeParameters(_indices, pi.GetIndexParameters(),
                                                                            false, out convertedIndices);
                if (!indicesOnProperty)
                {
                    convertedIndices = null;
                }
                if (pi.PropertyType == typeof(AbstractProperty))
                { // Property value -> request value and return DependencyPropertyDataDescriptor
                    object val = pi.GetValue(obj, convertedIndices);
                    if (val == null)
                    {
                        return(false);
                    }
                    result = new DependencyPropertyDataDescriptor(obj, _memberName, (AbstractProperty)val);
                }
                else
                { // Simple property
                    result = new SimplePropertyDataDescriptor(obj, pi);
                    if (convertedIndices != null && convertedIndices.Length > 0)
                    {
                        ((SimplePropertyDataDescriptor)result).Indices = convertedIndices;
                    }
                }
                if (_indices != null && _indices.Length > 0 && !indicesOnProperty)
                {
                    // Item or collection index -> handle index expression per IndexerPathSegment
                    return(new IndexerPathSegment(_indices).Evaluate(result, out result));
                }
                return(true);
            }
            if (mi is MethodInfo)
            {
                // Method invocation is not supported in evaluation
                return(false);
            }
            // Unsupported member type
            return(false);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Returns the information if the specified <paramref name="other"/> descriptor
 /// is targeted at the same property on the same object.
 /// </summary>
 /// <param name="other">Other descriptor whose target object and property should be compared.</param>
 public bool TargetEquals(SimplePropertyDataDescriptor other)
 {
   return _obj.Equals(other._obj) && _prop.Equals(other._prop) && IndicesEquals(other._indices);
 }
Exemplo n.º 10
0
 public IDataDescriptor Retarget(object newTarget)
 {
   if (newTarget == null)
     throw new NullReferenceException("Target object 'null' is not supported");
   if (!_prop.DeclaringType.IsAssignableFrom(newTarget.GetType()))
     throw new InvalidOperationException(string.Format(
         "Type of new target object is not compatible with this property descriptor (expected type: {0}, new target type: {1}",
         _prop.DeclaringType.Name, newTarget.GetType().Name));
   SimplePropertyDataDescriptor result = new SimplePropertyDataDescriptor(newTarget, _prop) {Indices = _indices};
   return result;
 }
Exemplo n.º 11
0
 public static bool CreateSimplePropertyDataDescriptor(object targetObj,
     string propertyName, out SimplePropertyDataDescriptor result)
 {
   result = null;
   if (targetObj == null)
     throw new NullReferenceException("Target object 'null' is not supported");
   PropertyInfo pi;
   if (!FindSimpleProperty(targetObj.GetType(), propertyName, out pi))
     return false;
   result = new SimplePropertyDataDescriptor(targetObj, pi);
   return true;
 }
 public DefaultTextInputHandler(UIElement parentElement, SimplePropertyDataDescriptor textDataDescriptor,
     SimplePropertyDataDescriptor caretIndexDataDescriptor) :
     base(parentElement, textDataDescriptor, caretIndexDataDescriptor) { }
 public CellPhoneTextInputHandler(UIElement parentElement, SimplePropertyDataDescriptor textDataDescriptor,
     SimplePropertyDataDescriptor caretIndexDataDescriptor) :
     base(parentElement, textDataDescriptor, caretIndexDataDescriptor)
 {
   _timer = new Timer(CURSOR_ADVANCE_TIMESPAN_MS);
   _timer.Elapsed += OnTimerElapsed;
   SetCurrentLayout(0);
 }