• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# fsData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中fsData的典型用法代码示例。如果您正苦于以下问题:C# fsData类的具体用法?C# fsData怎么用?C# fsData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



fsData类属于命名空间,在下文中一共展示了fsData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: TryDeserialize

        public override fsResult TryDeserialize(fsData data, ref object instance_, Type storageType)
        {
            var instance = (IEnumerable)instance_;
            var result = fsResult.Success;

            if ((result += CheckType(data, fsDataType.Array)).Failed) return result;

            if (data.AsList.Count == 0){
                return fsResult.Success;
            }

            //Most used thus special care
            if (instance is IList){
                var args = storageType.GetGenericArguments();
                if (args.Length == 1){
                    var targetList = (IList)instance;
                    var elementType = args[0];
                    for (var i = 0; i < data.AsList.Count; i++){
                        object item = null;
                        Serializer.TryDeserialize(data.AsList[i], elementType, ref item);
                        targetList.Add(item);
                    }
                    return fsResult.Success;
                }
            }

            // For general strategy, instance may already have items in it. We will try to deserialize into
            // the existing element.
            var elementStorageType = GetElementType(storageType);
            var addMethod = GetAddMethod(storageType);
            var getMethod = storageType.GetFlattenedMethod("get_Item");
            var setMethod = storageType.GetFlattenedMethod("set_Item");
            if (setMethod == null) TryClear(storageType, instance);
            var existingSize = TryGetExistingSize(storageType, instance);

            var serializedList = data.AsList;
            for (int i = 0; i < serializedList.Count; ++i) {
                var itemData = serializedList[i];
                object itemInstance = null;
                if (getMethod != null && i < existingSize) {
                    itemInstance = getMethod.Invoke(instance, new object[] { i });
                }

                // note: We don't fail the entire deserialization even if the item failed
                var itemResult = Serializer.TryDeserialize(itemData, elementStorageType, ref itemInstance);
                result.AddMessages(itemResult);
                if (itemResult.Failed) continue;

                if (setMethod != null && i < existingSize) {
                    setMethod.Invoke(instance, new object[] { i, itemInstance });
                }
                else {
                    addMethod.Invoke(instance, new object[] { itemInstance });
                }
            }

            return result;
        }
开发者ID:nemish,项目名称:cubematters,代码行数:58,代码来源:fsIEnumerableConverter.cs


示例17: TryDeserialize

		public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType)
		{
            int index = -1;
            var result = Serializer.TryDeserialize<int>(data, ref index);
            if (index == -1)
                throw new InvalidOperationException("Error deserializing Unity object of type " + storageType + ". Index shouldn't be -1. Message: " + result.FormattedMessages);
            instance = serializedObjects[index];
			return fsResult.Success;
		}
开发者ID:srndpty,项目名称:VFW,代码行数:9,代码来源:UnityObjectConverter.cs


示例18: TrySerialize

        public override fsResult TrySerialize(object instance_, out fsData serialized, Type storageType)
        {
            serialized = fsData.Null;

            var result = fsResult.Success;

            var instance = (IDictionary)instance_;

            Type keyStorageType, valueStorageType;
            GetKeyValueTypes(instance.GetType(), out keyStorageType, out valueStorageType);

            // No other way to iterate dictionaries and still have access to the
            // key/value info
            IDictionaryEnumerator enumerator = instance.GetEnumerator();

            bool allStringKeys = true;
            var serializedKeys = new List<fsData>(instance.Count);
            var serializedValues = new List<fsData>(instance.Count);
            while (enumerator.MoveNext()) {
                fsData keyData, valueData;
                if ((result += Serializer.TrySerialize(keyStorageType, enumerator.Key, out keyData)).Failed) return result;
                if ((result += Serializer.TrySerialize(valueStorageType, enumerator.Value, out valueData)).Failed) return result;

                serializedKeys.Add(keyData);
                serializedValues.Add(valueData);

                allStringKeys &= keyData.IsString;
            }

            if (allStringKeys) {
                serialized = fsData.CreateDictionary();
                var serializedDictionary = serialized.AsDictionary;

                for (int i = 0; i < serializedKeys.Count; ++i) {
                    fsData key = serializedKeys[i];
                    fsData value = serializedValues[i];
                    serializedDictionary[key.AsString] = value;
                }
            }
            else {
                serialized = fsData.CreateList(serializedKeys.Count);
                var serializedList = serialized.AsList;

                for (int i = 0; i < serializedKeys.Count; ++i) {
                    fsData key = serializedKeys[i];
                    fsData value = serializedValues[i];

                    var container = new Dictionary<string, fsData>();
                    container["Key"] = key;
                    container["Value"] = value;
                    serializedList.Add(new fsData(container));
                }
            }

            return result;
        }
开发者ID:hymerman,项目名称:fullserializer,代码行数:56,代码来源:fsDictionaryConverter.cs


示例19: BuildCompressedString

        private static void BuildCompressedString(fsData data, TextWriter stream)
        {
            switch (data.Type) {
                case fsDataType.Null:
                    stream.Write("null");
                    break;

                case fsDataType.Boolean:
                    if (data.AsBool) stream.Write("true");
                    else stream.Write("false");
                    break;

                case fsDataType.Double:
                    // doubles must *always* include a decimal
                    stream.Write(ConvertDoubleToString(data.AsDouble));
                    break;

                case fsDataType.Int64:
                    stream.Write(data.AsInt64);
                    break;

                case fsDataType.String:
                    stream.Write('"');
                    stream.Write(EscapeString(data.AsString));
                    stream.Write('"');
                    break;

                case fsDataType.Object: {
                        stream.Write('{');
                        bool comma = false;
                        foreach (var entry in data.AsDictionary) {
                            if (comma) stream.Write(',');
                            comma = true;
                            stream.Write('"');
                            stream.Write(entry.Key);
                            stream.Write('"');
                            stream.Write(":");
                            BuildCompressedString(entry.Value, stream);
                        }
                        stream.Write('}');
                        break;
                    }

                case fsDataType.Array: {
                        stream.Write('[');
                        bool comma = false;
                        foreach (var entry in data.AsList) {
                            if (comma) stream.Write(',');
                            comma = true;
                            BuildCompressedString(entry, stream);
                        }
                        stream.Write(']');
                        break;
                    }
            }
        }
开发者ID:x4maT,项目名称:fullserializer,代码行数:56,代码来源:fsJsonPrinter.cs


示例20: TryDeserialize

		public override fsResult TryDeserialize(fsData data, ref object instance, Type storageType){
			var database = Serializer.Context.Get<List<UnityEngine.Object>>();
			var index = (int)data.AsInt64;
			
			if (index >= database.Count)
				return fsResult.Warn("A Unity Object reference has not been deserialized");
			
			instance = database[index];
			return fsResult.Success;
		}
开发者ID:pangaeastudio,项目名称:vrgame-bruceli,代码行数:10,代码来源:fsUnityObjectConverter.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# function_info类代码示例发布时间:2022-05-24
下一篇:
C# frmMain类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap