本文整理汇总了C#中IObjectDescriptor类的典型用法代码示例。如果您正苦于以下问题:C# IObjectDescriptor类的具体用法?C# IObjectDescriptor怎么用?C# IObjectDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IObjectDescriptor类属于命名空间,在下文中一共展示了IObjectDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Enter
public override bool Enter(IObjectDescriptor value, IEmitter context)
{
var typeConverter = typeConverters.FirstOrDefault(t => t.Accepts(value.Type));
if (typeConverter != null)
{
typeConverter.WriteYaml(context, value.Value, value.Type);
return false;
}
var convertible = value.Value as IYamlConvertible;
if (convertible != null)
{
convertible.Write(context, nestedObjectSerializer);
return false;
}
#pragma warning disable 0618 // IYamlSerializable is obsolete
var serializable = value.Value as IYamlSerializable;
if (serializable != null)
{
serializable.WriteYaml(context);
return false;
}
#pragma warning restore
return base.Enter(value, context);
}
示例2: TraverseProperties
protected override void TraverseProperties(IObjectDescriptor value, IObjectGraphVisitor visitor, int currentDepth)
{
if (!ReflectionUtility.HasDefaultConstructor(value.Type) && !serializer.Converters.Any(c => c.Accepts(value.Type)))
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Type '{0}' cannot be deserialized because it does not have a default constructor or a type converter.", value.Type));
}
base.TraverseProperties(value, visitor, currentDepth);
}
示例3: EnterMapping
public override bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value)
{
var defaultValueAttribute = key.GetCustomAttribute<DefaultValueAttribute>();
var defaultValue = defaultValueAttribute != null
? defaultValueAttribute.Value
: GetDefault(key.Type);
return !_objectComparer.Equals(value.Value, defaultValue)
&& base.EnterMapping(key, value);
}
示例4: Enter
public override bool Enter(IObjectDescriptor value)
{
var alias = aliasProvider.GetAlias(value.Value);
if (alias != null && !emittedAliases.Add(alias))
{
eventEmitter.Emit(new AliasEventInfo(value) { Alias = alias });
return false;
}
return base.Enter(value);
}
示例5: EmitDocument
private void EmitDocument(IEmitter emitter, IObjectDescriptor graph)
{
var traversalStrategy = CreateTraversalStrategy();
var eventEmitter = CreateEventEmitter(emitter);
var emittingVisitor = CreateEmittingVisitor(emitter, traversalStrategy, eventEmitter, graph);
emitter.Emit(new StreamStart());
emitter.Emit(new DocumentStart());
traversalStrategy.Traverse(graph, emittingVisitor);
emitter.Emit(new DocumentEnd(true));
emitter.Emit(new StreamEnd());
}
示例6: Enter
protected override bool Enter(IObjectDescriptor value)
{
AnchorAssignment assignment;
if (value.Value != null && assignments.TryGetValue(value.Value, out assignment))
{
if (assignment.Anchor == null)
{
assignment.Anchor = "o" + nextId.ToString(CultureInfo.InvariantCulture);
++nextId;
}
return false;
}
return true;
}
示例7: Enter
public override bool Enter(IObjectDescriptor value)
{
var typeConverter = typeConverters.FirstOrDefault(t => t.Accepts(value.Type));
if (typeConverter != null)
{
typeConverter.WriteYaml(emitter, value.Value, value.Type);
return false;
}
var serializable = value as IYamlSerializable;
if (serializable != null)
{
serializable.WriteYaml(emitter);
return false;
}
return base.Enter(value);
}
示例8: CreateEmittingVisitor
private IObjectGraphVisitor CreateEmittingVisitor(IEmitter emitter, IObjectGraphTraversalStrategy traversalStrategy, IEventEmitter eventEmitter, IObjectDescriptor graph)
{
IObjectGraphVisitor emittingVisitor = new EmittingObjectGraphVisitor(eventEmitter);
emittingVisitor = new CustomSerializationObjectGraphVisitor(emitter, emittingVisitor, Converters);
if (!IsOptionSet(SerializationOptions.DisableAliases))
{
var anchorAssigner = new AnchorAssigner();
traversalStrategy.Traverse(graph, anchorAssigner);
emittingVisitor = new AnchorAssigningObjectGraphVisitor(emittingVisitor, eventEmitter, anchorAssigner);
}
if (!IsOptionSet(SerializationOptions.EmitDefaults))
{
emittingVisitor = new DefaultExclusiveObjectGraphVisitor(emittingVisitor);
}
return emittingVisitor;
}
示例9: AnchorAssignment
bool IObjectGraphVisitor.Enter(IObjectDescriptor value)
{
// Do not assign anchors to basic types
if (value.Value == null || value.Type.GetTypeCode() != TypeCode.Object)
{
return false;
}
AnchorAssignment assignment;
if (assignments.TryGetValue(value.Value, out assignment))
{
if (assignment.Anchor == null)
{
assignment.Anchor = "o" + nextId.ToString(CultureInfo.InvariantCulture);
++nextId;
}
return false;
}
else
{
assignments.Add(value.Value, new AnchorAssignment());
return true;
}
}
示例10:
bool IObjectGraphVisitor.EnterMapping(IPropertyDescriptor key, IObjectDescriptor value)
{
return true;
}
示例11: VisitMappingStart
public virtual void VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType)
{
nextVisitor.VisitMappingStart(mapping, keyType, valueType);
}
示例12: VisitSequenceEnd
public virtual void VisitSequenceEnd(IObjectDescriptor sequence)
{
nextVisitor.VisitSequenceEnd(sequence);
}
示例13: VisitScalar
public override void VisitScalar(IObjectDescriptor scalar)
{
eventEmitter.Emit(new ScalarEventInfo(scalar) { Anchor = aliasProvider.GetAlias(scalar.Value) });
}
示例14: EnterMapping
public virtual bool EnterMapping(IPropertyDescriptor key, IObjectDescriptor value)
{
return nextVisitor.EnterMapping(key, value);
}
示例15: VisitMappingStart
public override void VisitMappingStart(IObjectDescriptor mapping, Type keyType, Type valueType)
{
eventEmitter.Emit(new MappingStartEventInfo(mapping) { Anchor = aliasProvider.GetAlias(mapping.Value) });
}