示例#1
0
        public void EmitRequestInfoCreation(RequestAttributeBase requestAttribute)
        {
            this.ilGenerator.Emit(OpCodes.Ldarg_0);
            this.ilGenerator.Emit(OpCodes.Ldfld, this.requesterField);

            // For the standard HTTP methods, we can get a static instance. For others, we'll need to construct the HttpMethod
            // ourselves
            if (MethodInfos.HttpMethodProperties.TryGetValue(requestAttribute.Method, out PropertyInfo cachedPropertyInfo))
            {
                this.ilGenerator.Emit(OpCodes.Call, cachedPropertyInfo.GetMethod);
            }
            else
            {
                this.ilGenerator.Emit(OpCodes.Ldstr, requestAttribute.Method.Method);
                this.ilGenerator.Emit(OpCodes.Newobj, MethodInfos.HttpMethod_Ctor_String);
            }
            this.ilGenerator.Emit(OpCodes.Ldstr, requestAttribute.Path ?? string.Empty);
            this.ilGenerator.Emit(OpCodes.Ldsfld, this.methodInfoField);
            this.ilGenerator.Emit(OpCodes.Newobj, MethodInfos.RequestInfo_Ctor);
            this.ilGenerator.Emit(OpCodes.Stloc, this.requestInfoLocal);

            if (this.classHeadersField != null)
            {
                this.ilGenerator.Emit(OpCodes.Ldloc, this.requestInfoLocal);
                this.ilGenerator.Emit(OpCodes.Ldsfld, this.classHeadersField);
                this.ilGenerator.Emit(OpCodes.Callvirt, MethodInfos.RequestInfo_ClassHeaders_Set);
            }
        }
示例#2
0
        public void EmitRequestInfoCreation(RequestAttributeBase requestAttribute)
        {
            this.writer.Write("var " + this.requestInfoLocalName + " = new global::RestEase.Implementation.RequestInfo(");
            if (WellKnownNames.HttpMethodProperties.TryGetValue(requestAttribute.Method, out string httpMethod))
            {
                this.writer.Write(httpMethod);
            }
            else
            {
                this.writer.Write("new global::System.Net.Http.HttpMethod(" + requestAttribute.Method.Method + ")");
            }
            this.writer.Write(", " + QuoteString(requestAttribute.Path ?? string.Empty));
            if (this.methodInfoFieldName != null)
            {
                this.writer.Write(", " + this.qualifiedTypeName + "." + this.methodInfoFieldName);
            }
            else
            {
                this.writer.Write(", null");
            }
            this.writer.WriteLine(");");

            if (this.classHeadersFieldName != null)
            {
                this.writer.WriteLine(this.requestInfoLocalName + ".ClassHeaders = " + this.qualifiedTypeName + "." +
                                      this.classHeadersFieldName + ";");
            }
        }