static void discoverProperties(TypeData typeData, XmlDocument doc, XmlNamespaceManager nsmanager, List<TypeData> allowedTypes, List<string> allowedTypeNames, bool withNavPropertis, bool withKeys) { string typeName = typeData.Name; Console.WriteLine("Discover: " + typeName); bool hasProperty = typeData.Fields.Count != 0; string typeShortName = typeName; string typeNamespace = string.Empty; if (typeName.LastIndexOf('.') > 0) { typeNamespace = typeName.Substring(0, typeName.LastIndexOf('.')); typeShortName = typeName.Substring(typeName.LastIndexOf('.') + 1); } var schemaNode = doc.SelectSingleNode("//edmx:Schema[@Namespace = '" + typeNamespace + "']", nsmanager); if (schemaNode != null) { var typeNode = schemaNode.SelectSingleNode("edmx:EntityType[@Name = '" + typeShortName + "'] | edmx:ComplexType[@Name = '" + typeShortName + "']", nsmanager); if (typeNode != null) { allowedTypes.Add(typeData); if (!hasProperty) { var properties = typeNode.SelectNodes("edmx:Property", nsmanager); if (properties != null) { for (int j = 0; j < properties.Count; j++) { string field = properties[j].Attributes["Name"].Value; typeData.Fields.Add(field); } } if (withNavPropertis) { var navPropNodes = typeNode.SelectNodes("edmx:NavigationProperty", nsmanager); for (int j = 0; j < navPropNodes.Count; j++) { var navProp = navPropNodes[j]; string nav_name = navProp.Attributes["Name"].Value; string[] types = new string[] { navProp.Attributes["FromRole"].Value, navProp.Attributes["ToRole"].Value }; string nav_type = string.Empty; for (int t = 0; t < types.Length; t++) { var association = schemaNode.SelectSingleNode("edmx:Association/edmx:End[@Role = '" + types[t] + "']", nsmanager); if (association != null) { nav_type = association.Attributes["Type"].Value; if (nav_type != typeName || t == 1) break; } } if (allowedTypeNames.Contains(nav_type)) { typeData.Fields.Add(nav_name); } } } } else if (withKeys) { var keys = typeNode.SelectNodes("edmx:Key/edmx:PropertyRef", nsmanager); if (keys != null) { for (int j = 0; j < keys.Count; j++) { string keyField = keys[j].Attributes["Name"].Value; if (!typeData.Fields.Contains(keyField)) typeData.Fields.Insert(j, keyField); } } } } } }
static void Main(string[] args) { var options = new Options(); ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error)); if (!parser.ParseArguments(args, options)) Environment.Exit(1); Console.Write("Requesting: " + options.MetadataUri + "..."); MemoryStream documentStream = new MemoryStream(); if (options.MetadataUri.StartsWith("http")) { var r = new System.Net.WebClient(); var req = (HttpWebRequest)HttpWebRequest.Create(options.MetadataUri.Trim()); req.UserAgent = "JaySvcUtil.exe"; //req.Credentials = cred; req.PreAuthenticate = true; //req.Headers.Add("User-Agent: JaySvcUtil.exe"); if (!string.IsNullOrWhiteSpace(options.UserName)) { req.Credentials = new NetworkCredential(options.UserName, options.Password, options.Domain); } else { req.Credentials = CredentialCache.DefaultCredentials; } var res = req.GetResponse(); var resStream = res.GetResponseStream(); resStream.CopyTo(documentStream); documentStream.Position = 0; //resStream.Position = 0; //r.Credentials = cc; } else { File.OpenRead(options.MetadataUri).CopyTo(documentStream); documentStream.Position = 0; } //var metadata = r.DownloadString(options.MetadataUri.Trim()); Console.WriteLine(" done."); //// Compile the style sheet. //// Execute the XSLT transform. FileStream outputStream = new FileStream(options.OutputFileName, FileMode.Create); //MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(metadata)); XmlDocument doc = new XmlDocument(); doc.Load(documentStream); documentStream.Position = 0; var dsNode = doc.SelectSingleNode("//*[local-name() = 'DataServices']"); var schemaNode = doc.SelectSingleNode("//*[local-name() = 'Schema']"); var ns = schemaNode.NamespaceURI; var maxDSVersion = dsNode.Attributes["m:MaxDataServiceVersion"]; var version = maxDSVersion != null ? maxDSVersion.Value : ""; string metadataTypes = options.TypeFilter; if (metadataTypes == string.Empty && options.TypeFilterConfig != string.Empty) { MemoryStream configStream = new MemoryStream(); File.OpenRead(options.TypeFilterConfig).CopyTo(configStream); configStream.Position = 0; XmlDocument configDoc = new XmlDocument(); configDoc.Load(configStream); configStream.Position = 0; XslCompiledTransform configXslt = new XslCompiledTransform(Debugger.IsAttached); var _asm = Assembly.GetExecutingAssembly(); using (Stream str = _asm.GetManifestResourceStream("JaySvcUtil." + stylesheetConfig)) using (var sr = new StreamReader(str)) { configXslt.Load(new XPathDocument(sr)); } var configReader = XmlReader.Create(configStream); StringWriter sw = new StringWriter(); XmlWriter xwo = XmlWriter.Create(sw, configXslt.OutputSettings); configXslt.Transform(configReader, null, xwo); metadataTypes = sw.ToString(); } if (metadataTypes != string.Empty) { XmlNamespaceManager nsmanager = new XmlNamespaceManager(doc.NameTable); nsmanager.AddNamespace("edmx", ns); List<string> datas = metadataTypes.Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries).ToList(); List<TypeData> types = new List<TypeData>(); for (int i = 0; i < datas.Count; i++) { if (datas[i] != String.Empty) { TypeData typeData = new TypeData(datas[i]); string typeShortName = typeData.Name; string containerName = string.Empty; if (typeData.Name.LastIndexOf('.') > 0) { containerName = typeData.Name.Substring(0, typeData.Name.LastIndexOf('.')); typeShortName = typeData.Name.Substring(typeData.Name.LastIndexOf('.') + 1); } var conainers = doc.SelectNodes("//edmx:EntityContainer[@Name = '" + containerName + "']", nsmanager); for (int j = 0; j < conainers.Count; j++) { var entitySetDef = conainers[j].SelectSingleNode("edmx:EntitySet[@Name = '" + typeShortName + "']", nsmanager); if (entitySetDef != null) { typeData.Name = entitySetDef.Attributes["EntityType"].Value; break; } } types.Add(typeData); } } List<TypeData> discoveredData = null; if (options.DependentRelationsOnly) { discoveredData = DiscoverProperyDependencies(types, doc, nsmanager, options.Navigation == "true", options.GenerateKeys == "true"); } else { discoveredData = DiscoverTypeDependencies(types, doc, nsmanager, options.Navigation == "true", options.GenerateKeys == "true"); } var complex = doc.SelectNodes("//*[local-name() = 'ComplexType']"); for (int i = 0; i < complex.Count; i++) { string cns = complex[i].SelectSingleNode("../.").Attributes["Namespace"].Value; string data = cns == string.Empty ? complex[i].Attributes["Name"].Value : (cns + "." + complex[i].Attributes["Name"].Value); discoveredData.Add(new TypeData(data)); } string result = ""; for (int i = 0; i < discoveredData.Count; i++) { TypeData row = discoveredData[i]; if (row.Fields.Count > 0) { result += row.Name + ":" + string.Join(",", row.Fields) + ";"; } else { result += row.Name + ";"; } } metadataTypes = result; } //if (string.IsNullOrWhiteSpace(options.ODataVersion)) //{ options.ODataVersion = NamespaceVersions.Keys.Contains(ns) ? NamespaceVersions[ns] : "Unknown"; if (version != String.Empty) options.ODataMaxDataServiceVersion = version; else options.ODataMaxDataServiceVersion = maxNamespaceVersions.Keys.Contains(ns) ? maxNamespaceVersions[ns] : "3.0"; //} XslCompiledTransform xslt = new XslCompiledTransform(Debugger.IsAttached); if (Debugger.IsAttached) { buildDebugXslt(ns, false); xslt.Load(stylesheet); } else { xslt.Load(GetXslt(ns, false)); } Console.WriteLine("OData version: " + options.ODataVersion); var xslArg = new XsltArgumentList(); int metaIdx = options.MetadataUri.LastIndexOf("$metadata"); if (metaIdx > 0) { xslArg.AddParam("SerivceUri", "", options.MetadataUri.Substring(0, options.MetadataUri.LastIndexOf("$metadata") - 1)); } else { xslArg.AddParam("SerivceUri", "", ""); options.AutoCreateContext = false; } xslArg.AddParam("EntityBaseClass", "", options.EntityBaseClass); xslArg.AddParam("ContextBaseClass", "", options.ContextBaseClass); xslArg.AddParam("AutoCreateContext", "", options.AutoCreateContext); xslArg.AddParam("ContextInstanceName", "", options.ContextInstanceName); xslArg.AddParam("EntitySetBaseClass", "", options.EntitySetBaseClass); xslArg.AddParam("CollectionBaseClass", "", options.CollectionBaseClass); xslArg.AddParam("DefaultNamespace", "", ""); xslArg.AddParam("contextNamespace", "", options.ContextNamespace); xslArg.AddParam("MaxDataserviceVersion", "", options.ODataMaxDataServiceVersion); xslArg.AddParam("AllowedTypesList", "", metadataTypes); xslArg.AddParam("GenerateNavigationProperties", "", options.Navigation == "true"); var reader = XmlReader.Create(documentStream); xslt.Transform(reader, xslArg, outputStream); Console.WriteLine("Generating TypeScript document"); XslCompiledTransform xsltTS = new XslCompiledTransform(Debugger.IsAttached); documentStream.Position = 0; if (Debugger.IsAttached) { buildDebugXslt(ns, true); xsltTS.Load(stylesheetTS); } else { xsltTS.Load(GetXslt(ns, true)); } FileStream outputStreamTS = new FileStream(options.OutputFileName.Substring(0, options.OutputFileName.Length - 3) + ".d.ts", FileMode.Create); reader = XmlReader.Create(documentStream); xsltTS.Transform(reader, xslArg, outputStreamTS); }
static void discoverType(TypeData typeData, XmlDocument doc, XmlNamespaceManager nsmanager, List<TypeData> allowedTypes, List<string> allowedTypeNames, bool withNavPropertis, bool withKeys, bool collectTypes, List<string> collectedTypes) { string typeName = typeData.Name; if (allowedTypeNames.Contains(typeName)) { return; } Console.WriteLine("Discover: " + typeName); string typeShortName = typeName; string typeNamespace = string.Empty; if (typeName.LastIndexOf('.') > 0) { typeNamespace = typeName.Substring(0, typeName.LastIndexOf('.')); typeShortName = typeName.Substring(typeName.LastIndexOf('.') + 1); } var schemaNode = doc.SelectSingleNode("//edmx:Schema[@Namespace = '" + typeNamespace + "']", nsmanager); if (schemaNode != null) { var typeNode = schemaNode.SelectSingleNode("edmx:EntityType[@Name = '" + typeShortName + "'] | edmx:ComplexType[@Name = '" + typeShortName + "']", nsmanager); if (typeNode != null) { allowedTypes.Add(typeData); allowedTypeNames.Add(typeName); if (withKeys && typeData.Fields.Count > 0) { var keys = typeNode.SelectNodes("edmx:Key/edmx:PropertyRef", nsmanager); if (keys != null) { for (int j = 0; j < keys.Count; j++) { string keyField = keys[j].Attributes["Name"].Value; if (!typeData.Fields.Contains(keyField)) typeData.Fields.Insert(j, keyField); } } } if (withNavPropertis) { var navPropNodes = typeNode.SelectNodes("edmx:NavigationProperty", nsmanager); for (int j = 0; j < navPropNodes.Count; j++) { var navProp = navPropNodes[j]; if (typeData.Fields.Count == 0 || typeData.Fields.Contains(navProp.Attributes["Name"].Value)) { var FromRole = navProp.Attributes["FromRole"].Value; var ToRole = navProp.Attributes["ToRole"].Value; var association = schemaNode.SelectSingleNode("edmx:Association/edmx:End[@Role = '" + FromRole + "' and @Type != '" + typeName + "']", nsmanager); if (association == null) { association = schemaNode.SelectSingleNode("edmx:Association/edmx:End[@Role = '" + ToRole + "' and @Type != '" + typeName + "']", nsmanager); } if (association != null) { string nav_type = association.Attributes["Type"].Value; if (collectTypes) { if (!collectedTypes.Contains(nav_type) && !allowedTypeNames.Contains(nav_type)) collectedTypes.Add(nav_type); } else { discoverType(new TypeData(nav_type), doc, nsmanager, allowedTypes, allowedTypeNames, withNavPropertis, withKeys, false, collectedTypes); } } //else //{ // Console.WriteLine(typeName + ":" + FromRole + "/" + ToRole); //} } } } } } }
static void discoverProperties(TypeData typeData, XmlDocument doc, XmlNamespaceManager nsmanager, List <TypeData> allowedTypes, List <string> allowedTypeNames, bool withNavPropertis, bool withKeys) { string typeName = typeData.Name; Console.WriteLine("Discover: " + typeName); bool hasProperty = typeData.Fields.Count != 0; string typeShortName = typeName; string typeNamespace = string.Empty; if (typeName.LastIndexOf('.') > 0) { typeNamespace = typeName.Substring(0, typeName.LastIndexOf('.')); typeShortName = typeName.Substring(typeName.LastIndexOf('.') + 1); } var schemaNode = doc.SelectSingleNode("//edmx:Schema[@Namespace = '" + typeNamespace + "']", nsmanager); if (schemaNode != null) { var typeNode = schemaNode.SelectSingleNode("edmx:EntityType[@Name = '" + typeShortName + "'] | edmx:ComplexType[@Name = '" + typeShortName + "']", nsmanager); if (typeNode != null) { allowedTypes.Add(typeData); if (!hasProperty) { var properties = typeNode.SelectNodes("edmx:Property", nsmanager); if (properties != null) { for (int j = 0; j < properties.Count; j++) { string field = properties[j].Attributes["Name"].Value; typeData.Fields.Add(field); } } if (withNavPropertis) { var navPropNodes = typeNode.SelectNodes("edmx:NavigationProperty", nsmanager); for (int j = 0; j < navPropNodes.Count; j++) { var navProp = navPropNodes[j]; string nav_name = navProp.Attributes["Name"].Value; string[] types = new string[] { navProp.Attributes["FromRole"].Value, navProp.Attributes["ToRole"].Value }; string nav_type = string.Empty; for (int t = 0; t < types.Length; t++) { var association = schemaNode.SelectSingleNode("edmx:Association/edmx:End[@Role = '" + types[t] + "']", nsmanager); if (association != null) { nav_type = association.Attributes["Type"].Value; if (nav_type != typeName || t == 1) { break; } } } if (allowedTypeNames.Contains(nav_type)) { typeData.Fields.Add(nav_name); } } } } else if (withKeys) { var keys = typeNode.SelectNodes("edmx:Key/edmx:PropertyRef", nsmanager); if (keys != null) { for (int j = 0; j < keys.Count; j++) { string keyField = keys[j].Attributes["Name"].Value; if (!typeData.Fields.Contains(keyField)) { typeData.Fields.Insert(j, keyField); } } } } } } }
static void discoverType(TypeData typeData, XmlDocument doc, XmlNamespaceManager nsmanager, List <TypeData> allowedTypes, List <string> allowedTypeNames, bool withNavPropertis, bool withKeys, bool collectTypes, List <string> collectedTypes) { string typeName = typeData.Name; if (allowedTypeNames.Contains(typeName)) { return; } Console.WriteLine("Discover: " + typeName); string typeShortName = typeName; string typeNamespace = string.Empty; if (typeName.LastIndexOf('.') > 0) { typeNamespace = typeName.Substring(0, typeName.LastIndexOf('.')); typeShortName = typeName.Substring(typeName.LastIndexOf('.') + 1); } var schemaNode = doc.SelectSingleNode("//edmx:Schema[@Namespace = '" + typeNamespace + "']", nsmanager); if (schemaNode != null) { var typeNode = schemaNode.SelectSingleNode("edmx:EntityType[@Name = '" + typeShortName + "'] | edmx:ComplexType[@Name = '" + typeShortName + "']", nsmanager); if (typeNode != null) { allowedTypes.Add(typeData); allowedTypeNames.Add(typeName); if (withKeys && typeData.Fields.Count > 0) { var keys = typeNode.SelectNodes("edmx:Key/edmx:PropertyRef", nsmanager); if (keys != null) { for (int j = 0; j < keys.Count; j++) { string keyField = keys[j].Attributes["Name"].Value; if (!typeData.Fields.Contains(keyField)) { typeData.Fields.Insert(j, keyField); } } } } if (withNavPropertis) { var navPropNodes = typeNode.SelectNodes("edmx:NavigationProperty", nsmanager); for (int j = 0; j < navPropNodes.Count; j++) { var navProp = navPropNodes[j]; if (typeData.Fields.Count == 0 || typeData.Fields.Contains(navProp.Attributes["Name"].Value)) { var FromRole = navProp.Attributes["FromRole"].Value; var ToRole = navProp.Attributes["ToRole"].Value; var association = schemaNode.SelectSingleNode("edmx:Association/edmx:End[@Role = '" + FromRole + "' and @Type != '" + typeName + "']", nsmanager); if (association == null) { association = schemaNode.SelectSingleNode("edmx:Association/edmx:End[@Role = '" + ToRole + "' and @Type != '" + typeName + "']", nsmanager); } if (association != null) { string nav_type = association.Attributes["Type"].Value; if (collectTypes) { if (!collectedTypes.Contains(nav_type) && !allowedTypeNames.Contains(nav_type)) { collectedTypes.Add(nav_type); } } else { discoverType(new TypeData(nav_type), doc, nsmanager, allowedTypes, allowedTypeNames, withNavPropertis, withKeys, false, collectedTypes); } } //else //{ // Console.WriteLine(typeName + ":" + FromRole + "/" + ToRole); //} } } } } } }
static void Main(string[] args) { var options = new Options(); ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error)); if (!parser.ParseArguments(args, options)) { Environment.Exit(1); } Console.Write("Requesting: " + options.MetadataUri + "..."); MemoryStream documentStream = new MemoryStream(); if (options.MetadataUri.StartsWith("http")) { var r = new System.Net.WebClient(); var req = (HttpWebRequest)HttpWebRequest.Create(options.MetadataUri.Trim()); req.UserAgent = "JaySvcUtil.exe"; //req.Credentials = cred; req.PreAuthenticate = true; //req.Headers.Add("User-Agent: JaySvcUtil.exe"); if (!string.IsNullOrWhiteSpace(options.UserName)) { req.Credentials = new NetworkCredential(options.UserName, options.Password, options.Domain); } else { req.Credentials = CredentialCache.DefaultCredentials; } var res = req.GetResponse(); var resStream = res.GetResponseStream(); resStream.CopyTo(documentStream); documentStream.Position = 0; //resStream.Position = 0; //r.Credentials = cc; } else { File.OpenRead(options.MetadataUri).CopyTo(documentStream); documentStream.Position = 0; } //var metadata = r.DownloadString(options.MetadataUri.Trim()); Console.WriteLine(" done."); //// Compile the style sheet. //// Execute the XSLT transform. FileStream outputStream = new FileStream(options.OutputFileName, FileMode.Create); //MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(metadata)); XmlDocument doc = new XmlDocument(); doc.Load(documentStream); documentStream.Position = 0; var dsNode = doc.SelectSingleNode("//*[local-name() = 'DataServices']"); var schemaNode = doc.SelectSingleNode("//*[local-name() = 'Schema']"); var ns = schemaNode.NamespaceURI; var maxDSVersion = dsNode.Attributes["m:MaxDataServiceVersion"]; var version = maxDSVersion != null ? maxDSVersion.Value : ""; string metadataTypes = options.TypeFilter; if (metadataTypes == string.Empty && options.TypeFilterConfig != string.Empty) { MemoryStream configStream = new MemoryStream(); File.OpenRead(options.TypeFilterConfig).CopyTo(configStream); configStream.Position = 0; XmlDocument configDoc = new XmlDocument(); configDoc.Load(configStream); configStream.Position = 0; XslCompiledTransform configXslt = new XslCompiledTransform(Debugger.IsAttached); var _asm = Assembly.GetExecutingAssembly(); using (Stream str = _asm.GetManifestResourceStream("JaySvcUtil." + stylesheetConfig)) using (var sr = new StreamReader(str)) { configXslt.Load(new XPathDocument(sr)); } var configReader = XmlReader.Create(configStream); StringWriter sw = new StringWriter(); XmlWriter xwo = XmlWriter.Create(sw, configXslt.OutputSettings); configXslt.Transform(configReader, null, xwo); metadataTypes = sw.ToString(); } if (metadataTypes != string.Empty) { XmlNamespaceManager nsmanager = new XmlNamespaceManager(doc.NameTable); nsmanager.AddNamespace("edmx", ns); List <string> datas = metadataTypes.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList(); List <TypeData> types = new List <TypeData>(); for (int i = 0; i < datas.Count; i++) { if (datas[i] != String.Empty) { TypeData typeData = new TypeData(datas[i]); string typeShortName = typeData.Name; string containerName = string.Empty; if (typeData.Name.LastIndexOf('.') > 0) { containerName = typeData.Name.Substring(0, typeData.Name.LastIndexOf('.')); typeShortName = typeData.Name.Substring(typeData.Name.LastIndexOf('.') + 1); } var conainers = doc.SelectNodes("//edmx:EntityContainer[@Name = '" + containerName + "']", nsmanager); for (int j = 0; j < conainers.Count; j++) { var entitySetDef = conainers[j].SelectSingleNode("edmx:EntitySet[@Name = '" + typeShortName + "']", nsmanager); if (entitySetDef != null) { typeData.Name = entitySetDef.Attributes["EntityType"].Value; break; } } types.Add(typeData); } } List <TypeData> discoveredData = null; if (options.DependentRelationsOnly) { discoveredData = DiscoverProperyDependencies(types, doc, nsmanager, options.Navigation == "true", options.GenerateKeys == "true"); } else { discoveredData = DiscoverTypeDependencies(types, doc, nsmanager, options.Navigation == "true", options.GenerateKeys == "true"); } var complex = doc.SelectNodes("//*[local-name() = 'ComplexType']"); for (int i = 0; i < complex.Count; i++) { string cns = complex[i].SelectSingleNode("../.").Attributes["Namespace"].Value; string data = cns == string.Empty ? complex[i].Attributes["Name"].Value : (cns + "." + complex[i].Attributes["Name"].Value); discoveredData.Add(new TypeData(data)); } string result = ""; for (int i = 0; i < discoveredData.Count; i++) { TypeData row = discoveredData[i]; if (row.Fields.Count > 0) { result += row.Name + ":" + string.Join(",", row.Fields) + ";"; } else { result += row.Name + ";"; } } metadataTypes = result; } //if (string.IsNullOrWhiteSpace(options.ODataVersion)) //{ options.ODataVersion = NamespaceVersions.Keys.Contains(ns) ? NamespaceVersions[ns] : "Unknown"; if (version != String.Empty) { options.ODataMaxDataServiceVersion = version; } else { options.ODataMaxDataServiceVersion = maxNamespaceVersions.Keys.Contains(ns) ? maxNamespaceVersions[ns] : "3.0"; } //} XslCompiledTransform xslt = new XslCompiledTransform(Debugger.IsAttached); if (Debugger.IsAttached) { buildDebugXslt(ns, false); xslt.Load(stylesheet); } else { xslt.Load(GetXslt(ns, false)); } Console.WriteLine("OData version: " + options.ODataVersion); var xslArg = new XsltArgumentList(); int metaIdx = options.MetadataUri.LastIndexOf("$metadata"); if (metaIdx > 0) { xslArg.AddParam("SerivceUri", "", options.MetadataUri.Substring(0, options.MetadataUri.LastIndexOf("$metadata") - 1)); } else { xslArg.AddParam("SerivceUri", "", ""); options.AutoCreateContext = false; } xslArg.AddParam("EntityBaseClass", "", options.EntityBaseClass); xslArg.AddParam("ContextBaseClass", "", options.ContextBaseClass); xslArg.AddParam("AutoCreateContext", "", options.AutoCreateContext); xslArg.AddParam("ContextInstanceName", "", options.ContextInstanceName); xslArg.AddParam("EntitySetBaseClass", "", options.EntitySetBaseClass); xslArg.AddParam("CollectionBaseClass", "", options.CollectionBaseClass); xslArg.AddParam("DefaultNamespace", "", ""); xslArg.AddParam("contextNamespace", "", options.ContextNamespace); xslArg.AddParam("MaxDataserviceVersion", "", options.ODataMaxDataServiceVersion); xslArg.AddParam("AllowedTypesList", "", metadataTypes); xslArg.AddParam("GenerateNavigationProperties", "", options.Navigation == "true"); var reader = XmlReader.Create(documentStream); xslt.Transform(reader, xslArg, outputStream); Console.WriteLine("Generating TypeScript document"); XslCompiledTransform xsltTS = new XslCompiledTransform(Debugger.IsAttached); documentStream.Position = 0; if (Debugger.IsAttached) { buildDebugXslt(ns, true); xsltTS.Load(stylesheetTS); } else { xsltTS.Load(GetXslt(ns, true)); } FileStream outputStreamTS = new FileStream(options.OutputFileName.Substring(0, options.OutputFileName.Length - 3) + ".d.ts", FileMode.Create); reader = XmlReader.Create(documentStream); xsltTS.Transform(reader, xslArg, outputStreamTS); }