本文整理汇总了C#中XObject类的典型用法代码示例。如果您正苦于以下问题:C# XObject类的具体用法?C# XObject怎么用?C# XObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XObject类属于命名空间,在下文中一共展示了XObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public object Parse(Type type, XObject config, bool isAssignableTypeAllowed, XmlLocation childLocation, IContext context)
{
var xel = config as XElement;
if (xel == null)
throw new TestLibsException($"Couldn't cast following config to XElement:\n{config}");
return xel;
}
示例2: GetNodeCount
public int? GetNodeCount(XObject xml, string xpath)
{
if(xml == null)
{
return null;
}
if(xml.Document == null)
{
return null;
}
if(xml.Document.Root == null)
{
return null;
}
try
{
var namespaceResolver = new SimpleXmlNamespaceResolver(xml.Document);
var results = (IEnumerable)xml.Document.XPathEvaluate(xpath, namespaceResolver);
return results.OfType<XObject>().Count();
}
catch(Exception)
{
return null;
}
}
示例3: Select
public ISerializer Select(IMemberContext source, XObject target, IAdviceRequester adviceRequester)
{
if (target.NodeType != XmlNodeType.Element)
return null;
return _serializer;
}
示例4: AreEqual
public static void AreEqual(XObject expected, XObject actual)
{
if (expected is XDocument)
{
expected = ((XDocument)expected).Root;
}
if (actual is XDocument)
{
actual = ((XDocument)actual).Root;
}
if (expected == null && actual == null)
{
return;
}
if (expected == null)
{
RaiseAssertFailure(null, actual);
return;
}
if (actual == null)
{
RaiseAssertFailure(expected, null);
return;
}
if (expected.GetType() != actual.GetType())
{
RaiseAssertFailure(expected, actual);
return;
}
AssertEqualValues(expected, actual);
}
示例5: ParseDefinitionFileException
public ParseDefinitionFileException(string message, XObject source)
: base(GetMessage(message, source))
{
_source = source;
Line = (source as IXmlLineInfo).LineNumber;
Position = (source as IXmlLineInfo).LinePosition;
}
示例6: Deserialize
public void Deserialize(XObject source, IMemberContext target, IAdviceRequester adviceRequester)
{
if (source == null)
return;
if (source.NodeType != XmlNodeType.Element)
throw new ArgumentException("Parameter must be an XML element.", "source");
if (_log.IsDebugEnabled)
_log.Debug("Deserializing " + source.ToFriendlyName() + " into " + target + ".");
var elem = (XElement)source;
Type targetType = _typeConverter.GetActualType(source, target, adviceRequester);
if (targetType == null)
throw new ArgumentException("Unable to get target type for target '" + target + "'.");
IObjectContext targetObject = _objectContextFactory.CreateForDeserialization(target, targetType, adviceRequester);
if (targetObject == null)
throw new ArgumentException("Unable to create target object for target '" + target + "'.");
target.SetValue(targetObject);
List<IMapping<XObject, IMemberContext>> mappings = _mapper.MapForDeserialization(elem, target, adviceRequester)
.ToList();
if (mappings == null)
throw new ArgumentException("Unable to map source '" + source + "' and target '" + target + "'.");
DeserializeRecursively(mappings, adviceRequester);
target.CommitChanges();
}
示例7: EventsHelper
public EventsHelper(XObject x)
{
_root = x;
_root.Changing += new EventHandler<XObjectChangeEventArgs>(Changing);
_root.Changed += new EventHandler<XObjectChangeEventArgs>(Changed);
_events = new Queue<EventItem>();
}
示例8: AddSubcomponent
public override void AddSubcomponent(string name, XObject sub)
{
if (this.Levels == null)
this.Levels = new List<XLevelInfo>();
this.Levels.Add((XLevelInfo)sub);
}
示例9: Select
protected virtual IDeserializer Select(XObject source, IMemberContext target, Type type, IAdviceRequester adviceRequester)
{
var typeCode = Type.GetTypeCode(type);
switch (typeCode)
{
case TypeCode.Empty:
case TypeCode.DBNull:
return null;
case TypeCode.Object:
if (target.ContractType == typeof(TimeSpan))
break;
if (target.ContractType == typeof(string))
break;
if (target.ContractType.IsNullable())
break;
return null;
}
if (source == null)
return GetDeserializer(type);
if (source.NodeType == XmlNodeType.Element && !((XElement)source).HasElements)
return GetDeserializer(type);
if (source.NodeType == XmlNodeType.Attribute)
return GetDeserializer(type);
return null;
}
示例10: FindObject
private XObject FindObject(string id, XObject root)
{
var o = root.FindLocal(id);
if (o == null)
throw new InvalidOperationException(string.Format("Iterator '{0}' could not find obect id: '{1}'", this.Id, id));
return o;
}
示例11: Select
public IDeserializer Select(XObject source, IMemberContext target, IAdviceRequester adviceRequester)
{
return Selectors
.Select(s => s.Select(source, target, adviceRequester))
.Where(d => d != null)
.FirstOrDefault();
}
示例12: Binding
/// <summary>
/// Initializes a new instance.
/// </summary>
/// <param name="xml"></param>
/// <param name="context"></param>
/// <param name="xpath"></param>
internal Binding(XObject xml, EvaluationContext context, string xpath)
: this(xml, context, context.CompileXPath(xml, xpath))
{
Contract.Requires<ArgumentNullException>(xml != null);
Contract.Requires<ArgumentNullException>(context != null);
Contract.Requires<ArgumentNullException>(xpath != null);
}
示例13: setRoot
private void setRoot(XObject root)
{
if (root is XDocument)
_current = ((XDocument)root).Root;
else
_current = root;
}
示例14: GetActualType
public Type GetActualType(XObject source, IMemberContext target, IAdviceRequester adviceRequester)
{
return Converters
.Select(c => c.GetActualType(source, target, adviceRequester))
.Where(t => t != null)
.FirstOrDefault();
}
示例15: CopyAttributes
public void CopyAttributes(XObject src, XObject dest)
{
dest.Id = src.Id;
//dest.Class = src.Class;
dest.Enabled = src.Enabled;
// Element
var srcElement = src as XElement;
if (srcElement != null)
{
var destElement = (XElement)dest;
destElement.Bounds = srcElement.Bounds;
if (srcElement.backColor.HasValue)
destElement.BackColor = srcElement.BackColor;
if (srcElement.Rotation != 0)
destElement.Rotation = srcElement.Rotation;
}
// IHasPoints
var srcHasPoints = src as IHasPoints;
if (srcHasPoints != null && srcHasPoints.Points != 0)
{
((IHasPoints)dest).Points = srcHasPoints.Points;
}
var srcEnemy = src as XEnemy;
if (srcEnemy != null && srcEnemy.DamageSpecified)
{
((XEnemy)dest).Damage = srcEnemy.Damage;
}
}