public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("@#IModel");
     writer.WriteValue("0");
     if (_writeTypeInfo)
     {
         writer.WritePropertyName("__type");
         var valueType = value.GetType();
         if (TypeCacheUtils.IsGeneratedType(valueType))
         {
             valueType = valueType.BaseType;
         }
         if (valueType != null)
         {
             var assemblyQualifiedName = valueType.AssemblyQualifiedName;
             writer.WriteValue(assemblyQualifiedName);
         }
     }
     foreach (PropertyInfo prop in value.GetType().GetProperties())
     {
         if (TypeCacheUtils.IsExcludedProperty(prop))
         {
             continue;
         }
         //This check might be innecessary if we are serializing Deltas because the delta should not include the UniqueID
         if (!_writeUniqueId && string.Equals(prop.Name, "UniqueID"))
         {
             continue;
         }
         writer.WritePropertyName(prop.Name);
         serializer.Serialize(writer, prop.GetValue(value, null));
     }
     writer.WriteEndObject();
 }
Ejemplo n.º 2
0
 public static void AddToTypeContractorCache(Type t)
 {
     if (SHORTENTYPENAME)
     {
         lock (SyncTypeTables)
         {
             if (TypeCacheUtils.IsGeneratedType(t))
             {
                 //We will map the intercept types to their base types
                 //This typecontractor cache is used for serialization
                 //We do not need to know the intercepted type
                 var interceptedType = t;
                 TypeCacheUtils.GetOriginalType(ref t);
                 string currentKey;
                 if (!typeContractorReverse.TryGetValue(t, out currentKey))
                 {
                     AddToTypeContractorCache(t);
                     currentKey = typeContractorReverse[t];
                 }
                 typeContractorReverse.Add(interceptedType, currentKey);
             }
             else
             {
                 string key = typeContractorForward.Count.ToBase95ToString(PADDEDCONTRACTEDTYPENAME);
                 if (key.Length == 1)
                 {
                     key += '~';                   //by now the size is 2 then only add one char '~'
                 }
                 typeContractorForward.Add(key, t);
                 typeContractorReverse.Add(t, key);
             }
         }
     }
 }
 public override JsonContract ResolveContract(Type type)
 {
     //We do not want two different contracts for the proxy type and the actual type
     if (TypeCacheUtils.IsGeneratedType(type))
     {
         TypeCacheUtils.GetOriginalType(ref type);
     }
     return(base.ResolveContract(type));
 }
 public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
 {
     //var longAssemblyName = serializedType.Assembly.FullName;
     if (TypeCacheUtils.IsGeneratedType(serializedType))
     {
         serializedType = serializedType.BaseType;
     }
     TypeCacheUtils.AssemblyQualifiedNameCache(serializedType, out assemblyName, out typeName);
 }
Ejemplo n.º 5
0
        public static int GetModelTypedInt(Type type)
        {
            if (TypeCacheUtils.IsGeneratedType(type))
            {
                type = type.BaseType;
            }
            int mappedType = 0;

            ClientSideMappingInfo.TryGetValue(type, out mappedType);
            return(mappedType);
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            writer.WriteStartObject();
            writer.WritePropertyName("$type");
            var valueType = value.GetType();

            if (TypeCacheUtils.IsGeneratedType(valueType))
            {
                valueType = valueType.BaseType;
            }
            if (valueType != null)
            {
                var assemblyQualifiedName = valueType.AssemblyQualifiedName;
                writer.WriteValue(assemblyQualifiedName);
            }
            var viewmodel = (IStateObject)value.GetPropertyValue("ViewModel");
            var uid       = viewmodel.UniqueID;

            writer.WritePropertyName("UniqueID");
            writer.WriteValue(uid);
            writer.WriteEndObject();
        }