Example #1
0
        /// <summary>
        /// Populates the high level metadata properties
        /// </summary>
        /// <param name="il">The IL Generator</param>
        /// <param name="metadataLocal"> The metadata local. </param>
        /// <param name="interfaceMethod"> The interface method. </param>
        private static void PopulateMetadata(ILGenerator il, LocalBuilder metadataLocal, MethodInfo interfaceMethod)
        {
            HttpVerb verb = ReflectionUtils.DetermineHttpVerb(interfaceMethod);

            string consumeMediaType  = ReflectionUtils.DetermineConsumesMediaType(interfaceMethod, MediaType.TextXml);
            string producesMediaType = ReflectionUtils.DetermineProducesMediaType(interfaceMethod, MediaType.TextXml);

            PathAttribute methodPathAttr  = ReflectionUtils.GetAttribute <PathAttribute>(interfaceMethod);
            PathAttribute servicePathAttr = ReflectionUtils.GetAttribute <PathAttribute>(interfaceMethod.DeclaringType);

            string methodPath  = methodPathAttr == null ? "/" : methodPathAttr.Path;
            string servicePath = servicePathAttr == null ? string.Empty : servicePathAttr.Path;

            Type methodMetaType = typeof(MethodMetadata);

            ILWriter.WritePropertyString(il, metadataLocal, methodMetaType, "ServicePath", servicePath);
            ILWriter.WritePropertyString(il, metadataLocal, methodMetaType, "MethodPath", methodPath);
            ILWriter.WritePropertyString(il, metadataLocal, methodMetaType, "Consumes", consumeMediaType);
            ILWriter.WritePropertyString(il, metadataLocal, methodMetaType, "Produces", producesMediaType);
            ILWriter.WritePropertyInt(il, metadataLocal, methodMetaType, "Verb", (int)verb);
        }