本文整理汇总了C#中IMemberContext.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# IMemberContext.GetValue方法的具体用法?C# IMemberContext.GetValue怎么用?C# IMemberContext.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMemberContext
的用法示例。
在下文中一共展示了IMemberContext.GetValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapForDeserialization
public IEnumerable<IMapping<XObject, IMemberContext>> MapForDeserialization(XElement source, IMemberContext target, IAdviceRequester adviceRequester)
{
if (source == null)
throw new ArgumentNullException("source");
if (target == null)
throw new ArgumentNullException("target");
var targetObject = target.GetValue();
foreach (var member in targetObject.Members.Where(m => !m.Attributes.OfType<XmlIgnoreAttribute>().Any()))
{
var sourceType = GetSourceTypeAndPotentialNames(member);
switch (sourceType.Key)
{
case XmlNodeType.Element:
foreach (var mapping in GetMappingsFromElement(sourceType.Value, source, targetObject, member, adviceRequester))
yield return mapping;
break;
case XmlNodeType.Attribute:
yield return GetMappingFromAttribute(sourceType.Value, source, member);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}
示例2: Serialize
public bool Serialize(IMemberContext source, XObject target, IAdviceRequester adviceRequester)
{
if (source == null)
throw new ArgumentNullException("source");
if (target.NodeType != XmlNodeType.Element)
throw new ArgumentException("Parameter must be an XML element.", "target");
var elem = (XElement)target;
IObjectContext sourceObject = source.GetValue();
if (sourceObject == null || sourceObject.GetObject() == null)
{
if (_isNullableStrategy.IsNullable(source, elem, adviceRequester))
{
elem.Add(Constants.XsiNilAttribute);
return true;
}
return false;
}
List<IMapping<IMemberContext, XObject>> mappings = _mapper.MapForSerialization(source, elem, adviceRequester)
.ToList();
if (mappings == null)
throw new ArgumentException("Unable to map source '" + source + "' and target '" + target + "'.");
SerializeRecursively(elem, mappings, adviceRequester);
return true;
}
示例3: Serialize
public bool Serialize(IMemberContext source, XObject target, IAdviceRequester adviceRequester)
{
if (source == null)
throw new ArgumentNullException("source");
var sourceObject = source.GetValue().GetObject();
if (target.NodeType != XmlNodeType.Element)
throw new ArgumentException("Parameter must be an XML element.", "source");
var elem = (XElement)target;
var xmlSerializable = (IXmlSerializable)sourceObject;
var memoryStream = new MemoryStream();
var xmlWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xmlWriter.WriteStartElement(elem.Name.LocalName);
xmlWriter.WriteAttributeString("xmlns", "xsi", null, Constants.XmlSchemaInstanceNamespaceAttribute.Value);
xmlWriter.WriteAttributeString("xmlns", "xsd", null, Constants.XmlSchemaNamespaceAttribute.Value);
xmlSerializable.WriteXml(xmlWriter);
xmlWriter.WriteEndElement();
xmlWriter.Flush();
memoryStream.Position = 0;
var tempTarget = XElement.Load(memoryStream);
if (tempTarget.HasElements)
foreach (var element in tempTarget.Elements())
elem.Add(element);
else
elem.SetValue(tempTarget.Value);
foreach (var attribute in tempTarget.Attributes())
{
if (attribute.Name == Constants.XmlSchemaNamespaceAttribute.Name || attribute.Name == Constants.XmlSchemaInstanceNamespaceAttribute.Name)
continue;
elem.Add(attribute);
}
foreach (var childElem in elem.Elements())
{
var xmlnsXsiAttr = childElem.Attribute(Constants.XmlSchemaInstanceNamespaceAttribute.Name);
if (xmlnsXsiAttr != null)
xmlnsXsiAttr.Remove();
var xmlnsXsdAttr = childElem.Attribute(Constants.XmlSchemaNamespaceAttribute.Name);
if (xmlnsXsdAttr != null)
xmlnsXsdAttr.Remove();
}
return true;
}
示例4: MapForDeserialization
public IEnumerable<IMapping<XObject, IMemberContext>> MapForDeserialization(XElement source, IMemberContext target, IAdviceRequester adviceRequester)
{
var targetObject = target.GetValue();
if (targetObject == null)
throw new ArgumentException("Target should have had it value set to a collection at this point.", "target");
var elementNames = GetElementNames(target);
return source.Elements()
.Where(e => elementNames.Contains(e.Name, CaseInsensitiveXNameComparer.Instance))
.Select(elem => new Mapping<XObject, IMemberContext>(elem, targetObject.Members.Single()))
.ToList();
}
示例5: MapForSerialization
public IEnumerable<IMapping<IMemberContext, XObject>> MapForSerialization(IMemberContext source, XElement target, IAdviceRequester adviceRequester)
{
if (source == null)
throw new ArgumentNullException("source");
var elementType = GetElementType(source.GetActualType());
if (elementType == null)
throw new ArgumentException("Collection mapper has been invoked for target that is not a known list type: '" + source.GetActualType() + "'.", "target");
var sourceObject = source.GetValue();
if (sourceObject == null)
return Enumerable.Empty<IMapping<IMemberContext, XObject>>();
return sourceObject.Members
.Select(CreateMapping);
}
示例6: MapForSerialization
public IEnumerable<IMapping<IMemberContext, XObject>> MapForSerialization(IMemberContext source, XElement target, IAdviceRequester adviceRequester)
{
if (source == null)
throw new ArgumentNullException("source");
if (target == null)
throw new ArgumentNullException("target");
var sourceObject = source.GetValue();
if (sourceObject == null)
return Enumerable.Empty<IMapping<IMemberContext, XObject>>();
return sourceObject.Members
.Where(m => !m.Attributes.OfType<XmlIgnoreAttribute>().Any())
.Select(member => CreateMappingForSerialization(member, target))
.ToList();
}
示例7: GetActualObject
private static object GetActualObject(IMemberContext memberContext)
{
var objectContextValue = memberContext.GetValue();
if (objectContextValue == null)
return null;
var objectContextValueObject = objectContextValue.GetObject();
return objectContextValueObject;
}