本文整理汇总了C#中XmlElementHelper.ReadInteger方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElementHelper.ReadInteger方法的具体用法?C# XmlElementHelper.ReadInteger怎么用?C# XmlElementHelper.ReadInteger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlElementHelper
的用法示例。
在下文中一共展示了XmlElementHelper.ReadInteger方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestIntegerAttributes
public void TestIntegerAttributes()
{
XmlElement element = xmlDocument.CreateElement("element");
// Test attribute writing.
XmlElementHelper writer = new XmlElementHelper(element);
writer.SetAttribute("ValidName", -1234);
// Test reading of existing attribute.
XmlElementHelper reader = new XmlElementHelper(element);
Assert.AreEqual(-1234, reader.ReadInteger("ValidName"));
// Test reading of non-existence attribute with default value.
Assert.AreEqual(5678, reader.ReadInteger("InvalidName", 5678));
// Test reading of non-existence attribute without default value.
Assert.Throws<InvalidOperationException>(() =>
{
reader.ReadInteger("InvalidName");
});
}
示例2: LoadConnectorFromXml
/// <summary>
/// Creates and initializes a ConnectorModel from its Xml representation.
/// </summary>
/// <param name="connEl">XmlElement for a ConnectorModel.</param>
/// <param name="nodes">Dictionary to be used for looking up a NodeModel by it's Guid.</param>
/// <returns>Returns the new instance of ConnectorModel loaded from XmlElement.</returns>
public static ConnectorModel LoadConnectorFromXml(XmlElement connEl, IDictionary<Guid, NodeModel> nodes)
{
var helper = new XmlElementHelper(connEl);
var guid = helper.ReadGuid("guid", Guid.NewGuid());
var guidStart = helper.ReadGuid("start");
var guidEnd = helper.ReadGuid("end");
int startIndex = helper.ReadInteger("start_index");
int endIndex = helper.ReadInteger("end_index");
//find the elements to connect
NodeModel start;
if (nodes.TryGetValue(guidStart, out start))
{
NodeModel end;
if (nodes.TryGetValue(guidEnd, out end))
{
return ConnectorModel.Make(start, end, startIndex, endIndex, guid);
}
}
return null;
}
示例3: DeserializeCore
internal static PausePlaybackCommand DeserializeCore(XmlElement element)
{
XmlElementHelper helper = new XmlElementHelper(element);
var pauseDurationInMs = helper.ReadInteger("PauseDurationInMs");
return new PausePlaybackCommand(pauseDurationInMs);
}
示例4: DeserializeCore
protected override void DeserializeCore(XmlElement nodeElement, SaveContext context)
{
XmlElementHelper helper = new XmlElementHelper(nodeElement);
this.Radius = helper.ReadInteger(DummyModel.RadiusName);
this.Identifier = helper.ReadInteger(DummyModel.IdName);
}
示例5: GetModelForElement
public ModelBase GetModelForElement(XmlElement modelData)
{
XmlElementHelper helper = new XmlElementHelper(modelData);
int identifier = helper.ReadInteger(DummyModel.IdName);
return (models.Find((x) => (x.Identifier == identifier)));
}
示例6: ReloadModel
public void ReloadModel(XmlElement modelData)
{
XmlElementHelper helper = new XmlElementHelper(modelData);
int identifier = helper.ReadInteger(DummyModel.IdName);
DummyModel model = models.First((x) => (x.Identifier == identifier));
model.Deserialize(modelData, SaveContext.Undo);
}
示例7: DeserializeCore
internal static SelectModelCommand DeserializeCore(XmlElement element)
{
var helper = new XmlElementHelper(element);
var modifiers = ((ModifierKeys)helper.ReadInteger("Modifiers"));
var modelGuids = DeserializeGuid(element, helper);
return new SelectModelCommand(modelGuids, modifiers);
}
示例8: DeserializeCore
protected override void DeserializeCore(XmlElement element, SaveContext context)
{
XmlElementHelper helper = new XmlElementHelper(element);
// Restore some information from the node attributes.
this.GUID = helper.ReadGuid("guid", this.GUID);
Guid startNodeId = helper.ReadGuid("start");
int startIndex = helper.ReadInteger("start_index");
Guid endNodeId = helper.ReadGuid("end");
int endIndex = helper.ReadInteger("end_index");
PortType portType = ((PortType)helper.ReadInteger("portType"));
// Get to the start and end nodes that this connector connects to.
WorkspaceModel workspace = dynSettings.Controller.DynamoModel.CurrentWorkspace;
NodeModel startNode = workspace.GetModelInternal(startNodeId) as NodeModel;
NodeModel endNode = workspace.GetModelInternal(endNodeId) as NodeModel;
pStart = startNode.OutPorts[startIndex];
PortModel endPort = null;
if (portType == PortType.INPUT)
endPort = endNode.InPorts[endIndex];
pStart.Connect(this);
this.Connect(endPort);
}
示例9: LoadCommandFromFile
private bool LoadCommandFromFile(string commandFilePath)
{
if (string.IsNullOrEmpty(commandFilePath))
return false;
if (File.Exists(commandFilePath) == false)
return false;
if (null != loadedCommands)
{
throw new InvalidOperationException(
"Internal error: 'LoadCommandFromFile' called twice");
}
try
{
// Attempt to load the XML from the specified path.
var document = new XmlDocument();
document.Load(commandFilePath);
// Get to the root node of this Xml document.
var commandRoot = document.FirstChild as XmlElement;
if (null == commandRoot)
return false;
// Read in optional attributes from the command root element.
var helper = new XmlElementHelper(commandRoot);
ExitAfterPlayback = helper.ReadBoolean(EXIT_ATTRIB_NAME, true);
PauseAfterPlayback = helper.ReadInteger(PAUSE_ATTRIB_NAME, 10);
CommandInterval = helper.ReadInteger(INTERVAL_ATTRIB_NAME, 20);
loadedCommands = new List<DynamoModel.RecordableCommand>();
foreach (
DynamoModel.RecordableCommand command in
commandRoot.ChildNodes.Cast<XmlNode>()
.Select(
node => DynamoModel.RecordableCommand.Deserialize(
node as XmlElement))
.Where(command => null != command))
{
loadedCommands.Add(command);
}
}
catch (Exception)
{
// Something is wrong with the Xml file, invalidate the
// data member that points to it, and return from here.
return false;
}
// Even though the Xml file can properly be loaded, it is still
// possible that the loaded content did not result in any useful
// commands. In this case simply return false, indicating failure.
//
return (null != loadedCommands && (loadedCommands.Count > 0));
}
示例10: DeleteModel
public void DeleteModel(XmlElement modelData)
{
XmlElementHelper helper = new XmlElementHelper(modelData);
int identifier = helper.ReadInteger(DummyModel.IdName);
models.RemoveAll((x) => (x.Identifier == identifier));
}