本文整理汇总了C#中IMemberContext类的典型用法代码示例。如果您正苦于以下问题:C# IMemberContext类的具体用法?C# IMemberContext怎么用?C# IMemberContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IMemberContext类属于命名空间,在下文中一共展示了IMemberContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetActualType
public Type GetActualType(XObject source, IMemberContext target, IAdviceRequester adviceRequester)
{
return Converters
.Select(c => c.GetActualType(source, target, adviceRequester))
.Where(t => t != null)
.FirstOrDefault();
}
示例2: CreateForDeserialization
public IObjectContext CreateForDeserialization(IMemberContext targetMember, Type targetType, IAdviceRequester adviceRequester)
{
return Factories
.Select(f => f.CreateForDeserialization(targetMember, targetType, adviceRequester))
.Where(d => d != null)
.FirstOrDefault();
}
示例3: Select
public IDeserializer Select(XObject source, IMemberContext target, IAdviceRequester adviceRequester)
{
return Selectors
.Select(s => s.Select(source, target, adviceRequester))
.Where(d => d != null)
.FirstOrDefault();
}
示例4: CreateForSerialization
public IObjectContext CreateForSerialization(IMemberContext sourceMember, object source, IAdviceRequester adviceRequester)
{
return Factories
.Select(f => f.CreateForSerialization(sourceMember, source, adviceRequester))
.Where(d => d != null)
.FirstOrDefault();
}
示例5: 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;
}
示例6: EmitContext
// TODO: Replace IMemberContext with MemberCore
public EmitContext (IMemberContext rc, ILGenerator ig, TypeSpec return_type)
{
this.MemberContext = rc;
this.ig = ig;
this.return_type = return_type;
}
示例7: Select
public ISerializer Select(IMemberContext source, XObject target, IAdviceRequester adviceRequester)
{
if (target.NodeType != XmlNodeType.Element)
return null;
return _serializer;
}
示例8: 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();
}
示例9: CreateMappingForSerialization
private static IMapping<IMemberContext, XObject> CreateMappingForSerialization(IMemberContext member, XElement target)
{
var targetTypeAndName = GetTargetTypeAndName(member);
XObject xobj;
bool addTargetToParent = true;
switch (targetTypeAndName.Key)
{
case XmlNodeType.Element:
if (!member.ContractType.IsSubTypeOf<IXmlSerializable>() && member.ContractType.IsCollectionType() && HasXmlElementAttribute(member) || HasXmlTextAttribute(member))
{
xobj = target;
addTargetToParent = false;
}
else
xobj = new XElement(targetTypeAndName.Value);
break;
case XmlNodeType.Attribute:
xobj = new XAttribute(targetTypeAndName.Value, string.Empty);
break;
default:
throw new ArgumentOutOfRangeException("Mapped to an unknown node type: " + targetTypeAndName.Key + ".");
}
return new Mapping<IMemberContext, XObject>(member, xobj, addTargetToParent);
}
示例10: 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();
}
}
}
示例11: 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;
}
示例12: GetActualTypeFromXmlElementAttribute
private static Type GetActualTypeFromXmlElementAttribute(XElement source, IMemberContext target)
{
if (source == null)
return null;
return GetTypeFromXmlElementAttributeWithMatchingName(source, target)
?? GetTypeFromXmlElementAttributeWithoutName(target);
}
示例13: Select
public override IDeserializer Select(XObject source, IMemberContext target, IAdviceRequester adviceRequester)
{
var contractTypeFromAttr = GetContractTypeFromAttributes(source, target);
if (contractTypeFromAttr == null)
return null;
return Select(source, target, contractTypeFromAttr, adviceRequester);
}
开发者ID:kimbirkelund,项目名称:SekhmetSerialization,代码行数:8,代码来源:XmlSerializerValueTypeDeserializerSelector.cs
示例14: MultipleMatchesAdviceRequestedEventArgs
public MultipleMatchesAdviceRequestedEventArgs(XElement source, IObjectContext targetOwner, IMemberContext target, IEnumerable<XObject> matches, XObject selectedMatch)
: base(CommonAdviceTypes.MultipleMatches)
{
Source = source;
TargetOwner = targetOwner;
Target = target;
Matches = (matches ?? Enumerable.Empty<XObject>()).ToList();
SelectedMatch = selectedMatch;
}
示例15: ResolveType
public bool ResolveType(IMemberContext mc, TypeSpec defaultType)
{
if (TypeExpression != null)
this.Type = TypeExpression.ResolveAsType (mc);
else
this.Type = defaultType;
return this.Type != null;
}