/// <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) { this.name = propertyInfo.Name; this.isReadable = propertyInfo.CanRead; this.isWriteable = propertyInfo.CanWrite; this.targetType = propertyInfo.PropertyType; this.contextType = propertyInfo.DeclaringType; this.property = new SafeProperty(propertyInfo); }
private object[] InitializeIndexerProperty(object context, EvaluationContext evalContext) { object[] indices = ResolveArguments( evalContext ); if (indexer == null) { lock (this) { if (indexer == null) { Type contextType = context.GetType(); Type[] argTypes = ReflectionUtils.GetTypes(indices); string defaultMember = "Item"; object[] atts = contextType.GetCustomAttributes(typeof(DefaultMemberAttribute), true); if (atts != null && atts.Length > 0) { defaultMember = ((DefaultMemberAttribute) atts[0]).MemberName; } PropertyInfo indexerProperty = contextType.GetProperty(defaultMember, BINDING_FLAGS, 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; }
/// <summary> /// Creates a new instance of the safe indexer wrapper. /// </summary> /// <param name="indexerInfo">Indexer to wrap.</param> public SafeIndexer( PropertyInfo indexerInfo ) { AssertUtils.ArgumentNotNull( indexerInfo, "You cannot create a dynamic indexer for a null value." ); this.indexerProperty = indexerInfo; this.property = new SafeProperty( indexerInfo ); }