Beispiel #1
0
        private XmlSchemaObject MakePluginFacet(PluginAttribute pluginAttribute, Type type)
        {
            var facet = new XmlSchemaEnumerationFacet();

            facet.Value = pluginAttribute.Name;

            // Lame: For actions, everyone expects title case (SetProperty) but
            // the schema expects camel case (setProperty).
            if (pluginAttribute.Type == typeof(Peach.Core.Dom.Action))
            {
                facet.Value = Char.ToLowerInvariant(facet.Value[0]) + facet.Value.Substring(1);
            }

            var descAttr = type.GetAttributes <DescriptionAttribute>().FirstOrDefault();

            if (descAttr != null)
            {
                facet.Annotate(descAttr.Description);
            }
            else
            {
                facet.Annotate(type);
            }

            return(facet);
        }
Beispiel #2
0
        XmlSchemaSimpleType GetEnumType(Type type)
        {
            XmlSchemaSimpleType ret;

            if (enumTypeCache.TryGetValue(type, out ret))
            {
                return(ret);
            }

            var content = new XmlSchemaSimpleTypeRestriction()
            {
                BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace),
            };

            foreach (var item in type.GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                var attr = item.GetAttributes <XmlEnumAttribute>().FirstOrDefault();

                var facet = new XmlSchemaEnumerationFacet();
                facet.Value = attr != null ? attr.Name : item.Name;
                facet.Annotate(item);

                content.Facets.Add(facet);
            }

            ret = new XmlSchemaSimpleType()
            {
                Content = content,
            };

            enumTypeCache.Add(type, ret);

            return(ret);
        }