Пример #1
0
        protected static void DoOdataVocabulariesMethod(
            StringBuilder sb,
            string mainNamespaceName,
            string subNamespace,
            string className,
            PropertyInfoBase[] properties,
            PropertyInfoBase[] baseClassProperties)
        {
            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// Gets the CDSL that defines the OData Vocabularies for this class");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine(
                "        public static " + (baseClassProperties != null ? "new " : string.Empty)
                + "System.Xml.XmlReader GetOdataVocabularies()");
            sb.AppendLine("        {");

            string fullNamespace = mainNamespaceName
                                   + (!string.IsNullOrWhiteSpace(subNamespace) ? "." + subNamespace : null);

            foreach (PropertyInfoBase property in properties)
            {
                sb.AppendLine("            // " + property.Name);
                sb.AppendLine(string.Empty);
            }

            sb.AppendLine("        var schema = new XElement(");
            sb.AppendLine("            \"Schema\",");
            sb.AppendLine("            new XAttribute(\"Namespace\", \"" + fullNamespace + "\"),");
            sb.AppendLine("            new XAttribute(\"xmlns\", \"http://schemas.microsoft.com/ado/2009/11/edm\"),");
            sb.AppendLine("            // using directive");
            sb.AppendLine("            new XElement(");
            sb.AppendLine("                \"Using\",");
            sb.AppendLine("                new XAttribute(\"Namespace\", \"Org.OData.Validation.V1\"),");
            sb.AppendLine("                new XAttribute(\"Alias\", \"Validation\"),");

            string fullClassName = fullNamespace + "." + className;
            if (baseClassProperties != null && baseClassProperties.Any())
            {
                for (int position = 0; position < baseClassProperties.Count() - 1; position++)
                {
                    sb.AppendLine("                new XElement(\"Annotations\",");
                    sb.AppendLine(
                        "                    new XAttribute(\"Target\", \"" + fullClassName + "/"
                        + baseClassProperties[position].Name + "\")),");
                }

                sb.AppendLine("                new XElement(");
                sb.AppendLine("                    \"Annotations\",");
                sb.AppendLine(
                    "                    new XAttribute(\"Target\", \"" + fullClassName + "/"
                    + baseClassProperties[baseClassProperties.Count() - 1].Name + "\")),");
            }

            for (int position = 0; position < properties.Count() - 1; position++)
            {
                sb.AppendLine("                new XElement(");
                sb.AppendLine("                    \"Annotations\",");
                sb.AppendLine(
                    "                    new XAttribute(\"Target\", \"" + fullClassName + "/"
                    + properties[position].Name + "\")),");
            }

            sb.AppendLine("                new XElement(");
            sb.AppendLine("                    \"Annotations\",");
            sb.AppendLine(
                "                    new XAttribute(\"Target\", \"" + fullClassName + "/"
                + properties[properties.Count() - 1].Name + "\"))));");
            sb.AppendLine(string.Empty);
            sb.AppendLine("        Debug.Assert(schema.Document != null, \"schema.Document != null\");");
            sb.AppendLine("        return schema.Document.CreateReader();");
            sb.AppendLine("        }");
        }