Exemplo n.º 1
0
        public ConstantValue GetPropertyValue(string name)
        {
            PropertyInfo property = attrib.GetType().GetProperty(name, BindingFlags.Instance | BindingFlags.Public);

            if (property != null && ReflectorAttributeUtils.IsAttributeProperty(Reflector.Wrap(property)))
            {
                return(ConstantValue.FromNative(property.GetValue(attrib, null)));
            }

            throw new ArgumentException(String.Format("The attribute does not have a writable instance property named '{0}'.", name));
        }
Exemplo n.º 2
0
        public ConstantValue GetFieldValue(string name)
        {
            FieldInfo field = attrib.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public);

            if (field != null && ReflectorAttributeUtils.IsAttributeField(Reflector.Wrap(field)))
            {
                return(ConstantValue.FromNative(field.GetValue(attrib)));
            }

            throw new ArgumentException(String.Format("The attribute does not have a writable instance field named '{0}'.", name));
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public ConstantValue GetPropertyValue(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            foreach (KeyValuePair <StaticPropertyWrapper, ConstantValue> entry in PropertyArguments)
            {
                if (entry.Key.Name == name)
                {
                    return(entry.Value);
                }
            }

            IPropertyInfo property = Type.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);

            if (property != null && ReflectorAttributeUtils.IsAttributeProperty(property))
            {
                return(ConstantValue.FromNative(ReflectionUtils.GetDefaultValue(property.ValueType.TypeCode)));
            }

            throw new ArgumentException(String.Format("The attribute does not have a writable instance property named '{0}'.", name));
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public ConstantValue GetFieldValue(string name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            foreach (KeyValuePair <StaticFieldWrapper, ConstantValue> entry in FieldArguments)
            {
                if (entry.Key.Name == name)
                {
                    return(entry.Value);
                }
            }

            IFieldInfo field = Type.GetField(name, BindingFlags.Public | BindingFlags.Instance);

            if (field != null && ReflectorAttributeUtils.IsAttributeField(field))
            {
                return(ConstantValue.FromNative(ReflectionUtils.GetDefaultValue(field.ValueType.TypeCode)));
            }

            throw new ArgumentException(String.Format("The attribute does not have a writable instance field named '{0}'.", name));
        }
Exemplo n.º 5
0
 /// <inheritdoc />
 public object Resolve(bool throwOnError)
 {
     return(resolveMemoizer.Memoize(throwOnError, () =>
                                    ReflectorAttributeUtils.CreateAttribute(this, throwOnError)));
 }