Ejemplo n.º 1
0
        /// <summary>
        /// Add a ParameterProperty to the ParameterProperty list.
        /// </summary>
        /// <param name="property"></param>
        public void AddParameterProperty(ParameterProperty property)
        {
            // These mappings will replace any mappings that this map
            // had for any of the keys currently in the specified map.
            propertiesMap[property.PropertyName] = property;
            properties.Add(property);

            if (propertiesList.Contains(property) == false)
            {
                propertiesList.Add(property);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a ParameterProperty to the ParameterProperty list.
        /// </summary>
        /// <param name="property"></param>
        public void AddParameterProperty(ParameterProperty property)
        {
            if (property.Direction == ParameterDirection.Output ||
                property.Direction == ParameterDirection.InputOutput)
            {
                HasOutputParameter = true;
            }

            // These mappings will replace any mappings that this map
            // had for any of the keys currently in the specified map.
            propertiesMap[property.PropertyName] = property;
            properties.Add(property);

            if (propertiesList.Contains(property) == false)
            {
                propertiesList.Add(property);
            }
        }
Ejemplo n.º 3
0
        //Retrieve all methods and properties decorated with ConsoleFX attributes and cache them in
        //local fields.
        private void LoadMemberMetadata()
        {
            MethodInfo[] methods = _programType.GetMethods();
            foreach (MethodInfo method in methods)
            {
                if (method.IsDefined(typeof(SwitchAttribute), true))
                {
                    CommandLine.ValidateMethodSignature(method, typeof(void), typeof(string[]));
                    object[] switchAttributes = method.GetCustomAttributes(typeof(SwitchAttribute), true);
                    foreach (SwitchAttribute switchAttribute in switchAttributes)
                    {
                        SwitchMethodInfo switchMethodInfo = new SwitchMethodInfo(method);

                        object[] groupUsageAttributes = method.GetCustomAttributes(typeof(SwitchUsageAttribute), true);
                        switchMethodInfo.ModeUsages.AddRange((SwitchUsageAttribute[])groupUsageAttributes);

                        object[] validatorAttributes = method.GetCustomAttributes(typeof(BaseValidatorAttribute), true);
                        switchMethodInfo.Validators.AddRange((BaseValidatorAttribute[])validatorAttributes);

                        _switches.Add(switchAttribute, switchMethodInfo);
                    }
                    continue;
                }

                object[] errorHandlerAttributes = method.GetCustomAttributes(typeof(ErrorHandlerAttribute), true);
                if (errorHandlerAttributes.Length > 0)
                {
                    foreach (ErrorHandlerAttribute errorHandlerAttribute in errorHandlerAttributes)
                    {
                        CommandLine.ValidateMethodSignature(method, typeof(void), typeof(Exception));
                        _errorHandlers.Add(errorHandlerAttribute, method);
                    }
                    continue;
                }

                object[] executionAttributes = method.GetCustomAttributes(typeof(ExecutionPointAttribute), true);
                if (executionAttributes.Length > 0)
                {
                    foreach (ExecutionPointAttribute executionAttribute in executionAttributes)
                    {
                        CommandLine.ValidateMethodSignature(method, typeof(int), typeof(string[]));
                        _executionPoints.Add(executionAttribute, method);
                    }
                    continue;
                }

                object[] commonValidatorAttributes = method.GetCustomAttributes(typeof(ValidatorAttribute), true);
                if (commonValidatorAttributes.Length > 0)
                {
                    CommandLine.ValidateMethodSignature(method, typeof(bool), typeof(string[]));
                    _validatorMethod = method;
                    continue;
                }

                object[] modeSetterAttribute = method.GetCustomAttributes(typeof(ModeSetterAttribute), true);
                if (modeSetterAttribute.Length > 0)
                {
                    CommandLine.ValidateMethodSignature(method, typeof(int), typeof(string[]));
                    _modeSetterMethod = method;
                    continue;
                }

                object[] usageAttributes = method.GetCustomAttributes(typeof(UsageAttribute), true);
                if (usageAttributes.Length > 0)
                {
                    CommandLine.ValidateMethodSignature(method, typeof(void));
                    _usageMethod = method;
                    continue;
                }
            }

            PropertyInfo[] properties = _programType.GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if (!property.IsDefined(typeof(ParameterPropertyAttribute), true))
                {
                    continue;
                }
                ParameterPropertyAttribute[] parameterPropertyAttributes = ReflectionHelper.GetCustomAttributes <ParameterPropertyAttribute>(property, true);
                foreach (ParameterPropertyAttribute parameterPropertyAttribute in parameterPropertyAttributes)
                {
                    Dictionary <int, ParameterPropertyInfo> subPair;
                    if (!_parameterProperties.TryGetValue(parameterPropertyAttribute.Mode, out subPair))
                    {
                        subPair = new Dictionary <int, ParameterPropertyInfo>();
                        _parameterProperties.Add(parameterPropertyAttribute.Mode, subPair);
                    }
                    if (!subPair.ContainsKey(parameterPropertyAttribute.Index))
                    {
                        ParameterPropertyInfo parameterPropertyInfo = new ParameterPropertyInfo(property);
                        parameterPropertyInfo.Validators.AddRange(ReflectionHelper.GetCustomAttributes <BaseValidatorAttribute>(property, true));
                        subPair.Add(parameterPropertyAttribute.Index, parameterPropertyInfo);
                    }
                }
            }
        }