Esempio n. 1
0
        /// <summary>
        /// Create the XMLNode for the method.
        /// </summary>
        /// <param name="doc">XmlDocument used to create the XML entities; mandatory</param>
        /// <param name="fieldDescription">MethodDescription to get the information from; mandatory</param>
        /// <returns>XmlNode with the method infos</returns>
        public static XmlNode CreateMethodNode(XmlDocument doc, MethodDescription methodDescription)
        {
            if (doc == null || methodDescription == null)
            {
                throw new ArgumentNullException("Mandatory values for creating the method node are missing!");
            }

            XmlNode methodNode = doc.CreateElement("MethodDescription");

            AppendAttribute(methodNode, "MethodName", methodDescription.Name, doc);
            AppendAttribute(methodNode, "ReturnType", methodDescription.ReturnType, doc);

            IList <AnnotationInfo> annotations = methodDescription.Annotations;

            CreateAnnotationNodes(methodNode, annotations, doc);

            XmlNode modifiersRootNode = doc.CreateElement("MethodModifiers");

            methodNode.AppendChild(modifiersRootNode);

            foreach (var modifier in methodDescription.Modifiers)
            {
                XmlNode modifierNode = doc.CreateElement("MethodModifier");
                modifierNode.InnerText = modifier;
                modifiersRootNode.AppendChild(modifierNode);
            }

            XmlNode parameterTypesRootNode = doc.CreateElement("MethodParameterTypes");

            methodNode.AppendChild(parameterTypesRootNode);

            IList <String> paramTypes = methodDescription.ParameterTypes;
            IList <String> paramNames = methodDescription.ParameterNames;

            for (int i = 0; i < paramTypes.Count; i++)
            {
                String  parameterType     = paramTypes[i];
                String  parameterName     = paramNames[i];
                XmlNode parameterTypeNode = doc.CreateElement("MethodParameterType");
                parameterTypesRootNode.AppendChild(parameterTypeNode);
                parameterTypeNode.InnerText = parameterType;
                AppendAttribute(parameterTypeNode, ATTRIBUTE_NAME_NAME, parameterName, doc);
            }

            return(methodNode);
        }
Esempio n. 2
0
        /// <summary>
        /// Create a method description from the given information.
        /// </summary>
        /// <param name="methodInfo">MethodInfo to get the infos from; mandatory</param>
        /// <returns>MethodDescription</returns>
        public static MethodDescription CreateMethodDescriptionFrom(MethodInfo methodInfo)
        {
            if (methodInfo == null)
            {
                throw new ArgumentNullException("Mandatory values for creating a method description are missing!");
            }

            var            returnType     = GetReturnTypeFrom(methodInfo);
            var            modifiers      = GetModifiersFrom(methodInfo);
            IList <String> parameterTypes = new List <String>();
            IList <String> parameterNames = new List <String>();

            GetParameterInfoFrom(methodInfo, parameterTypes, parameterNames);

            MethodDescription methodDescription = new MethodDescription(methodInfo.Name, returnType, modifiers, parameterTypes, parameterNames);

            GetAnnotationInfo(methodInfo, methodDescription.Annotations);

            return(methodDescription);
        }
Esempio n. 3
0
        /// <summary>
        /// Create the "dummy" method description for delegates.
        /// </summary>
        /// <param name="methodInfos">All method infos of the delegate class; mandatory</param>
        /// <returns>Single MethodDescription for the delegate</returns>
        public static MethodDescription CreateDelegateMethodDescriptionFrom(MethodInfo[] methodInfos)
        {
            if (methodInfos == null || methodInfos.Length != 3)
            {
                throw new ArgumentNullException("Mandatory values for creating a delegate method description are missing!");
            }

            string returnType = null;
            IList <AnnotationInfo> attributes     = null;
            IList <string>         modifiers      = null;
            IList <String>         parameterTypes = null;
            IList <String>         parameterNames = null;

            foreach (var methodInfo in methodInfos)
            {
                if ("Invoke" == methodInfo.Name)
                {
                    returnType     = GetReturnTypeFrom(methodInfo);
                    parameterTypes = new List <String>();
                    parameterNames = new List <String>();
                    GetParameterInfoFrom(methodInfo, parameterTypes, parameterNames);
                    attributes = GetAnnotationInfo(methodInfo);
                }
            }

            MethodDescription methodDescription = new MethodDescription("Invoke", returnType, modifiers, parameterTypes, parameterNames);

            if (attributes != null)
            {
                IList <AnnotationInfo> annotations = methodDescription.Annotations;
                foreach (AnnotationInfo attribute in attributes)
                {
                    annotations.Add(attribute);
                }
            }
            return(methodDescription);
        }