Esempio n. 1
0
        public static CompoundParameterContext Register(
            [NotNull] DynamicParameterContext parentContext,
            [NotNull] MemberInfo compoundParameterMember,
            [NotNull] ICompoundParameter compoundParameterValue)
        {
            if (parentContext is null)
            {
                throw new ArgumentNullException(nameof(parentContext));
            }

            if (compoundParameterMember is null)
            {
                throw new ArgumentNullException(nameof(compoundParameterMember));
            }

            if (compoundParameterValue is null)
            {
                throw new ArgumentNullException(nameof(compoundParameterValue));
            }

            var context = _contexts.GetValue(
                compoundParameterValue,
                _ => new CompoundParameterContext(parentContext, compoundParameterMember));

            return(context);
        }
Esempio n. 2
0
 private CompoundParameterContext(
     [NotNull] DynamicParameterContext parentContext,
     [NotNull] MemberInfo compoundParameterMember)
 {
     this._parentContext   = parentContext;
     this.CurrentParameter = compoundParameterMember;
 }
        internal DynamicParameterInstance(
            [NotNull] DynamicParameterContext context,
            [NotNull] DynamicParameterDescriptor descriptor)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (descriptor is null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            this.Context             = context;
            this.ParameterDescriptor = descriptor;
        }
Esempio n. 4
0
        public static void SetParameterInterceptor <TCmdlet>(
            [NotNull] this TCmdlet cmdlet,
            [NotNull] IParameterInterceptor interceptor)
            where TCmdlet : Cmdlet
        {
            if (cmdlet is null)
            {
                throw new ArgumentNullException(nameof(cmdlet));
            }

            if (interceptor is null)
            {
                throw new ArgumentNullException(nameof(interceptor));
            }

            var context = DynamicParameterContext.GetContext(cmdlet);

            context.SetParameterInterceptor(interceptor);
        }
Esempio n. 5
0
        public static DynamicParameterInstance EnableDynamicParameter <TCmdlet>(
            [NotNull] this TCmdlet cmdlet,
            [NotNull] DynamicParameterDescriptor parameterDescriptor)
            where TCmdlet : Cmdlet
        {
            if (cmdlet is null)
            {
                throw new ArgumentNullException(nameof(cmdlet));
            }

            if (parameterDescriptor is null)
            {
                throw new ArgumentNullException(nameof(parameterDescriptor));
            }

            var context  = DynamicParameterContext.GetContext(cmdlet);
            var instance = context.EnableParameter(parameterDescriptor);

            return(instance);
        }
Esempio n. 6
0
        public static object GetDynamicParameterObject <TCmdlet>(
            [NotNull] this TCmdlet cmdlet,
            [NotNull] IDynamicParameterObjectBuilder factory)
            where  TCmdlet : Cmdlet
        {
            if (cmdlet is null)
            {
                throw new ArgumentNullException(nameof(cmdlet));
            }

            if (factory is null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

            var context = DynamicParameterContext.GetContext(cmdlet);

            var dynamicParameterObject = context.GetDynamicParameterObject(factory);

            return(dynamicParameterObject);
        }
Esempio n. 7
0
        public static void PopulateRuntimeDefinedParameterValues <TCmdlet>(
            [NotNull] this TCmdlet cmdlet,
            [NotNull] RuntimeDefinedParameterDictionary runtimeDefinedParameters)
            where TCmdlet : Cmdlet
        {
            if (cmdlet is null)
            {
                throw new ArgumentNullException(nameof(cmdlet));
            }

            if (runtimeDefinedParameters is null)
            {
                throw new ArgumentNullException(nameof(runtimeDefinedParameters));
            }

            var context = DynamicParameterContext.GetContext(cmdlet);

            foreach (var parameter in runtimeDefinedParameters.Values)
            {
                context.SetParameterValue(parameter.Name, parameter.Value);
            }
        }
Esempio n. 8
0
        public static bool TryGetParameter <TCmdlet>(
            [NotNull] this TCmdlet cmdlet,
            [NotNull] string parameterName,
            [NotNull] out DynamicParameterInstance parameter)
            where  TCmdlet : Cmdlet
        {
            if (cmdlet is null)
            {
                throw new ArgumentNullException(nameof(cmdlet));
            }

            if (parameterName is null)
            {
                throw new ArgumentNullException(nameof(parameterName));
            }

            var context = DynamicParameterContext.GetContext(cmdlet);

            bool enabled = context.TryGetParameter(parameterName, out parameter);

            return(enabled);
        }