本文整理汇总了C#中fsData类的典型用法代码示例。如果您正苦于以下问题:C# fsData类的具体用法?C# fsData怎么用?C# fsData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
fsData类属于命名空间,在下文中一共展示了fsData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TrySerialize
public override fsResult TrySerialize(object instance_, out fsData serialized, Type storageType) {
var instance = (IEnumerable)instance_;
var result = fsResult.Success;
Type elementType = GetElementType(storageType);
serialized = fsData.CreateList(HintSize(instance));
var serializedList = serialized.AsList;
foreach (object item in instance) {
fsData itemData;
// note: We don't fail the entire deserialization even if the item failed
var itemResult = Serializer.TrySerialize(elementType, item, out itemData);
result.AddMessages(itemResult);
if (itemResult.Failed) continue;
serializedList.Add(itemData);
}
// Stacks iterate from back to front, which means when we deserialize we will deserialize
// the items in the wrong order, so the stack will get reversed.
if (IsStack(instance.GetType())) {
serializedList.Reverse();
}
return result;
}
示例2: TrySerialize
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType)
{
serialized = fsData.CreateDictionary();
var result = fsResult.Success;
fsMetaType metaType = fsMetaType.Get(Serializer.Config, instance.GetType());
metaType.EmitAotData();
for (int i = 0; i < metaType.Properties.Length; ++i) {
fsMetaProperty property = metaType.Properties[i];
if (property.CanRead == false) continue;
fsData serializedData;
var itemResult = Serializer.TrySerialize(property.StorageType, property.OverrideConverterType,
property.Read(instance), out serializedData);
result.AddMessages(itemResult);
if (itemResult.Failed) {
continue;
}
serialized.AsDictionary[property.JsonName] = serializedData;
}
return result;
}
示例3: TrySerialize
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
// note: IList[index] is **significantly** faster than Array.Get, so make sure we use
// that instead.
IList arr = (Array)instance;
Type elementType = storageType.GetElementType();
var result = fsResult.Success;
serialized = fsData.CreateList(arr.Count);
var serializedList = serialized.AsList;
for (int i = 0; i < arr.Count; ++i) {
object item = arr[i];
fsData serializedItem;
var itemResult = Serializer.TrySerialize(elementType, item, out serializedItem);
result.AddMessages(itemResult);
if (itemResult.Failed) continue;
serializedList.Add(serializedItem);
}
return result;
}
示例4: OnBeforeDeserializeAfterInstanceCreation
public override void OnBeforeDeserializeAfterInstanceCreation(Type storageType, object instance, ref fsData data) {
if (instance is fsISerializationCallbacks == false) {
throw new InvalidCastException("Please ensure the converter for " + storageType + " actually returns an instance of it, not an instance of " + instance.GetType());
}
((fsISerializationCallbacks)instance).OnBeforeDeserialize(storageType, ref data);
}
示例5: TryDeserialize
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
var result = fsResult.Success;
// Verify that we actually have an Object
if ((result += CheckType(data, fsDataType.Object)).Failed) {
return result;
}
fsMetaType metaType = fsMetaType.Get(storageType);
for (int i = 0; i < metaType.Properties.Length; ++i) {
fsMetaProperty property = metaType.Properties[i];
if (property.CanWrite == false) continue;
fsData propertyData;
if (data.AsDictionary.TryGetValue(property.Name, out propertyData)) {
object deserializedValue = null;
var itemResult = Serializer.TryDeserialize(propertyData, property.StorageType, ref deserializedValue);
result.AddMessages(itemResult);
if (itemResult.Failed) continue;
property.Write(instance, deserializedValue);
}
}
return result;
}
示例6: TryDeserialize
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
var result = fsResult.Success;
// Verify that we actually have an List
if ((result += CheckType(data, fsDataType.Array)).Failed) {
return result;
}
Type elementType = storageType.GetElementType();
var serializedList = data.AsList;
var list = new ArrayList(serializedList.Count);
int existingCount = list.Count;
for (int i = 0; i < serializedList.Count; ++i) {
var serializedItem = serializedList[i];
object deserialized = null;
if (i < existingCount) deserialized = list[i];
var itemResult = Serializer.TryDeserialize(serializedItem, elementType, ref deserialized);
result.AddMessages(itemResult);
if (itemResult.Failed) continue;
if (i < existingCount) list[i] = deserialized;
else list.Add(deserialized);
}
instance = list.ToArray(elementType);
return result;
}
示例7: TrySerialize
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType) {
var instanceType = instance.GetType();
if (fsConfig.Serialize64BitIntegerAsString && (instanceType == typeof(Int64) || instanceType == typeof(UInt64))) {
serialized = new fsData((string)Convert.ChangeType(instance, typeof(string)));
return fsResult.Success;
}
if (UseBool(instanceType)) {
serialized = new fsData((bool)instance);
return fsResult.Success;
}
if (UseInt64(instanceType)) {
serialized = new fsData((Int64)Convert.ChangeType(instance, typeof(Int64)));
return fsResult.Success;
}
if (UseDouble(instanceType)) {
serialized = new fsData((double)Convert.ChangeType(instance, typeof(double)));
return fsResult.Success;
}
if (UseString(instanceType)) {
serialized = new fsData((string)Convert.ChangeType(instance, typeof(string)));
return fsResult.Success;
}
serialized = null;
return fsResult.Fail("Unhandled primitive type " + instance.GetType());
}
示例8: TryDeserialize
public override fsResult TryDeserialize(fsData storage, ref object instance, Type storageType) {
var result = fsResult.Success;
if (UseBool(storageType)) {
if ((result += CheckType(storage, fsDataType.Boolean)).Succeeded) {
instance = storage.AsBool;
}
return result;
}
if (UseDouble(storageType) || UseInt64(storageType)) {
if (storage.IsDouble) {
instance = Convert.ChangeType(storage.AsDouble, storageType);
}
else if (storage.IsInt64) {
instance = Convert.ChangeType(storage.AsInt64, storageType);
}
else {
return fsResult.Fail(GetType().Name + " expected number but got " + storage.Type + " in " + storage);
}
return fsResult.Success;
}
if (UseString(storageType)) {
if ((result += CheckType(storage, fsDataType.String)).Succeeded) {
instance = storage.AsString;
}
return result;
}
return fsResult.Fail(GetType().Name + ": Bad data; expected bool, number, string, but got " + storage);
}
示例9: TrySerialize
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType)
{
var database = Serializer.Context.Get<List<UnityEngine.Object>>();
var o = instance as UnityEngine.Object;
var index = -1;
for (var i = 0; i < database.Count; i++){
if (ReferenceEquals(database[i], o)){
index = i;
break;
}
}
//this is done to avoid serializing 0 because it's default value of int and will not be printed,
//which is done for performance. Thus we always start from index 1.
if (database.Count == 0){
database.Add(null);
}
if (index <= 0){
index = database.Count;
database.Add(o);
}
serialized = new fsData(index);
return fsResult.Success;
}
示例10: Print
private static IEnumerable<string> Print(fsData data) {
if (data.IsBool) {
yield return "" + data.AsBool.ToString().ToLower() + "";
yield return " " + data.AsBool.ToString().ToLower() + "";
yield return " " + data.AsBool.ToString().ToLower() + " ";
yield return " \n" + data.AsBool.ToString().ToLower() + "\n ";
}
else if (data.IsDouble) {
yield return "" + ConvertDoubleToString(data.AsDouble) + "";
yield return " " + ConvertDoubleToString(data.AsDouble) + "";
yield return " " + ConvertDoubleToString(data.AsDouble) + " ";
yield return " \n" + ConvertDoubleToString(data.AsDouble) + "\n ";
}
else if (data.IsInt64) {
yield return "" + data.AsInt64 + "";
yield return " " + data.AsInt64 + "";
yield return " " + data.AsInt64 + " ";
yield return " \n" + data.AsInt64 + "\n ";
}
else if (data.IsNull) {
yield return "null";
yield return " null";
yield return " null ";
yield return " \nnull\n ";
}
else if (data.IsString) {
yield return "\"" + data.AsString + "\"";
yield return " \"" + data.AsString + "\"";
yield return "\"" + data.AsString + "\" ";
yield return " \"" + data.AsString + "\" ";
yield return "\n\"" + data.AsString + "\" \n ";
}
else if (data.IsList) {
foreach (string permutation in Permutations(data.AsList, 0)) {
yield return "[" + permutation + "]";
yield return " [" + permutation + "]";
yield return "[ " + permutation + "]";
yield return "[" + permutation + " ]";
yield return "[" + permutation + "] ";
yield return " \n[\n" + permutation + "\n] \n";
}
}
else if (data.IsDictionary) {
foreach (string permutation in Permutations(data.AsDictionary.ToList(), 0)) {
yield return "{" + permutation + "}";
yield return " {" + permutation + "}";
yield return "{ " + permutation + "}";
yield return "{" + permutation + " }";
yield return "{" + permutation + "} ";
yield return " \n{\n" + permutation + "\n} \n";
}
}
}
示例11: CompressedJson
/// <summary>
/// Returns the data in a relatively compressed JSON format.
/// </summary>
public static string CompressedJson(fsData data)
{
var sb = new StringBuilder();
using (var writer = new StringWriter(sb)) {
BuildCompressedString(data, writer);
return sb.ToString();
}
}
示例12: TryDeserialize
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
{
Type objectType = (Type)instance;
fsResult result = fsResult.Success;
instance = JsonUtility.FromJson(fsJsonPrinter.CompressedJson(data), objectType);
return result;
}
示例13: PrettyJson
/// <summary>
/// Returns the data in a pretty printed JSON format.
/// </summary>
public static string PrettyJson(fsData data)
{
var sb = new StringBuilder();
using (var writer = new StringWriter(sb)) {
BuildPrettyString(data, writer, 0);
return sb.ToString();
}
}
示例14: TrySerialize
public override fsResult TrySerialize(object instance, out fsData serialized, Type storageType)
{
var obj = (UnityObject)instance;
var serializationOperator = Serializer.Context.Get<ISerializationOperator>();
int id = serializationOperator.StoreObjectReference(obj);
return Serializer.TrySerialize<int>(id, out serialized);
}
示例15: TryDeserialize
public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType) {
if (data.IsString) {
instance = new Guid(data.AsString);
return fsResult.Success;
}
return fsResult.Fail("fsGuidConverter encountered an unknown JSON data type");
}