Ejemplo n.º 1
0
        protected internal override ConstantValue[] GetAttributeConstructorArguments(StaticAttributeWrapper attribute)
        {
            var attributeHandle = (CustomAttribute)attribute.Handle;

            return(CollectionUtils.ConvertAllToArray <CustomAttributeArgument, ConstantValue>(attributeHandle.ConstructorArguments,
                                                                                              ConvertConstantValue));
        }
 /// <summary>
 /// Gets the property arguments of an attribute.
 /// </summary>
 /// <param name="attribute">The attribute, not null.</param>
 /// <returns>The property argument values.</returns>
 protected internal abstract IEnumerable<KeyValuePair<StaticPropertyWrapper, ConstantValue>> GetAttributePropertyArguments(StaticAttributeWrapper attribute);
 /// <summary>
 /// Gets the constructor arguments of an attribute.
 /// </summary>
 /// <param name="attribute">The attribute, not null.</param>
 /// <returns>The constructor argument values.</returns>
 protected internal abstract ConstantValue[] GetAttributeConstructorArguments(StaticAttributeWrapper attribute);
 /// <summary>
 /// Gets the constructor of an attribute.
 /// </summary>
 /// <param name="attribute">The attribute, not null.</param>
 /// <returns>The constructor.</returns>
 protected internal abstract StaticConstructorWrapper GetAttributeConstructor(StaticAttributeWrapper attribute);
Ejemplo n.º 5
0
 protected override IEnumerable<KeyValuePair<StaticPropertyWrapper, ConstantValue>> GetAttributePropertyArguments(StaticAttributeWrapper attribute)
 {
     IAttributeInstance attributeHandle = (IAttributeInstance)attribute.Handle;
     foreach (StaticPropertyWrapper property in attribute.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
     {
         if (ReflectorAttributeUtils.IsAttributeProperty(property))
         {
             ConstantValue? value = GetAttributeNamedParameter(attributeHandle, (IProperty) property.Handle);
             if (value.HasValue)
                 yield return new KeyValuePair<StaticPropertyWrapper, ConstantValue>(property, value.Value);
         }
     }
 }
Ejemplo n.º 6
0
 protected override IEnumerable<KeyValuePair<StaticFieldWrapper, ConstantValue>> GetAttributeFieldArguments(StaticAttributeWrapper attribute)
 {
     IAttributeInstance attributeHandle = (IAttributeInstance)attribute.Handle;
     foreach (StaticFieldWrapper field in attribute.Type.GetFields(BindingFlags.Public | BindingFlags.Instance))
     {
         if (ReflectorAttributeUtils.IsAttributeField(field))
         {
             ConstantValue? value = GetAttributeNamedParameter(attributeHandle, (IField)field.Handle);
             if (value.HasValue)
                 yield return new KeyValuePair<StaticFieldWrapper, ConstantValue>(field, value.Value);
         }
     }
 }
Ejemplo n.º 7
0
        protected override ConstantValue[] GetAttributeConstructorArguments(StaticAttributeWrapper attribute)
        {
            IAttributeInstance attributeHandle = (IAttributeInstance)attribute.Handle;

            IList<IParameter> parameters = attributeHandle.Constructor.Parameters;
            if (parameters.Count == 0)
                return EmptyArray<ConstantValue>.Instance;

            List<ConstantValue> values = new List<ConstantValue>();
            for (int i = 0; ; i++)
            {
#if RESHARPER_50_OR_NEWER
                if (i == attributeHandle.PositionParameterCount)
                    break;
#endif

                ConstantValue? value = GetAttributePositionParameter(attributeHandle, i);
                if (value.HasValue)
                    values.Add(value.Value);
                else
                    break;
            }

            int lastParameterIndex = parameters.Count - 1;
            IParameter lastParameter = parameters[lastParameterIndex];
            if (!lastParameter.IsParameterArray)
                return values.ToArray();

            // Note: When presented with a constructor that accepts a variable number of
            //       arguments, ReSharper treats them as a sequence of normal parameter
            //       values.  So we we need to map them back into a params array appropriately.                
            ConstantValue[] args = new ConstantValue[parameters.Count];
            values.CopyTo(0, args, 0, lastParameterIndex);

            int varArgsCount = values.Count - lastParameterIndex;
            ConstantValue[] varArgs = new ConstantValue[varArgsCount];

            for (int i = 0; i < varArgsCount; i++)
                varArgs[i] = values[lastParameterIndex + i];

            args[lastParameterIndex] = new ConstantValue(MakeType(lastParameter.Type), varArgs);
            return args;
        }
Ejemplo n.º 8
0
        protected override StaticConstructorWrapper GetAttributeConstructor(StaticAttributeWrapper attribute)
        {
            IAttributeInstance attributeHandle = (IAttributeInstance)attribute.Handle;
            IDeclaredType declaredTypeHandle = attributeHandle.AttributeType;
            IConstructor constructorHandle = attributeHandle.Constructor;

            return new StaticConstructorWrapper(this, constructorHandle, MakeDeclaredType(declaredTypeHandle));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Gets the property arguments of an attribute.
 /// </summary>
 /// <param name="attribute">The attribute, not null.</param>
 /// <returns>The property argument values.</returns>
 protected internal abstract IEnumerable <KeyValuePair <StaticPropertyWrapper, ConstantValue> > GetAttributePropertyArguments(StaticAttributeWrapper attribute);
Ejemplo n.º 10
0
 /// <summary>
 /// Gets the constructor arguments of an attribute.
 /// </summary>
 /// <param name="attribute">The attribute, not null.</param>
 /// <returns>The constructor argument values.</returns>
 protected internal abstract ConstantValue[] GetAttributeConstructorArguments(StaticAttributeWrapper attribute);
Ejemplo n.º 11
0
 /// <summary>
 /// Gets the constructor of an attribute.
 /// </summary>
 /// <param name="attribute">The attribute, not null.</param>
 /// <returns>The constructor.</returns>
 protected internal abstract StaticConstructorWrapper GetAttributeConstructor(StaticAttributeWrapper attribute);
Ejemplo n.º 12
0
        protected internal override IEnumerable <KeyValuePair <StaticPropertyWrapper, ConstantValue> > GetAttributePropertyArguments(StaticAttributeWrapper attribute)
        {
            var attributeHandle = (CustomAttribute)attribute.Handle;
            var declaringType   = GetAttributeType(attributeHandle);

            foreach (var entry in attributeHandle.Properties)
            {
                var propertyName = entry.Name;
                var value        = ConvertConstantValue(entry.Argument);
                var field        = (StaticPropertyWrapper)declaringType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
                yield return(new KeyValuePair <StaticPropertyWrapper, ConstantValue>(field, value));
            }
        }
Ejemplo n.º 13
0
        protected internal override StaticConstructorWrapper GetAttributeConstructor(StaticAttributeWrapper attribute)
        {
            var attributeHandle = (CustomAttribute)attribute.Handle;

            return(WrapConstructor(attributeHandle.Constructor));
        }
Ejemplo n.º 14
0
        protected internal override IEnumerable<KeyValuePair<StaticPropertyWrapper, ConstantValue>> GetAttributePropertyArguments(StaticAttributeWrapper attribute)
        {
            var attributeHandle = (CustomAttribute)attribute.Handle;
            var declaringType = GetAttributeType(attributeHandle);

            foreach (var entry in attributeHandle.Properties)
            {
                var propertyName = entry.Name;
                var value = ConvertConstantValue(entry.Argument);
                var field = (StaticPropertyWrapper)declaringType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
                yield return new KeyValuePair<StaticPropertyWrapper, ConstantValue>(field, value);
            }
        }
Ejemplo n.º 15
0
 protected internal override ConstantValue[] GetAttributeConstructorArguments(StaticAttributeWrapper attribute)
 {
     var attributeHandle = (CustomAttribute)attribute.Handle;
     return CollectionUtils.ConvertAllToArray<CustomAttributeArgument, ConstantValue>(attributeHandle.ConstructorArguments,
         ConvertConstantValue);
 }
Ejemplo n.º 16
0
 protected internal override StaticConstructorWrapper GetAttributeConstructor(StaticAttributeWrapper attribute)
 {
     var attributeHandle = (CustomAttribute)attribute.Handle;
     return WrapConstructor(attributeHandle.Constructor);
 }