Exemple #1
0
        public ContractResolver(IFactory entityFactory, IKnownSerializationTypes knowTypes)
        {
            _entityFactory = entityFactory;
            _knowTypes     = knowTypes;

            foreach (Type type in ReflectTypes().Concat(_knowTypes.GetKnownTypes()))
            {
                string typeNamespace = GetNamespace(type);
                string typeName      = GetName(type);

                _typeToNames[type] = new Tuple <string, string>(typeNamespace, typeName);

                if (_namesToType.ContainsKey(typeNamespace) == false)
                {
                    _namesToType[typeNamespace] = new Dictionary <string, Type>();
                }
                _namesToType[typeNamespace][typeName] = type;
            }
        }
		public ContractResolver(IFactory entityFactory, IKnownSerializationTypes knowTypes)
		{
			_entityFactory = entityFactory;
			_knowTypes = knowTypes;

			foreach (Type type in ReflectTypes().Concat(_knowTypes.GetKnownTypes()))
			{
				string typeNamespace = GetNamespace(type);
				string typeName = GetName(type);

				_typeToNames[type] = new Tuple<string, string>(typeNamespace, typeName);

				if (_namesToType.ContainsKey(typeNamespace) == false)
				{
					_namesToType[typeNamespace] = new Dictionary<string, Type>();
				}
				_namesToType[typeNamespace][typeName] = type;
			}
		}
Exemple #3
0
        public static T DeepClone <T>(this T obj, IKnownSerializationTypes knownTypes)
        {
            if (knownTypes == null)
            {
                throw new ArgumentNullException("knownTypes");
            }

            T   cloned     = default(T);
            var serializer = new DataContractSerializer(typeof(T), knownTypes.GetKnownTypes(), maxItemsInObjectGraph: 0x7FFF,
                                                        ignoreExtensionDataObject: false,
                                                        preserveObjectReferences: true,
                                                        dataContractSurrogate: null);

            using (var ms = new System.IO.MemoryStream())
            {
                serializer.WriteObject(ms, obj);
                ms.Seek(0, System.IO.SeekOrigin.Begin);
                cloned = (T)serializer.ReadObject(ms);
            }
            return(cloned);
        }