protected internal override object GetParameterValue( IDynamicParameterContext context) { var value = this.GetValueAccessor(context); return(value); }
protected internal override void SetParameterValue( IDynamicParameterContext context, object value) { if (context is null) { throw new ArgumentNullException(nameof(context)); } this._setValueAccessor(context.Cmdlet, value); }
protected internal override object GetParameterValue( IDynamicParameterContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } var value = this._getValueAccessor(context.Cmdlet); return(value); }
public object GetDynamicParameterObject( IDynamicParameterContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } var parameters = context.GetParameters(); string descriptorIds = string.Join("_", parameters.Select(x => x.ParameterDescriptor.Id).OrderBy(x => x)); string proxyTypeName = $"DynamicProxy_{descriptorIds}"; if (!_constructorCache.TryGetValue(proxyTypeName, out var constructor)) { _constructorCache[proxyTypeName] = constructor = CreateProxyType(proxyTypeName, context); } var proxyObject = constructor(context); return(proxyObject); }
private static Func <IDynamicParameterContext, object> CreateProxyType( [NotNull] string proxyTypeName, [NotNull] IDynamicParameterContext context) { const TypeAttributes typeAttributes = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed; const FieldAttributes fieldAttributes = FieldAttributes.InitOnly | FieldAttributes.Private; var typeBuilder = _moduleBuilder.DefineType( proxyTypeName, typeAttributes); var contextFieldBuilder = typeBuilder.DefineField( "_context", typeof(DynamicParameterContext), fieldAttributes); GenerateConstructor(typeBuilder, contextFieldBuilder); foreach (var parameter in context.GetParameters()) { AddParameter( typeBuilder, parameter.ParameterDescriptor, contextFieldBuilder); } var generatedType = typeBuilder.CreateTypeInfo(); var constructorDelegate = GetConstructorDelegate(generatedType); return(constructorDelegate); }
public object GetDynamicParameterObject( IDynamicParameterContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } var rdpd = new RuntimeDefinedParameterDictionary(); foreach (var parameter in context.GetParameters()) { var descriptor = parameter.ParameterDescriptor; var attributes = new Collection <Attribute>(); foreach (var attributeData in descriptor.Attributes) { attributes.Add((Attribute)attributeData.GetInstance()); } var rdp = new RuntimeDefinedParameter( descriptor.ParameterName, descriptor.ParameterType, attributes); if (parameter.IsSet) { rdp.Value = parameter.Value; } rdpd.Add(descriptor.ParameterName, rdp); } return(rdpd); }
protected internal override void SetParameterValue( IDynamicParameterContext context, object value) { this.SetValueAccessor(context, value); }
protected internal abstract void SetParameterValue( [NotNull] IDynamicParameterContext context, [CanBeNull] object value);
protected internal abstract object GetParameterValue( [NotNull] IDynamicParameterContext context);
public void SetValue( IDynamicParameterContext context, DynamicParameterDescriptor descriptor, ref object value) { }