/// <summary>
        ///     Creates dynamic property instance for the specified <see cref="PropertyInfo" />.
        /// </summary>
        /// <param name="property">Property info to create dynamic property for.</param>
        /// <returns>Dynamic property for the specified <see cref="PropertyInfo" />.</returns>
        public static IDynamicProperty Create(PropertyInfo property)
        {
            AssertUtils.ArgumentNotNull(property, "You cannot create a dynamic property for a null value.");

            IDynamicProperty dynamicProperty = new SafeProperty(property);
            return dynamicProperty;
        }
 public PropertyValueAccessor(PropertyInfo propertyInfo)
 {
     _name = propertyInfo.Name;
     _isReadable = propertyInfo.CanRead;
     _isWriteable = propertyInfo.CanWrite;
     _targetType = propertyInfo.PropertyType;
     _contextType = propertyInfo.DeclaringType;
     _property = new SafeProperty(propertyInfo);
 }
Esempio n. 3
0
        private object[] InitializeIndexerProperty(object context, EvaluationContext evalContext)
        {
            var indices = ResolveArguments(evalContext);

            if (_indexer == null)
            {
                lock (this)
                {
                    if (_indexer == null)
                    {
                        var contextType = context.GetType();
                        var argTypes = ReflectionUtils.GetTypes(indices);
                        var defaultMember = "Item";
                        var atts = contextType.GetCustomAttributes(typeof (DefaultMemberAttribute), true);
                        if (atts.Length > 0)
                        {
                            defaultMember = ((DefaultMemberAttribute) atts[0]).MemberName;
                        }
                        var indexerProperty = contextType.GetProperty(defaultMember, DefaultBindingFlags, null, null, argTypes, null);
                        if (indexerProperty == null)
                        {
                            throw new ArgumentException("Indexer property with specified number and types of arguments does not exist.");
                        }

                        _indexer = new SafeProperty(indexerProperty);
                    }
                }
            }

            return indices;
        }