本文整理匯總了C#中System.Xml.Linq.XElement.ElementsNoNamespace方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.ElementsNoNamespace方法的具體用法?C# XElement.ElementsNoNamespace怎麽用?C# XElement.ElementsNoNamespace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.ElementsNoNamespace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetPackages
private IEnumerable<VsTemplateWizardPackageInfo> GetPackages(XElement packagesElement)
{
var declarations = (from packageElement in packagesElement.ElementsNoNamespace("package")
let id = packageElement.GetOptionalAttributeValue("id")
let version = packageElement.GetOptionalAttributeValue("version")
let skipAssemblyReferences = packageElement.GetOptionalAttributeValue("skipAssemblyReferences")
select new { id, version, skipAssemblyReferences }).ToList();
SemanticVersion semVer;
bool skipAssemblyReferencesValue;
var missingOrInvalidAttributes = from declaration in declarations
where
String.IsNullOrWhiteSpace(declaration.id) ||
String.IsNullOrWhiteSpace(declaration.version) ||
!SemanticVersion.TryParse(declaration.version, out semVer) ||
(declaration.skipAssemblyReferences != null &&
!Boolean.TryParse(declaration.skipAssemblyReferences, out skipAssemblyReferencesValue))
select declaration;
if (missingOrInvalidAttributes.Any())
{
ShowErrorMessage(
VsResources.TemplateWizard_InvalidPackageElementAttributes);
throw new WizardBackoutException();
}
return from declaration in declarations
select new VsTemplateWizardPackageInfo(
declaration.id,
declaration.version,
declaration.skipAssemblyReferences != null && Boolean.Parse(declaration.skipAssemblyReferences)
);
}
示例2: ReadDependencies
private static List<ManifestDependency> ReadDependencies(XElement containerElement)
{
// element is <dependency>
return (from element in containerElement.ElementsNoNamespace("dependency")
select new ManifestDependency
{
Id = element.GetOptionalAttributeValue("id").SafeTrim(),
Version = element.GetOptionalAttributeValue("version").SafeTrim()
}).ToList();
}
示例3: ReadDependencies
private static List<ManifestDependency> ReadDependencies(XElement containerElement)
{
// element is <dependency>
return (from element in containerElement.ElementsNoNamespace("dependency")
let idElement = element.Attribute("id")
where idElement != null && !String.IsNullOrEmpty(idElement.Value)
select new ManifestDependency
{
Id = idElement.Value.SafeTrim(),
Version = element.GetOptionalAttributeValue("version").SafeTrim()
}).ToList();
}
示例4: ReadDependencySets
private static List<ManifestDependencySet> ReadDependencySets(XElement dependenciesElement)
{
if (!dependenciesElement.HasElements)
{
return new List<ManifestDependencySet>();
}
// Disallow the <dependencies> element to contain both <dependency> and
// <group> child elements. Unfortunately, this cannot be enforced by XSD.
if (dependenciesElement.ElementsNoNamespace("dependency").Any() &&
dependenciesElement.ElementsNoNamespace("group").Any())
{
throw new InvalidDataException(NuGetResources.Manifest_DependenciesHasMixedElements);
}
var dependencies = ReadDependencies(dependenciesElement);
if (dependencies.Count > 0)
{
// old format, <dependency> is direct child of <dependencies>
var dependencySet = new ManifestDependencySet
{
Dependencies = dependencies
};
return new List<ManifestDependencySet> { dependencySet };
}
else
{
var groups = dependenciesElement.ElementsNoNamespace("group");
return (from element in groups
select new ManifestDependencySet
{
TargetFramework = element.GetOptionalAttributeValue("targetFramework").SafeTrim(),
Dependencies = ReadDependencies(element)
}).ToList();
}
}
示例5: ReadReference
public static List<ManifestReference> ReadReference(XElement referenceElement, bool throwIfEmpty)
{
var references = (from element in referenceElement.ElementsNoNamespace("reference")
let fileAttribute = element.Attribute("file")
where fileAttribute != null && !String.IsNullOrEmpty(fileAttribute.Value)
select new ManifestReference { File = fileAttribute.Value.SafeTrim() }
).ToList();
if (throwIfEmpty && references.Count == 0)
{
throw new InvalidDataException(NuGetResources.Manifest_ReferencesIsEmpty);
}
return references;
}
示例6: ReadDependencyList
/// <summary>
/// Parse dependencies from the xelement and returns a list of PackageDependencySet
/// </summary>
/// <param name="dependenciesElement"></param>
/// <returns></returns>
private static List<PackageDependencySet> ReadDependencyList(XElement dependenciesElement)
{
// No elements so return empty list
if (!dependenciesElement.HasElements)
{
return new List<PackageDependencySet>();
}
// Direct child of dependenciesElement with tag <group>
var groups = dependenciesElement.ElementsNoNamespace("group");
// It is an error for <dependencies> element to contain both <dependency> and <group> child elements
if (dependenciesElement.ElementsNoNamespace("dependency").Any() && groups.Any())
{
throw new InvalidDataException(Messages.DependencyHasBothElements);
}
var dependencies = ReadDependencies(dependenciesElement);
if (!groups.Any())
{
// since there is no group, we are encoutering
// old format, <dependency> is direct child of <dependencies>
var dependencySet = new PackageDependencySet
{
Dependencies = dependencies
};
return new List<PackageDependencySet> { dependencySet };
}
else
{
// new format, with <group> as child of <dependencies>
// Project each group into a packagedependencyset
return groups.Select(group =>
new PackageDependencySet {
TargetFramework = group.GetOptionalAttributeValue("targetFramework").SafeTrim(),
Dependencies = ReadDependencies(group)
}).ToList();
}
}
示例7: ReadContentFiles
private static List<ManifestContentFiles> ReadContentFiles(XElement contentFilesElement)
{
if (!contentFilesElement.HasElements)
{
return new List<ManifestContentFiles>(0);
}
var contentFileSets = (from element in contentFilesElement.ElementsNoNamespace("files")
let includeAttribute = element.Attribute("include")
where includeAttribute != null && !string.IsNullOrEmpty(includeAttribute.Value)
let excludeAttribute = element.Attribute("exclude")
let buildActionAttribute = element.Attribute("buildAction")
let copyToOutputAttribute = element.Attribute("copyToOutput")
let flattenAttribute = element.Attribute("flatten")
select new ManifestContentFiles
{
Include = includeAttribute.Value?.Trim(),
Exclude = excludeAttribute == null ? null : excludeAttribute.Value,
BuildAction = buildActionAttribute == null ? null : buildActionAttribute.Value,
CopyToOutput = copyToOutputAttribute == null ? null : copyToOutputAttribute.Value,
Flatten = flattenAttribute == null ? null : flattenAttribute.Value
}).ToList();
return contentFileSets;
}
示例8: ReadFrameworkAssemblies
private static List<ManifestFrameworkAssembly> ReadFrameworkAssemblies(XElement frameworkElement)
{
if (!frameworkElement.HasElements)
{
return new List<ManifestFrameworkAssembly>(0);
}
return (from element in frameworkElement.ElementsNoNamespace("frameworkAssembly")
let assemblyNameAttribute = element.Attribute("assemblyName")
where assemblyNameAttribute != null && !String.IsNullOrEmpty(assemblyNameAttribute.Value)
select new ManifestFrameworkAssembly
{
AssemblyName = assemblyNameAttribute.Value.SafeTrim(),
TargetFramework = element.GetOptionalAttributeValue("targetFramework").SafeTrim()
}).ToList();
}
示例9: ReadReferenceSets
private static List<ManifestReferenceSet> ReadReferenceSets(XElement referencesElement)
{
if (!referencesElement.HasElements)
{
return new List<ManifestReferenceSet>(0);
}
if (referencesElement.ElementsNoNamespace("group").Any() &&
referencesElement.ElementsNoNamespace("reference").Any())
{
throw new InvalidDataException(NuGetResources.Manifest_ReferencesHasMixedElements);
}
var references = ReadReference(referencesElement, throwIfEmpty: false);
if (references.Count > 0)
{
// old format, <reference> is direct child of <references>
var referenceSet = new ManifestReferenceSet
{
References = references
};
return new List<ManifestReferenceSet> { referenceSet };
}
else
{
var groups = referencesElement.ElementsNoNamespace("group");
return (from element in groups
select new ManifestReferenceSet
{
TargetFramework = element.GetOptionalAttributeValue("targetFramework").SafeTrim(),
References = ReadReference(element, throwIfEmpty: true)
}).ToList();
}
}
示例10: ReadReference
private static List<ManifestReference> ReadReference(XElement referenceElement, bool throwIfEmpty)
{
var references =
(from element in referenceElement.ElementsNoNamespace("reference")
select new ManifestReference { File = element.GetOptionalAttributeValue("file").SafeTrim() }
).ToList();
if (throwIfEmpty && references.Count == 0)
{
throw new InvalidDataException(NuGetResources.Manifest_ReferencesIsEmpty);
}
return references;
}
示例11: ReadFilesList
private static List<ManifestFile> ReadFilesList(XElement xElement)
{
if (xElement == null)
{
return null;
}
List<ManifestFile> files = new List<ManifestFile>();
foreach (var file in xElement.ElementsNoNamespace("file"))
{
var srcElement = file.Attribute("src");
if (srcElement == null || String.IsNullOrEmpty(srcElement.Value))
{
continue;
}
string target = file.GetOptionalAttributeValue("target").SafeTrim();
string exclude = file.GetOptionalAttributeValue("exclude").SafeTrim();
// Multiple sources can be specified by using semi-colon separated values.
files.AddRange(from source in srcElement.Value.Trim(';').Split(';')
select new ManifestFile { Source = source.SafeTrim(), Target = target.SafeTrim(), Exclude = exclude.SafeTrim() });
}
return files;
}
示例12: ReadDependencies
/// <summary>
/// Read the dependencies from xelement. Returns a list of dependencies
/// </summary>
/// <param name="containerElement"></param>
/// <returns></returns>
private static List<PackageDependency> ReadDependencies(XElement containerElement)
{
// list of dependency
var dependencies = containerElement.ElementsNoNamespace("dependency");
return (from element in containerElement.ElementsNoNamespace("dependency")
let idElement = element.Attribute("id")
// Check that id is not null or empty
where idElement != null && !String.IsNullOrEmpty(idElement.Value)
// Project a PackageDependency based on that
select new PackageDependency
{
Id = idElement.Value.SafeTrim(),
DependencyVersion = DependencyVersion.ParseDependencyVersion(element.GetOptionalAttributeValue("version").SafeTrim())
}).ToList();
}
示例13: GetPackages
private IEnumerable<PreinstalledPackageInfo> GetPackages(XElement packagesElement)
{
var declarations = (from packageElement in packagesElement.ElementsNoNamespace("package")
let id = packageElement.GetOptionalAttributeValue("id")
let version = packageElement.GetOptionalAttributeValue("version")
let skipAssemblyReferences = packageElement.GetOptionalAttributeValue("skipAssemblyReferences")
let includeDependencies = packageElement.GetOptionalAttributeValue("includeDependencies")
select new { id, version, skipAssemblyReferences, includeDependencies }).ToList();
NuGetVersion semVer = null;
bool skipAssemblyReferencesValue;
bool includeDependenciesValue;
var missingOrInvalidAttributes = from declaration in declarations
where
String.IsNullOrWhiteSpace(declaration.id) ||
String.IsNullOrWhiteSpace(declaration.version) ||
!NuGetVersion.TryParse(declaration.version, out semVer) ||
(declaration.skipAssemblyReferences != null &&
!Boolean.TryParse(declaration.skipAssemblyReferences, out skipAssemblyReferencesValue)) ||
(declaration.includeDependencies != null &&
!Boolean.TryParse(declaration.includeDependencies, out includeDependenciesValue))
select declaration;
if (missingOrInvalidAttributes.Any())
{
ShowErrorMessage(
VsResources.TemplateWizard_InvalidPackageElementAttributes);
throw new WizardBackoutException();
}
return from declaration in declarations
select new PreinstalledPackageInfo(
declaration.id,
declaration.version,
skipAssemblyReferences: declaration.skipAssemblyReferences != null && Boolean.Parse(declaration.skipAssemblyReferences),
// Note that the declaration uses "includeDependencies" but we need to invert it to become ignoreDependencies
// The declaration uses includeDependencies so that the default value can be 'false'
ignoreDependencies: !(declaration.includeDependencies != null && Boolean.Parse(declaration.includeDependencies))
);
}
示例14: ReadDependencies
private static List<PackageDependency> ReadDependencies(XElement containerElement)
{
// element is <dependency>
return (from element in containerElement.ElementsNoNamespace("dependency")
let idElement = element.Attribute("id")
where idElement != null && !string.IsNullOrEmpty(idElement.Value)
select new PackageDependency(
idElement.Value?.Trim(),
element.GetOptionalAttributeValue("version")?.Trim())
).ToList();
}
示例15: ReadReference
public static List<ManifestReference> ReadReference(XElement referenceElement)
{
return (from element in referenceElement.ElementsNoNamespace("reference")
select new ManifestReference { File = element.GetOptionalAttributeValue("file").SafeTrim() }
).ToList();
}