本文整理汇总了C#中IFileProvider.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# IFileProvider.OpenFile方法的具体用法?C# IFileProvider.OpenFile怎么用?C# IFileProvider.OpenFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileProvider
的用法示例。
在下文中一共展示了IFileProvider.OpenFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
// TODO maybe move some (or all) of this to the TemplateResolver
public static TemplateInfo Load(TemplateResolver resolver, IFileProvider source, string name)
{
string specPath = System.IO.Path.Combine(name, Template.TemplateDefinitionFileName);
if (!source.FileExists(specPath))
throw new FileNotFoundException("Couldn't find template specification: " + specPath + " from " + source.ToString(), specPath);
Dictionary<string, TemplateParameterInfo> parameters = new Dictionary<string, TemplateParameterInfo>();
TemplateInfo inheritedTemplate = null;
using (var fileStream = source.OpenFile(specPath, FileMode.Open))
{
XDocument templateSpec = XDocument.Load(fileStream);
XAttribute inheritsAttr = templateSpec.Element("template").Attribute("inherits");
if (inheritsAttr != null)
{
string inheritedTemplateName = inheritsAttr.Value;
if (!resolver.TryResolve(inheritedTemplateName, out inheritedTemplate))
throw new Exception("Failed to resolve inherted template: " + inheritedTemplateName);
// add inherited parameters
foreach (TemplateParameterInfo param in inheritedTemplate.Parameters)
parameters.Add(param.Name, param);
}
IEnumerable<XElement> parameterElements = templateSpec.XPathSelectElements("/template/parameter");
foreach (XElement parameterElement in parameterElements)
{
string paramName = parameterElement.Attribute("name").Value;
string defaultValue = ReadOptionalAttribute(parameterElement, "select");
string description = ReadOptionalAttribute(parameterElement, "description");
// add or override inherited parameter default value
parameters[paramName] = new TemplateParameterInfo(paramName, description, defaultValue);
}
}
return new TemplateInfo(source, specPath, name, parameters.Values.ToArray(), inheritedTemplate);
}
示例2: LoadStylesheet
/// <summary>
/// The load stylesheet.
/// </summary>
/// <param name="fileProvider"><see cref="IFileProvider"/> used to load the stylesheet.</param>
/// <param name="name">
/// </param>
/// <returns>
/// </returns>
private XslCompiledTransform LoadStylesheet(IFileProvider fileProvider, string name)
{
XslCompiledTransform ret = new XslCompiledTransform(true);
using (Stream str = fileProvider.OpenFile(name, FileMode.Open))
{
XmlReader reader = XmlReader.Create(str, new XmlReaderSettings { CloseInput = true, });
XsltSettings settings = new XsltSettings(false, true);
XmlResolver resolver = new XmlFileProviderResolver(fileProvider);
ret.Load(reader, settings, resolver);
}
return ret;
}