/// <summary>
        /// Add a path parameter from a property: a [Path] property which is used to substitute a placeholder in the path
        /// </summary>
        /// <typeparam name="T">Type of the value of the path parameter</typeparam>
        /// <param name="serializationMethod">Method to use to serialize the value</param>
        /// <param name="name">Name of the name/value pair</param>
        /// <param name="value">Value of the name/value pair</param>
        /// <param name="format">Format string to use</param>
        /// <param name="urlEncode">Whether or not this path parameter should be URL-encoded</param>
        public void AddPathProperty <T>(PathSerializationMethod serializationMethod, string name, T value, string?format = null, bool urlEncode = true)
        {
            if (this._pathProperties == null)
            {
                this._pathProperties = new List <PathParameterInfo>();
            }

            this._pathProperties.Add(new PathParameterInfo <T>(name, value, format, urlEncode, serializationMethod));
        }
Esempio n. 2
0
        public void EmitAddPathParameter(ParameterModel parameter, PathSerializationMethod serializationMethod)
        {
            Assert(parameter.PathAttribute != null);
            var attribute = parameter.PathAttribute.Attribute;

            this.writer.WriteLine(this.requestInfoLocalName + ".AddPathParameter(" + EnumValue(serializationMethod) + ", " +
                                  QuoteString(parameter.PathAttributeName) + ", " + ReferenceTo(parameter) + ", " +
                                  QuoteString(attribute.Format) + ", " + (attribute.UrlEncode ? "true" : "false") + ");");
        }
Esempio n. 3
0
        public void EmitAddPathParameter(ParameterModel parameter, PathSerializationMethod serializationMethod)
        {
            Assert(parameter.PathAttribute != null);
            var pathParameter = parameter.PathAttribute.Attribute;
            var methodInfo    = MethodInfos.RequestInfo_AddPathParameter.MakeGenericMethod(parameter.ParameterInfo.ParameterType);

            this.ilGenerator.Emit(OpCodes.Ldloc, this.requestInfoLocal);
            this.ilGenerator.Emit(OpCodes.Ldc_I4, (int)serializationMethod);
            this.ilGenerator.Emit(OpCodes.Ldstr, parameter.PathAttributeName);
            this.ilGenerator.Emit(OpCodes.Ldarg, (short)parameter.ParameterInfo.Position + 1);
            this.LoadString(pathParameter.Format);
            this.ilGenerator.Emit(pathParameter.UrlEncode ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
            this.ilGenerator.Emit(OpCodes.Callvirt, methodInfo);
        }
Esempio n. 4
0
        public void EmitAddPathProperty(EmittedProperty property, PathSerializationMethod serializationMethod)
        {
            Assert(property.PropertyModel.PathAttribute != null);
            var attribute   = property.PropertyModel.PathAttribute.Attribute;
            var typedMethod = MethodInfos.RequestInfo_AddPathProperty.MakeGenericMethod(property.FieldBuilder.FieldType);

            this.ilGenerator.Emit(OpCodes.Ldloc, this.requestInfoLocal);
            this.ilGenerator.Emit(OpCodes.Ldc_I4, (int)serializationMethod);
            this.ilGenerator.Emit(OpCodes.Ldstr, property.PropertyModel.PathAttributeName);
            this.ilGenerator.Emit(OpCodes.Ldarg_0);
            this.ilGenerator.Emit(OpCodes.Ldfld, property.FieldBuilder);
            this.LoadString(attribute.Format);
            this.ilGenerator.Emit(attribute.UrlEncode ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
            this.ilGenerator.Emit(OpCodes.Callvirt, typedMethod);
        }
Esempio n. 5
0
        public PathSerializationMethod ResolvePath(PathSerializationMethod parameterMethod)
        {
            if (parameterMethod != PathSerializationMethod.Default)
            {
                return(parameterMethod);
            }

            if (this.MethodAttribute != null && this.MethodAttribute.Path != PathSerializationMethod.Default)
            {
                return(this.MethodAttribute.Path);
            }

            if (this.ClassAttribute != null && this.ClassAttribute.Path != PathSerializationMethod.Default)
            {
                return(this.ClassAttribute.Path);
            }

            return(DefaultPathSerializationMethod);
        }
Esempio n. 6
0
 /// <summary>
 /// Initialises a new instance of the <see cref="PathAttribute"/> class, with the given name and serialization method
 /// </summary>
 /// <param name="name">Placeholder in the path to replace</param>
 /// <param name="serializationMethod">Serialization method to use to serialize the value</param>
 public PathAttribute(string name, PathSerializationMethod serializationMethod)
 {
     this.Name = name;
     this.SerializationMethod = serializationMethod;
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PathAttribute"/> class, with the given serialization method
 /// </summary>
 /// <param name="serializationMethod">Serialization method to use to serialize the value</param>
 public PathAttribute(PathSerializationMethod serializationMethod)
 {
     // Don't set this.Name
     this.SerializationMethod = serializationMethod;
 }
Esempio n. 8
0
 /// <summary>
 /// Initialises a new instance of the <see cref="SerializationMethodsAttribute"/> class
 /// </summary>
 public SerializationMethodsAttribute()
 {
     this.Body  = BodySerializationMethod.Default;
     this.Query = QuerySerializationMethod.Default;
     this.Path  = PathSerializationMethod.Default;
 }