本文整理匯總了C#中System.Xml.Linq.XElement.GetOptionalAttributeValue方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.GetOptionalAttributeValue方法的具體用法?C# XElement.GetOptionalAttributeValue怎麽用?C# XElement.GetOptionalAttributeValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.GetOptionalAttributeValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadMetadata
private static ManifestMetadata ReadMetadata(XElement xElement)
{
var manifestMetadata = new ManifestMetadata();
manifestMetadata.DependencySets = new List<ManifestDependencySet>();
manifestMetadata.ReferenceSets = new List<ManifestReferenceSet>();
manifestMetadata.MinClientVersionString = xElement.GetOptionalAttributeValue("minClientVersion");
// we store all child elements under <metadata> so that we can easily check for required elements.
var allElements = new HashSet<string>();
XNode node = xElement.FirstNode;
while (node != null)
{
var element = node as XElement;
if (element != null)
{
ReadMetadataValue(manifestMetadata, element, allElements);
}
node = node.NextNode;
}
// now check for required elements, which include <id>, <version>, <authors> and <description>
foreach (var requiredElement in RequiredElements)
{
if (!allElements.Contains(requiredElement))
{
throw new InvalidDataException(
String.Format(CultureInfo.CurrentCulture, NuGetResources.Manifest_RequiredElementMissing, requiredElement));
}
}
return manifestMetadata;
}
示例2: ReadMetadata
private static ManifestMetadata ReadMetadata(XElement xElement)
{
var manifestMetadata = new ManifestMetadata();
manifestMetadata.DependencySets = new List<ManifestDependencySet>();
manifestMetadata.ReferenceSets = new List<ManifestReferenceSet>();
manifestMetadata.MinClientVersionString = xElement.GetOptionalAttributeValue("minClientVersion");
XNode node = xElement.FirstNode;
while (node != null)
{
var element = node as XElement;
if (element != null)
{
ReadMetadataValue(manifestMetadata, element);
}
node = node.NextNode;
}
return manifestMetadata;
}
示例3: ParseProperty
/// <summary>
/// Parse a Property from its XElement
/// </summary>
/// <param name="propertyElement">XElement to parse Property from</param>
/// <returns>A memberProperty</returns>
protected virtual MemberProperty ParseProperty(XElement propertyElement)
{
var name = propertyElement.GetRequiredAttributeValue("Name");
DataType dataType = this.ParsePropertyDataType(propertyElement);
var memberProperty = new MemberProperty(name, dataType);
if (propertyElement.GetOptionalAttributeValue("ConcurrencyMode", "None") == "Fixed")
{
memberProperty.Annotations.Add(new ConcurrencyTokenAnnotation());
}
this.ParseAnnotations(memberProperty, propertyElement);
return memberProperty;
}
示例4: ParseType
/// <summary>
/// Parses a XElement that contains type information
/// Accepts an element that is a CollectionType, RowType, ReferenceType, and TypeRef
/// </summary>
/// <param name="typeElement">XElement that contains a Type element</param>
/// <returns>DataType represented by the XElement</returns>
protected DataType ParseType(XElement typeElement)
{
if (typeElement.Name.LocalName == "CollectionType")
{
string elementTypeName = typeElement.GetOptionalAttributeValue("ElementType", null);
if (elementTypeName != null)
{
bool isNullable = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("Nullable", "true"));
DataType dataType = this.ParseType(elementTypeName, isNullable, typeElement.Attributes());
return DataTypes.CollectionType.WithElementDataType(dataType);
}
else
{
var elementType = typeElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName));
return DataTypes.CollectionType.WithElementDataType(this.ParseType(elementType));
}
}
else if (typeElement.Name.LocalName == "RowType")
{
var row = new RowType();
foreach (var propertyElement in typeElement.Elements().Where(el => this.IsXsdlElement(el, "Property")))
{
row.Properties.Add(this.ParseProperty(propertyElement));
}
return DataTypes.RowType.WithDefinition(row);
}
else if (typeElement.Name.LocalName == "ReferenceType")
{
DataType dataType = this.ParseType(typeElement.GetRequiredAttributeValue("Type"), true, null);
return DataTypes.ReferenceType.WithEntityType((dataType as EntityDataType).Definition);
}
else if (typeElement.Name.LocalName == "TypeRef")
{
bool isNullable = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("Nullable", "true"));
DataType dataType = this.ParseType(typeElement.GetRequiredAttributeValue("Type"), isNullable, typeElement.Attributes());
return dataType;
}
else
{
throw new TaupoNotSupportedException("Unsupported data type element: " + typeElement.Name.LocalName);
}
}
示例5: ParseFunction
/// <summary>
/// Parses a function element
/// </summary>
/// <param name="functionElement">the XElement to represent a Function</param>
/// <returns>the Function representation in entity data model</returns>
protected virtual Function ParseFunction(XElement functionElement)
{
string name = functionElement.GetRequiredAttributeValue("Name");
var function = new Function(this.CurrentNamespace, name);
string returnTypeName = functionElement.GetOptionalAttributeValue("ReturnType", null);
if (returnTypeName != null)
{
bool isNullable = XmlConvert.ToBoolean(functionElement.GetOptionalAttributeValue("Nullable", "true"));
function.ReturnType = this.ParseType(returnTypeName, isNullable, null);
}
var returnTypeElement = functionElement.Elements().SingleOrDefault(el => this.IsXsdlElement(el, "ReturnType"));
if (returnTypeElement != null)
{
returnTypeName = returnTypeElement.GetOptionalAttributeValue("Type", null);
bool isNullable = XmlConvert.ToBoolean(returnTypeElement.GetOptionalAttributeValue("Nullable", "true"));
if (returnTypeName != null)
{
function.ReturnType = this.ParseType(returnTypeName, isNullable, returnTypeElement.Attributes());
}
else
{
function.ReturnType = this.ParseType(returnTypeElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName)));
}
}
foreach (var parameterElement in functionElement.Elements().Where(el => this.IsXsdlElement(el, "Parameter")))
{
function.Parameters.Add(this.ParseFunctionParameter(parameterElement));
}
this.ParseAnnotations(function, functionElement);
return function;
}
示例6: ParseEntityContainer
/// <summary>
/// Parses an entity container element in the csdl file.
/// </summary>
/// <param name="entityContainerElement">the entity container element to parse</param>
/// <returns>the parsed entity container object in the entity model schema</returns>
protected override EntityContainer ParseEntityContainer(XElement entityContainerElement)
{
var entityContainer = base.ParseEntityContainer(entityContainerElement);
foreach (var functionImportElement in entityContainerElement.Elements().Where(el => this.IsXsdlElement(el, "FunctionImport")))
{
entityContainer.Add(this.ParseFunctionImport(functionImportElement));
}
string typeaccess = entityContainerElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "TypeAccess", null);
if (typeaccess != null)
{
entityContainer.Annotations.Add(new TypeAccessModifierAnnotation(this.GetAccessModifier(typeaccess)));
}
return entityContainer;
}
示例7: GetRepositoryType
private RepositoryType GetRepositoryType(XElement packagesElement)
{
string repositoryAttributeValue = packagesElement.GetOptionalAttributeValue("repository");
switch (repositoryAttributeValue)
{
case "extension":
return RepositoryType.Extension;
case "registry":
return RepositoryType.Registry;
case "template":
case null:
return RepositoryType.Template;
default:
ShowErrorMessage(String.Format(VsResources.TemplateWizard_InvalidRepositoryAttribute,
repositoryAttributeValue));
throw new WizardBackoutException();
}
}
示例8: GetExtensionRepositoryPath
private string GetExtensionRepositoryPath(XElement packagesElement, object vsExtensionManager)
{
string repositoryId = packagesElement.GetOptionalAttributeValue("repositoryId");
if (repositoryId == null)
{
ShowErrorMessage(VsResources.TemplateWizard_MissingExtensionId);
throw new WizardBackoutException();
}
var extensionManagerShim = new ExtensionManagerShim(vsExtensionManager);
string installPath;
if (!extensionManagerShim.TryGetExtensionInstallPath(repositoryId, out installPath))
{
ShowErrorMessage(String.Format(VsResources.TemplateWizard_InvalidExtensionId,
repositoryId));
throw new WizardBackoutException();
}
return Path.Combine(installPath, "Packages");
}
示例9: ParseFunctionImport
private FunctionImport ParseFunctionImport(XElement functionImportElement)
{
string functionImportName = functionImportElement.GetRequiredAttributeValue("Name");
var functionImport = new FunctionImport(functionImportName);
bool isComposable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsComposable", "false"));
functionImport.IsComposable = isComposable;
bool isBindable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsBindable", "false"));
functionImport.IsBindable = isBindable;
bool isSideEffecting = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("IsSideEffecting", "true"));
functionImport.IsSideEffecting = isSideEffecting;
string entitySetPath = functionImportElement.GetOptionalAttributeValue("EntitySetPath", null);
if (entitySetPath != null)
{
functionImport.Annotations.Add(new EntitySetPathAnnotation(entitySetPath));
}
foreach (var parameterElement in functionImportElement.Elements().Where(el => this.IsXsdlElement(el, "Parameter")))
{
functionImport.Parameters.Add(this.ParseFunctionParameter(parameterElement));
}
string returnTypeName = functionImportElement.GetOptionalAttributeValue("ReturnType", null);
if (returnTypeName != null)
{
bool isNullable = XmlConvert.ToBoolean(functionImportElement.GetOptionalAttributeValue("Nullable", "true"));
var returnType = new FunctionImportReturnType(this.ParseType(returnTypeName, isNullable, null));
string entitySetName = functionImportElement.GetOptionalAttributeValue("EntitySet", null);
if (entitySetName != null)
{
returnType.EntitySet = new EntitySetReference(entitySetName);
}
functionImport.Add(returnType);
}
foreach (var returnTypeElement in functionImportElement.Elements().Where(el => this.IsXsdlElement(el, "ReturnType")))
{
var type = returnTypeElement.GetRequiredAttributeValue("Type");
var returnType = new FunctionImportReturnType(this.ParseType(type, true, null));
var entitySet = returnTypeElement.GetOptionalAttributeValue("EntitySet", null);
if (entitySet != null)
{
returnType.EntitySet = new EntitySetReference(entitySet);
}
functionImport.ReturnTypes.Add(returnType);
}
string methodaccess = functionImportElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "MethodAccess", null);
if (methodaccess != null)
{
functionImport.Annotations.Add(new MethodAccessModifierAnnotation(this.GetAccessModifier(methodaccess)));
}
this.ParseAnnotations(functionImport, functionImportElement);
return functionImport;
}
示例10: ParseNavigationProperty
private NavigationProperty ParseNavigationProperty(XElement navigationPropertyElement)
{
var name = navigationPropertyElement.GetRequiredAttributeValue("Name");
string relationshipNamespace = this.ParseEdmTypeName(navigationPropertyElement.GetRequiredAttributeValue("Relationship"))[0];
string relationshipName = this.ParseEdmTypeName(navigationPropertyElement.GetRequiredAttributeValue("Relationship"))[1];
string fromRole = navigationPropertyElement.GetRequiredAttributeValue("FromRole");
string toRole = navigationPropertyElement.GetRequiredAttributeValue("ToRole");
var navProp = new NavigationProperty(name, new AssociationTypeReference(relationshipNamespace, relationshipName), fromRole, toRole);
this.ParseAnnotations(navProp, navigationPropertyElement);
string getteraccess = navigationPropertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "GetterAccess", null);
string setteraccess = navigationPropertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "SetterAccess", null);
if (getteraccess != null || setteraccess != null)
{
AccessModifier setter;
AccessModifier getter;
this.GetGetterAndSetterModifiers(getteraccess, setteraccess, out setter, out getter);
navProp.Annotations.Add(new PropertyAccessModifierAnnotation(setter, getter));
}
return navProp;
}
示例11: ParseEnumMember
private EnumMember ParseEnumMember(XElement memberElement)
{
string name = memberElement.GetRequiredAttributeValue("Name");
string valueString = memberElement.GetOptionalAttributeValue("Value", null);
var member = new EnumMember(name, valueString);
this.ParseAnnotations(member, memberElement);
return member;
}
示例12: ParseEnumType
private EnumType ParseEnumType(XElement enumTypeElement)
{
string name = enumTypeElement.GetRequiredAttributeValue("Name");
string underlyingTypeString = enumTypeElement.GetOptionalAttributeValue("UnderlyingType", null);
Type underlyingType = null;
if (underlyingTypeString != null)
{
string underlyingTypeName = this.ParseEdmTypeName(underlyingTypeString)[1];
underlyingType = Type.GetType("System." + underlyingTypeName);
}
var isFlagsString = enumTypeElement.Attribute("IsFlags");
var enumType = new EnumType(this.CurrentNamespace, name) { IsFlags = isFlagsString == null ? (bool?)null : bool.Parse(isFlagsString.Value), UnderlyingType = underlyingType };
foreach (var memberElement in enumTypeElement.Elements().Where(el => this.IsXsdlElement(el, "Member")))
{
enumType.Members.Add(this.ParseEnumMember(memberElement));
}
this.ParseAnnotations(enumType, enumTypeElement);
return enumType;
}
示例13: ParseNamedStructuralTypeAttributes
private void ParseNamedStructuralTypeAttributes(XElement typeElement, NamedStructuralType type)
{
type.IsAbstract = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("Abstract", "false"));
type.IsOpen = XmlConvert.ToBoolean(typeElement.GetOptionalAttributeValue("OpenType", "false"));
string baseTypeFullName = typeElement.GetOptionalAttributeValue("BaseType", null);
if (baseTypeFullName != null)
{
string[] typeNameInfo = this.ParseEdmTypeName(baseTypeFullName);
string baseTypeNamespace = typeNameInfo[0];
string baseTypeName = typeNameInfo[1];
ComplexType complexType = type as ComplexType;
EntityType entityType = type as EntityType;
if (complexType != null)
{
complexType.BaseType = new ComplexTypeReference(baseTypeNamespace, baseTypeName);
}
else
{
ExceptionUtilities.Assert(entityType != null, "{0} is neither Entity nor Complex, but {1}!", type.FullName, type.GetType());
entityType.BaseType = new EntityTypeReference(baseTypeNamespace, baseTypeName);
}
}
string typeaccess = typeElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "TypeAccess", null);
if (typeaccess != null)
{
type.Annotations.Add(new TypeAccessModifierAnnotation(this.GetAccessModifier(typeaccess)));
}
}
示例14: ParseProperty
/// <summary>
/// Parse a Property from its XElement
/// </summary>
/// <param name="propertyElement">XElement to parse Property from</param>
/// <returns>A memberProperty</returns>
protected override MemberProperty ParseProperty(XElement propertyElement)
{
MemberProperty memberProperty = base.ParseProperty(propertyElement);
string defaultValueString = propertyElement.GetOptionalAttributeValue("DefaultValue", null);
if (defaultValueString != null)
{
memberProperty.DefaultValue = this.ParseDefaultValueString(defaultValueString, memberProperty.PropertyType);
}
string getteraccess = propertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "GetterAccess", null);
string setteraccess = propertyElement.GetOptionalAttributeValue(EdmConstants.CodegenNamespace + "SetterAccess", null);
if (getteraccess != null || setteraccess != null)
{
AccessModifier setter;
AccessModifier getter;
this.GetGetterAndSetterModifiers(getteraccess, setteraccess, out setter, out getter);
memberProperty.Annotations.Add(new PropertyAccessModifierAnnotation(setter, getter));
}
string collectionKindString = propertyElement.GetOptionalAttributeValue("CollectionKind", null);
if (collectionKindString != null)
{
CollectionKind kind = (CollectionKind)Enum.Parse(typeof(CollectionKind), collectionKindString, false);
memberProperty.Annotations.Add(new CollectionKindAnnotation(kind));
}
return memberProperty;
}
示例15: ParsePropertyDataType
/// <summary>
/// Parses the property Element to determine the DataType of the Property
/// </summary>
/// <param name="propertyElement">Property Element used as input to find the DataType</param>
/// <returns>DataType that is determined from the property element</returns>
protected override DataType ParsePropertyDataType(XElement propertyElement)
{
bool isNullable = XmlConvert.ToBoolean(propertyElement.GetOptionalAttributeValue("Nullable", "true"));
string parameterTypeName = propertyElement.GetOptionalAttributeValue("Type", null);
if (parameterTypeName != null)
{
return this.ParseType(parameterTypeName, isNullable, propertyElement.Attributes());
}
else
{
var parameterTypeElement = propertyElement.Elements().Single(e => this.IsXsdlNamespace(e.Name.NamespaceName));
return this.ParseType(parameterTypeElement);
}
}