本文整理汇总了C#中fsData.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# fsData.ToString方法的具体用法?C# fsData.ToString怎么用?C# fsData.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fsData
的用法示例。
在下文中一共展示了fsData.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnBeforeDeserialize
public override void OnBeforeDeserialize(Type storageType, ref fsData data)
{
if (data.IsNull){
return;
}
var json = data.AsDictionary;
fsData typeData;
if (json.TryGetValue("$type", out typeData)){
var serializedType = ReflectionTools.GetType( typeData.AsString );
if (serializedType == null || serializedType == typeof(MissingConnection)){
//TargetType is either the one missing or the one previously stored as missing in the MissingConnection.
var targetFullTypeName = serializedType == null? typeData.AsString : json["missingType"].AsString;
//Try find type with same name in some other namespace that is subclass of Connection
var typeNameWithoutNS = targetFullTypeName.Split('.').LastOrDefault();
foreach(var type in ReflectionTools.GetAllTypes()){
if (type.Name == typeNameWithoutNS && type.IsSubclassOf(typeof(NodeCanvas.Framework.Connection))){
json["$type"] = new fsData(type.FullName);
return;
}
}
}
//Handle missing serialized Connection type
if (serializedType == null){
//inject the 'MissingConnection' type and store recovery serialization state.
//recoveryState and missingType are serializable members of MissingConnection.
json["recoveryState"] = new fsData( data.ToString() );
json["missingType"] = new fsData( typeData.AsString );
json["$type"] = new fsData( typeof(MissingConnection).FullName );
}
//Recover possible found serialized type
if (serializedType == typeof(MissingConnection)){
//Does the missing type now exists? If so recover
var missingType = ReflectionTools.GetType( json["missingType"].AsString );
if (missingType != null){
var recoveryState = json["recoveryState"].AsString;
var recoverJson = fsJsonParser.Parse(recoveryState).AsDictionary;
//merge the recover state *ON TOP* of the current state, thus merging only Declared recovered members
json = json.Concat( recoverJson.Where( kvp => !json.ContainsKey(kvp.Key) ) ).ToDictionary( c => c.Key, c => c.Value );
json["$type"] = new fsData( missingType.FullName );
data = new fsData( json );
}
}
}
}
示例2: OnBeforeDeserialize
public override void OnBeforeDeserialize(Type storageType, ref fsData data)
{
if (data.IsNull)
return;
var json = data.AsDictionary;
if (json.ContainsKey("$type")){
var serializedType = ReflectionTools.GetType( json["$type"].AsString );
//Handle missing serialized Node type
if (serializedType == null){
//inject the 'MissingTask' type and store recovery serialization state
json["recoveryState"] = new fsData( data.ToString() );
json["missingType"] = new fsData( json["$type"].AsString );
Type missingNodeType = null;
if (storageType == typeof(ActionTask))
missingNodeType = typeof(MissingAction);
if (storageType == typeof(ConditionTask))
missingNodeType = typeof(MissingCondition);
if (missingNodeType == null){
Debug.LogError("Can't resolve missing Task type");
return;
}
json["$type"] = new fsData( missingNodeType.FullName );
//There is no way to know DecalredOnly properties to save just them instead of the whole object since we dont have an actual type
}
//Recover possible found serialized type
if (serializedType == typeof(MissingAction) || serializedType == typeof(MissingCondition)){
//Does the missing type now exists? If so recover
var missingType = ReflectionTools.GetType( json["missingType"].AsString );
if (missingType != null){
var recoveryState = json["recoveryState"].AsString;
var recoverJson = fsJsonParser.Parse(recoveryState).AsDictionary;
//merge the recover state *ON TOP* of the current state, thus merging only Declared recovered members
json = json.Concat( recoverJson.Where( kvp => !json.ContainsKey(kvp.Key) ) ).ToDictionary( c => c.Key, c => c.Value );
json["$type"] = new fsData( missingType.FullName );
data = new fsData( json );
}
}
}
}
示例3: OnBeforeDeserialize
public override void OnBeforeDeserialize(Type storageType, ref fsData data){
if (data.IsNull)
return;
var json = data.AsDictionary;
if (json.ContainsKey("$type")){
var serializedType = ReflectionTools.GetType( json["$type"].AsString );
//Handle missing serialized Node type
if (serializedType == null){
//inject the 'MissingNode' type and store recovery serialization state
json["recoveryState"] = new fsData( data.ToString() );
json["missingType"] = new fsData( json["$type"].AsString );
json["$type"] = new fsData( typeof(MissingNode).FullName );
}
//Recover possible found serialized type
if (serializedType == typeof(MissingNode)){
//Does the missing type now exists? If so recover
var missingType = ReflectionTools.GetType( json["missingType"].AsString );
if (missingType != null){
var recoveryState = json["recoveryState"].AsString;
var recoverJson = fsJsonParser.Parse(recoveryState).AsDictionary;
//merge the recover state *ON TOP* of the current state, thus merging only Declared recovered members
json = json.Concat( recoverJson.Where( kvp => !json.ContainsKey(kvp.Key) ) ).ToDictionary( c => c.Key, c => c.Value );
json["$type"] = new fsData( missingType.FullName );
data = new fsData( json );
}
}
}
}
示例4: OnBeforeDeserialize
public override void OnBeforeDeserialize(Type storageType, ref fsData data)
{
if (data.IsNull){
return;
}
var json = data.AsDictionary;
fsData typeData;
if (json.TryGetValue("$type", out typeData)){
var serializedType = ReflectionTools.GetType( typeData.AsString );
if (serializedType == null || serializedType == typeof(MissingAction) || serializedType == typeof(MissingCondition)){
//TargetType is either the one missing or the one previously stored as missing in the MissingTask.
var targetFullTypeName = serializedType == null? typeData.AsString : json["missingType"].AsString;
//try find defined [DeserializeFrom] attribute
foreach(var type in ReflectionTools.GetAllTypes()){
var att = type.RTGetAttribute<DeserializeFromAttribute>(false);
if (att != null && att.previousTypeNames.Any(n => n == targetFullTypeName) ){
json["$type"] = new fsData( type.FullName );
return;
}
}
//Try find type with same name in some other namespace that is subclass of Task
var typeNameWithoutNS = targetFullTypeName.Split('.').LastOrDefault();
foreach(var type in ReflectionTools.GetAllTypes()){
if (type.Name == typeNameWithoutNS && type.IsSubclassOf(typeof(NodeCanvas.Framework.Task))){
json["$type"] = new fsData(type.FullName);
return;
}
}
}
//Handle missing serialized Task type
if (serializedType == null){
//Otherwise replace with a missing task.
Type missingNodeType = null;
if (storageType == typeof(ActionTask)){ missingNodeType = typeof(MissingAction); }
if (storageType == typeof(ConditionTask)){ missingNodeType = typeof(MissingCondition); }
if (missingNodeType == null){ return; }
//inject the 'MissingTask' type and store recovery serialization state.
//recoveryState and missingType are serializable members of MissingTask.
json["$type"] = new fsData( missingNodeType.FullName );
json["recoveryState"] = new fsData( data.ToString() );
json["missingType"] = new fsData( typeData.AsString );
//There is no way to know DecalredOnly properties to save just them instead of the whole object since we dont have an actual type
}
//Recover possible found serialized type
if (serializedType == typeof(MissingAction) || serializedType == typeof(MissingCondition)){
//Does the missing type now exists? If so recover
var missingType = ReflectionTools.GetType( json["missingType"].AsString );
if (missingType != null){
var recoveryState = json["recoveryState"].AsString;
var recoverJson = fsJsonParser.Parse(recoveryState).AsDictionary;
//merge the recover state *ON TOP* of the current state, thus merging only Declared recovered members
json = json.Concat( recoverJson.Where( kvp => !json.ContainsKey(kvp.Key) ) ).ToDictionary( c => c.Key, c => c.Value );
json["$type"] = new fsData( missingType.FullName );
data = new fsData( json );
}
}
}
}