Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new instance based on the specified cmdlet type.
 /// </summary>
 /// <param name="cmdletType">The type of the cmdlet. Must be a sub-class of <see cref="Cmdlet"/>
 /// and have a <see cref="CmdletAttribute"/>.</param>
 public Command(Type cmdletType)
 {
     if (cmdletType == null) throw new ArgumentNullException("cmdletType");
     CmdletType = cmdletType;
     _attribute = CmdletType.GetCustomAttribute<CmdletAttribute>();
     if (_attribute == null) throw new ArgumentException("Missing CmdletAttribute", "cmdletType");
 }
Ejemplo n.º 2
0
 public CmdletInfo(Type type, CmdletAttribute cmdlet)
     : this()
 {
     Type = type;
     Verb = cmdlet.VerbName;
     Noun = cmdlet.NounName;
 }
Ejemplo n.º 3
0
            public override void VisitCmdlet(CmdletAttribute cmdlet)
            {
                _cmdletInfo = new CmdletInfo(CurrentType, cmdlet);
                _command._cmdlets.Add(_cmdletInfo);

                base.VisitCmdlet(cmdlet);
            }
        public CmdletInfo GetCmdletByTypeName(string cmdletTypeName)
        {
            if (string.IsNullOrEmpty(cmdletTypeName))
            {
                throw PSTraceSource.NewArgumentNullException("cmdletTypeName");
            }
            Exception exception        = null;
            Type      implementingType = LanguagePrimitives.ConvertStringToType(cmdletTypeName, out exception);

            if (exception != null)
            {
                throw exception;
            }
            if (implementingType == null)
            {
                return(null);
            }
            CmdletAttribute attribute = null;

            foreach (object obj2 in implementingType.GetCustomAttributes(true))
            {
                attribute = obj2 as CmdletAttribute;
                if (attribute != null)
                {
                    break;
                }
            }
            if (attribute == null)
            {
                throw PSTraceSource.NewNotSupportedException();
            }
            string nounName = attribute.NounName;

            return(new CmdletInfo(attribute.VerbName + "-" + nounName, implementingType, null, null, this._context));
        }
Ejemplo n.º 5
0
        public void Class_HasCmdletAttribute()
        {
            // Given
            var expectedAttribute = new CmdletAttribute(VerbsCommon.Get, "Post");
            var sut = typeof(GetPostCommand);

            // When
            var result = sut.GetCustomAttributes(typeof(CmdletAttribute), false);

            // Then
            Assert.Contains(expectedAttribute, result);
        }
Ejemplo n.º 6
0
 public sealed override void VisitType(Type type)
 {
     currentCmdlet = GetAttribute<CmdletAttribute>(type, false);
     
     if (currentCmdlet != null)
     {
         try
         {
             VisitCmdlet(currentCmdlet);
             base.VisitType(type);
         }
         finally
         {
             currentCmdlet = null;
         }
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Get the cmdlet info using the name of the cmdlet's implementing type. This bypasses
        /// session state and retrieves the command directly. Note that the help file and snapin/module
        /// info will both be null on returned object.
        /// </summary>
        /// <param name="cmdletTypeName">The type name of the class implementing this cmdlet.</param>
        /// <returns>CmdletInfo for the cmdlet if found, null otherwise.</returns>
        public CmdletInfo GetCmdletByTypeName(string cmdletTypeName)
        {
            if (string.IsNullOrEmpty(cmdletTypeName))
            {
                throw PSTraceSource.NewArgumentNullException(nameof(cmdletTypeName));
            }

            Exception e          = null;
            Type      cmdletType = TypeResolver.ResolveType(cmdletTypeName, out e);

            if (e != null)
            {
                throw e;
            }

            if (cmdletType == null)
            {
                return(null);
            }

            CmdletAttribute ca = null;

            foreach (var attr in cmdletType.GetCustomAttributes(true))
            {
                ca = attr as CmdletAttribute;
                if (ca != null)
                {
                    break;
                }
            }

            if (ca == null)
            {
                throw PSTraceSource.NewNotSupportedException();
            }

            string noun       = ca.NounName;
            string verb       = ca.VerbName;
            string cmdletName = verb + "-" + noun;

            return(new CmdletInfo(cmdletName, cmdletType, null, null, _context));
        }
Ejemplo n.º 8
0
 private void ConstructCmdletMetadataUsingReflection()
 {
     if (this.CommandType.GetInterface(typeof(IDynamicParameters).Name, true) != null)
     {
         this._implementsDynamicParameters = true;
     }
     foreach (Attribute attribute in this.CommandType.GetCustomAttributes(false))
     {
         CmdletAttribute attribute2 = attribute as CmdletAttribute;
         if (attribute2 != null)
         {
             this.ProcessCmdletAttribute(attribute2);
             this.Name = attribute2.VerbName + "-" + attribute2.NounName;
         }
         else if (attribute is ObsoleteAttribute)
         {
             this._obsolete = (ObsoleteAttribute)attribute;
         }
         else
         {
             this._otherAttributes.Add(attribute);
         }
     }
 }
Ejemplo n.º 9
0
 public virtual void VisitCmdlet(CmdletAttribute cmdlet)
 {
 }
Ejemplo n.º 10
0
 private static string GetCmdletName(CmdletAttribute cmdletAttribute)
 {
     string verbName = cmdletAttribute.VerbName;
     string nounName = cmdletAttribute.NounName;
     return (verbName + "-" + nounName);
 }