本文整理汇总了C#中ISchemaElement类的典型用法代码示例。如果您正苦于以下问题:C# ISchemaElement类的具体用法?C# ISchemaElement怎么用?C# ISchemaElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISchemaElement类属于命名空间,在下文中一共展示了ISchemaElement类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetAttributeOnObject
private static void SetAttributeOnObject(ISchemaElement schemaElement, string name, string value)
{
ISetAttributes setAttributes = schemaElement as ISetAttributes;
if (setAttributes == null)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixStrings.EXP_ISchemaElementDoesnotImplementISetAttribute, schemaElement.GetType().FullName));
}
else
{
setAttributes.SetAttribute(name, value);
}
}
示例2: ParseObjectFromElement
/// <summary>
/// Parses an ISchemaElement from the XmlElement.
/// </summary>
/// <param name="schemaElement">ISchemaElement to fill in.</param>
/// <param name="element">XmlElement to parse from.</param>
private void ParseObjectFromElement(ISchemaElement schemaElement, XmlElement element)
{
foreach (XmlAttribute attribute in element.Attributes)
{
this.SetAttributeOnObject(schemaElement, attribute.LocalName, attribute.Value);
}
foreach (XmlNode node in element.ChildNodes)
{
XmlElement childElement = node as XmlElement;
if (childElement != null)
{
ISchemaElement childSchemaElement = null;
ICreateChildren createChildren = schemaElement as ICreateChildren;
if (createChildren == null)
{
throw new InvalidOperationException("ISchemaElement with name " + element.LocalName + " does not implement ICreateChildren.");
}
else
{
childSchemaElement = createChildren.CreateChild(childElement.LocalName);
}
if (childSchemaElement == null)
{
childSchemaElement = this.CreateObjectFromElement(childElement);
if (childSchemaElement == null)
{
throw new InvalidOperationException("XmlElement with name " + childElement.LocalName + " does not have a corresponding ISchemaElement.");
}
}
this.ParseObjectFromElement(childSchemaElement, childElement);
IParentElement parentElement = (IParentElement)schemaElement;
parentElement.AddChild(childSchemaElement);
}
else
{
XmlText childText = node as XmlText;
if (childText != null)
{
this.SetAttributeOnObject(schemaElement, "Content", childText.Value);
}
}
}
}
示例3: SetAttributeOnObject
/// <summary>
/// Sets an attribute on an ISchemaElement.
/// </summary>
/// <param name="schemaElement">Schema element to set attribute on.</param>
/// <param name="name">Name of the attribute to set.</param>
/// <param name="value">Value to set on the attribute.</param>
private void SetAttributeOnObject(ISchemaElement schemaElement, string name, string value)
{
ISetAttributes setAttributes = schemaElement as ISetAttributes;
if (setAttributes == null)
{
throw new InvalidOperationException("ISchemaElement with name "
+ schemaElement.GetType().FullName.ToString()
+ " does not implement ISetAttributes.");
}
else
{
setAttributes.SetAttribute(name, value);
}
}
示例4: IndexElement
/// <summary>
/// Index an element by its corresponding row.
/// </summary>
/// <param name="row">The row corresponding to the element.</param>
/// <param name="element">The element to index.</param>
public void IndexElement(Row row, ISchemaElement element)
{
this.elements.Add(String.Concat(row.TableDefinition.Name, ':', row.GetPrimaryKey(PrimaryKeyDelimiter)), element);
}
示例5: RemoveElement
/// <summary>
/// Removes an element from this collection.
/// </summary>
/// <param name="element">The element to remove.</param>
/// <exception cref="ArgumentException">Thrown if the element's type isn't assignable to the collection's type.</exception>
public void RemoveElement(ISchemaElement element)
{
if (!this.elementType.IsAssignableFrom(element.GetType()))
{
throw new ArgumentException(
String.Format(
CultureInfo.InvariantCulture,
WixStrings.EXP_ElementIsSubclassOfDifferentType,
this.elementType.Name,
element.GetType().Name),
"element");
}
this.elements.Remove(element);
}
示例6: RemoveElement
/// <summary>
/// Removes an element from this collection.
/// </summary>
/// <param name="element">The element to remove.</param>
/// <exception cref="ArgumentException">Thrown if the element's type isn't assignable to the collection's type.</exception>
public void RemoveElement(ISchemaElement element)
{
if (!this.elementType.IsAssignableFrom(element.GetType()))
{
throw new ArgumentException(
String.Format(
CultureInfo.InvariantCulture,
"Element must be a subclass of {0}, but was of type {1}.",
this.elementType.Name,
element.GetType().Name),
"element");
}
this.elements.Remove(element);
}
示例7: AddElement
/// <summary>
/// Adds a child element to this collection.
/// </summary>
/// <param name="element">The element to add.</param>
/// <exception cref="ArgumentException">Thrown if the child is not of an allowed type.</exception>
public void AddElement(ISchemaElement element)
{
foreach (object obj in this.items)
{
bool containerUsed;
CollectionItem collectionItem = obj as CollectionItem;
if (collectionItem != null)
{
containerUsed = collectionItem.Elements.Count != 0;
if (collectionItem.ElementType.IsAssignableFrom(element.GetType()))
{
collectionItem.AddElement(element);
if (!containerUsed)
{
this.containersUsed++;
}
this.totalContainedItems++;
return;
}
continue;
}
ElementCollection collection = obj as ElementCollection;
if (collection != null)
{
containerUsed = collection.Count != 0;
try
{
collection.AddElement(element);
if (!containerUsed)
{
this.containersUsed++;
}
this.totalContainedItems++;
return;
}
catch (ArgumentException)
{
// Eat the exception and keep looking. We'll throw our own if we can't find its home.
}
continue;
}
}
throw new ArgumentException(String.Format(
CultureInfo.InvariantCulture,
"Element of type {0} is not valid for this collection.",
element.GetType().Name));
}
示例8: ParseObjectFromElement
private void ParseObjectFromElement(ISchemaElement schemaElement, XmlElement element)
{
foreach (XmlAttribute attribute in element.Attributes)
{
SetAttributeOnObject(schemaElement, attribute.LocalName, attribute.Value);
}
foreach (XmlNode node in element.ChildNodes)
{
XmlElement childElement = node as XmlElement;
if (childElement != null)
{
ISchemaElement childSchemaElement = null;
ICreateChildren createChildren = schemaElement as ICreateChildren;
if (createChildren == null)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixStrings.EXP_ISchemaElementDoesnotImplementICreateChildren, element.LocalName));
}
else
{
childSchemaElement = createChildren.CreateChild(childElement.LocalName);
}
if (childSchemaElement == null)
{
childSchemaElement = this.CreateObjectFromElement(childElement);
if (childSchemaElement == null)
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentUICulture, WixStrings.EXP_XmlElementDoesnotHaveISchemaElement, childElement.LocalName));
}
}
this.ParseObjectFromElement(childSchemaElement, childElement);
IParentElement parentElement = (IParentElement)schemaElement;
parentElement.AddChild(childSchemaElement);
}
else
{
XmlText childText = node as XmlText;
if (childText != null)
{
SetAttributeOnObject(schemaElement, "Content", childText.Value);
}
}
}
}
示例9: AddChild
public virtual void AddChild(ISchemaElement child)
{
this.children.AddElement(child);
}
示例10: RemoveChild
public virtual void RemoveChild(ISchemaElement child)
{
this.children.RemoveElement(child);
}