GetXsdElementType() public static method

public static GetXsdElementType ( ParameterInfo parameter ) : string
parameter System.Reflection.ParameterInfo
return string
示例#1
0
        private void AddParameterElements(XElement complexType, ParameterInfo[] parameters, string[] requiredParameters)
        {
            XElement sequence = new XElement(_Namespace + "sequence");

            foreach (var parameter in from parameter in parameters
                     let typeName = MagickScriptTypes.GetXsdElementType(parameter)
                                    where typeName != null
                                    orderby parameter.Name
                                    select new
            {
                Name = parameter.Name,
                TypeName = typeName,
                IsRequired = requiredParameters.Contains(parameter.Name)
            })
            {
                XElement element = new XElement(_Namespace + "element",
                                                new XAttribute("name", parameter.Name));

                if (!parameter.IsRequired)
                {
                    element.Add(new XAttribute("minOccurs", "0"));
                }

                element.Add(new XAttribute("type", parameter.TypeName));

                sequence.Add(element);
            }

            if (sequence.HasElements)
            {
                complexType.Add(sequence);
            }
        }
示例#2
0
        private XElement CreateElement(PropertyInfo property)
        {
            string name = MagickScriptTypes.GetXsdName(property);

            string attributeTypeName = MagickScriptTypes.GetXsdAttributeType(property);

            if (attributeTypeName != null)
            {
                XElement complexType = new XElement(_Namespace + "complexType");
                complexType.Add(new XElement(_Namespace + "attribute",
                                             new XAttribute("name", "value"),
                                             new XAttribute("use", "required"),
                                             new XAttribute("type", attributeTypeName)));

                return(new XElement(_Namespace + "element",
                                    new XAttribute("name", name),
                                    complexType));
            }
            else
            {
                string elementTypeName = MagickScriptTypes.GetXsdElementType(property);
                if (string.IsNullOrEmpty(elementTypeName))
                {
                    throw new NotImplementedException("CreateElement: " + name);
                }

                return(new XElement(_Namespace + "element",
                                    new XAttribute("name", name),
                                    new XAttribute("type", elementTypeName)));
            }
        }
示例#3
0
        private void AddMethods(XElement element, IEnumerable <MethodBase> methods)
        {
            ParameterInfo[] parameters = (from method in methods
                                          from parameter in method.GetParameters()
                                          select parameter).ToArray();
            if (parameters.Length == 0)
            {
                element.Add(new XAttribute("type", "empty"));
                return;
            }

            if (methods.Count() == 1 && IsTypedElement(methods.First(), parameters))
            {
                string elementTypeName = MagickScriptTypes.GetXsdElementType(parameters[0]);
                if (string.IsNullOrEmpty(elementTypeName))
                {
                    throw new NotImplementedException("AddMethods: " + methods.First().Name);
                }

                element.Add(new XAttribute("type", elementTypeName));
                return;
            }

            XElement complexType = new XElement(_Namespace + "complexType");

            AddArguments(complexType, methods);

            element.Add(complexType);
        }
示例#4
0
        private void AddClassElements(XElement complexType, IEnumerable <PropertyInfo> properties, IEnumerable <MethodInfo> methods)
        {
            XElement sequence = new XElement(_Namespace + "sequence");

            foreach (var property in from property in properties
                     let typeName = MagickScriptTypes.GetXsdElementType(property)
                                    where typeName != null
                                    let name = MagickScriptTypes.GetXsdName(property)
                                               orderby name
                                               select new
            {
                Name = name,
                TypeName = typeName
            })
            {
                XElement element = new XElement(_Namespace + "element",
                                                new XAttribute("name", property.Name),
                                                new XAttribute("minOccurs", "0"));

                element.Add(new XAttribute("type", property.TypeName));

                sequence.Add(element);
            }

            if (methods.Count() > 0)
            {
                foreach (MethodBase method in methods)
                {
                    XElement element = new XElement(_Namespace + "element",
                                                    new XAttribute("name", MagickScriptTypes.GetXsdName(method)),
                                                    new XAttribute("minOccurs", "0"),
                                                    new XAttribute("maxOccurs", "unbounded"));
                    AddMethods(element, new MethodBase[] { method });
                    sequence.Add(element);
                }
            }

            if (sequence.HasElements)
            {
                complexType.Add(sequence);
            }
        }