本文整理匯總了C#中SharpYaml.Serialization.ObjectContext類的典型用法代碼示例。如果您正苦於以下問題:C# ObjectContext類的具體用法?C# ObjectContext怎麽用?C# ObjectContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ObjectContext類屬於SharpYaml.Serialization命名空間,在下文中一共展示了ObjectContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadCollectionItem
/// <inheritdoc/>
protected override object ReadCollectionItem(ref ObjectContext objectContext, Type itemType)
{
// Save the Yaml stream, in case loading fails we can keep this representation
var parsingEvents = new List<ParsingEvent>();
var reader = objectContext.Reader;
var startDepth = reader.CurrentDepth;
do
{
parsingEvents.Add(reader.Expect<ParsingEvent>());
} while (reader.CurrentDepth > startDepth);
// Save states
var previousReader = objectContext.SerializerContext.Reader;
var previousAllowErrors = objectContext.SerializerContext.AllowErrors;
objectContext.SerializerContext.Reader = new EventReader(new MemoryParser(parsingEvents));
objectContext.SerializerContext.AllowErrors = true;
try
{
return objectContext.ObjectSerializerBackend.ReadCollectionItem(ref objectContext, itemType);
}
catch (YamlException)
{
// There was a failure, let's keep this object so that it can be serialized back later
return new UnloadableScript(parsingEvents);
}
finally
{
// Restore states
objectContext.SerializerContext.Reader = previousReader;
objectContext.SerializerContext.AllowErrors = previousAllowErrors;
}
}
示例2: ReadMemberName
public override string ReadMemberName(ref ObjectContext objectContext, string memberName)
{
var newMemberName = memberName.Trim(PostFixSealed, PostFixNew);
if (newMemberName.Length != memberName.Length)
{
var overrideType = OverrideType.Base;
if (memberName.Contains(PostFixNewSealed) || memberName.EndsWith(PostFixNewSealedAlt))
{
overrideType = OverrideType.New | OverrideType.Sealed;
}
else if (memberName.EndsWith(PostFixNew))
{
overrideType = OverrideType.New;
}
else if (memberName.EndsWith(PostFixSealed))
{
overrideType = OverrideType.Sealed;
}
if (overrideType != OverrideType.Base)
{
var objectType = objectContext.Instance.GetType();
if (cachedDescriptor == null || cachedDescriptor.Type != objectType)
{
cachedDescriptor = typeDescriptorFactory.Find(objectType);
}
var memberDescriptor = cachedDescriptor[newMemberName];
objectContext.Instance.SetOverride(memberDescriptor, overrideType);
}
}
return base.ReadMemberName(ref objectContext, newMemberName);
}
示例3: WriteMemberName
public override void WriteMemberName(ref ObjectContext objectContext, SharpYaml.Serialization.IMemberDescriptor member, string memberName)
{
// Replace the key with SiliconStudio.Core.Reflection IMemberDescriptor
// Cache previous
if (member != null)
{
var customDescriptor = (IMemberDescriptor)member.Tag;
if (customDescriptor == null)
{
customDescriptor = typeDescriptorFactory.Find(objectContext.Instance.GetType())[memberName];
member.Tag = customDescriptor;
}
if (customDescriptor != null)
{
var overrideType = objectContext.Instance.GetOverride(customDescriptor);
if (!keepOnlySealedOverrides && (overrideType & OverrideType.New) != 0)
{
memberName += PostFixNew;
}
if ((overrideType & OverrideType.Sealed) != 0)
{
memberName += PostFixSealed;
}
}
}
base.WriteMemberName(ref objectContext, member, memberName);
}
示例4: WriteScalar
protected override void WriteScalar(ref ObjectContext objectContext, ScalarEventInfo scalar)
{
// TODO: if ParameterKey is written to an object, It will not serialized a tag
scalar.Tag = null;
scalar.IsPlainImplicit = true;
base.WriteScalar(ref objectContext, scalar);
}
示例5: ConvertTo
public override string ConvertTo(ref ObjectContext objectContext)
{
var attachedReference = AttachedReferenceManager.GetAttachedReference(objectContext.Instance);
if (attachedReference == null)
throw new YamlException(string.Format("Unable to extract asset reference from object [{0}]", objectContext.Instance));
return string.Format("{0}:{1}", attachedReference.Id, attachedReference.Url);
}
示例6: WriteDictionaryItems
protected override void WriteDictionaryItems(ref ObjectContext objectContext)
{
// Don't sort dictionary keys
var savedSettings = objectContext.Settings.SortKeyForMapping;
objectContext.Settings.SortKeyForMapping = false;
base.WriteDictionaryItems(ref objectContext);
objectContext.Settings.SortKeyForMapping = savedSettings;
}
示例7: WriteDictionaryItem
protected override void WriteDictionaryItem(ref ObjectContext objectContext, KeyValuePair<object, object> keyValue, KeyValuePair<Type, Type> types)
{
var propertyKey = (PropertyKey)keyValue.Key;
objectContext.SerializerContext.WriteYaml(propertyKey, types.Key);
// Deduce expected value type from PropertyKey
objectContext.SerializerContext.WriteYaml(keyValue.Value, propertyKey.PropertyType);
}
示例8: ConvertTo
public override string ConvertTo(ref ObjectContext objectContext)
{
var attachedReference = AttachedReferenceManager.GetAttachedReference(objectContext.Instance);
if (attachedReference == null)
throw new YamlException($"Unable to extract asset reference from object [{objectContext.Instance}]");
var referenceId = IdentifiableHelper.GetId(objectContext.Instance);
return $"{referenceId}/{attachedReference.Id}:{attachedReference.Url}";
}
示例9: ConvertFrom
public override object ConvertFrom(ref ObjectContext context, Scalar fromScalar)
{
PackageVersion packageVersion;
if (!PackageVersion.TryParse(fromScalar.Value, out packageVersion))
{
throw new YamlException(fromScalar.Start, fromScalar.End, "Invalid version format. Unable to decode [{0}]".ToFormat(fromScalar.Value));
}
return packageVersion;
}
示例10: ConvertFrom
public override object ConvertFrom(ref ObjectContext context, Scalar fromScalar)
{
PackageReference packageReference;
if (!PackageReference.TryParse(fromScalar.Value, out packageReference))
{
throw new YamlException(fromScalar.Start, fromScalar.End, "Unable to decode package reference [{0}]. Expecting format GUID:LOCATION".ToFormat(fromScalar.Value));
}
return packageReference;
}
示例11: ConvertFrom
public override object ConvertFrom(ref ObjectContext context, Scalar fromScalar)
{
AssetReference assetReference;
if (!AssetReference.TryParse(context.Descriptor.Type, fromScalar.Value, out assetReference))
{
throw new YamlException(fromScalar.Start, fromScalar.End, "Unable to decode asset reference [{0}]. Expecting format GUID:LOCATION".ToFormat(fromScalar.Value));
}
return assetReference;
}
示例12: ConvertFrom
public override object ConvertFrom(ref ObjectContext objectContext, Scalar fromScalar)
{
var parameterKey = ParameterKeys.FindByName(fromScalar.Value);
if (parameterKey == null)
{
throw new YamlException(fromScalar.Start, fromScalar.End, "Unable to find registered ParameterKey [{0}]".ToFormat(fromScalar.Value));
}
return parameterKey;
}
示例13: ReadDictionaryItem
protected override KeyValuePair<object, object> ReadDictionaryItem(ref ObjectContext objectContext, KeyValuePair<Type, Type> keyValueType)
{
// Read PropertyKey
var keyResult = (PropertyKey)objectContext.SerializerContext.ReadYaml(null, keyValueType.Key);
// Deduce expected value type from PropertyKey
var valueResult = objectContext.SerializerContext.ReadYaml(null, keyResult.PropertyType);
return new KeyValuePair<object, object>(keyResult, valueResult);
}
示例14: ConvertFrom
public override object ConvertFrom(ref ObjectContext objectContext, Scalar fromScalar)
{
Guid id;
if (!Guid.TryParse(fromScalar.Value, out id))
{
throw new YamlException(fromScalar.Start, fromScalar.End, $"Unable to parse id [{fromScalar.Value}]");
}
var materialNull = new MaterialNull();
IdentifiableHelper.SetId(materialNull, id);
return materialNull;
}
示例15: ConvertFrom
public override object ConvertFrom(ref ObjectContext context, Scalar fromScalar)
{
Guid guid;
UFile location;
if (!AssetReference.TryParse(fromScalar.Value, out guid, out location))
{
throw new YamlException(fromScalar.Start, fromScalar.End, "Unable to decode asset reference [{0}]. Expecting format GUID:LOCATION".ToFormat(fromScalar.Value));
}
return AttachedReferenceManager.CreateSerializableVersion(context.Descriptor.Type, guid, location);
}