Esempio n. 1
0
 protected override object NewParameter(NewCodeElementItemParams newItemParams, string path, object newValue)
 {
     return(_attribute.AddArgument(newValue.ToString(), path, newItemParams.Position));
 }
Esempio n. 2
0
        /// <summary>
        /// Fusion des paramètres d'attributs entre l'existant et les nouveaux
        /// </summary>
        /// <param name="attributeName">Name of the attribute.</param>
        /// <param name="strategyId">The strategy id.</param>
        /// <param name="multiple">if set to <c>true</c> [multiple].</param>
        /// <param name="args">The args.</param>
        public void AddAttribute(string attributeName, string strategyId, bool multiple, Dictionary <string, string> args)
        {
            Debug.Assert(attributeName != null);

            CodeAttribute2 attribute = null;

            try
            {
                if (!multiple)
                {
                    foreach (CodeElement element in GetAttributesInternal())
                    {
                        if (element.Name == attributeName)
                        {
                            attribute = element as CodeAttribute2;
                            break;
                        }
                    }
                }

                if (attribute == null)
                {
                    attribute = AddAttributeInternal(attributeName);
                }

                //            Dictionary<string, string> args = SplitArguments(value);
                int i = 0;
                foreach (CodeAttributeArgument argument in attribute.Arguments)
                {
                    string argumentName = argument.Name;
                    string key          = argumentName;

                    if (String.IsNullOrEmpty(key))
                    {
                        key = String.Format("{0}{1}", EmptyAttributeNameSig, i);
                    }
                    i++;
                    if (args.ContainsKey(key))
                    {
                        string newValue = args[key];
                        if (argument.Value != newValue)
                        {
                            argument.Value = newValue;
                        }
                        args.Remove(key);
                    }
                }
                foreach (string remainingArgumentName in args.Keys)
                {
                    attribute.AddArgument(args[remainingArgumentName],
                                          remainingArgumentName.StartsWith(EmptyAttributeNameSig)
                                              ? String.Empty
                                              : remainingArgumentName, -1);
                }

                // On enleve cette possibilité car à priori les attributs définis sur une méthode sont bien répercutés sur les méthodes
                // de surcharge
//                if (multiple)
//                    AddGeneratedAttribute(strategyId, attribute);
            }
            catch (Exception ex)
            {
                ILogger logger = ServiceLocator.Instance.GetService <ILogger>();
                if (logger != null)
                {
                    logger.WriteError("Code injection", String.Format("can add attribute {0}", attributeName), ex);
                }
            }
        }
Esempio n. 3
0
 public ShellCodeAttributeArgument AddArgument(string Value, object Name, object Position)
 {
     return(new ShellCodeAttributeArgument(_attribute.AddArgument(Value, Name, Position)));
 }