当前位置: 首页>>代码示例>>C#>>正文


C# fsData类代码示例

本文整理汇总了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;
        }
开发者ID:dbrizov,项目名称:fullserializer,代码行数:28,代码来源:fsIEnumerableConverter.cs

示例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;
        }
开发者ID:hymerman,项目名称:fullserializer,代码行数:26,代码来源:fsReflectedConverter.cs

示例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;
        }
开发者ID:dbrizov,项目名称:fullserializer,代码行数:26,代码来源:fsArrayConverter.cs

示例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);
        }
开发者ID:Wuzseen,项目名称:DIGM530-AWT,代码行数:7,代码来源:fsISerializationCallbacks.cs

示例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;
        }
开发者ID:huwz2015,项目名称:cloud3dview_cloudshare,代码行数:28,代码来源:fsReflectedConverter.cs

示例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;
        }
开发者ID:dbrizov,项目名称:fullserializer,代码行数:30,代码来源:fsArrayConverter.cs

示例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());
        }
开发者ID:dbrizov,项目名称:fullserializer,代码行数:31,代码来源:fsPrimitiveConverter.cs

示例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);
        }
开发者ID:srndpty,项目名称:VFW,代码行数:32,代码来源:fsPrimitiveConverter.cs

示例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;
        }
开发者ID:nemish,项目名称:cubematters,代码行数:27,代码来源:fsUnityObjectConverter.cs

示例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";
                }
            }
        }
开发者ID:dbrizov,项目名称:fullserializer,代码行数:59,代码来源:ParseTests.cs

示例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();
     }
 }
开发者ID:x4maT,项目名称:fullserializer,代码行数:11,代码来源:fsJsonPrinter.cs

示例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;
        }
开发者ID:hymerman,项目名称:fullserializer,代码行数:8,代码来源:UnityEvent_Converter.cs

示例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();
     }
 }
开发者ID:x4maT,项目名称:fullserializer,代码行数:11,代码来源:fsJsonPrinter.cs

示例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);
        }
开发者ID:JoeYarnall,项目名称:something-new,代码行数:8,代码来源:UnityObjectConverter.cs

示例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");
        }
开发者ID:dbrizov,项目名称:fullserializer,代码行数:8,代码来源:fsGuidConverter.cs


注:本文中的fsData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。