Exemple #1
0
        public static Type ExtractType(string strType)
        {
            var typeAttrInObject = Serializer.TypeAttrInObject;

            if (strType != null &&
                strType.Length > typeAttrInObject.Length &&
                strType.Substring(0, typeAttrInObject.Length) == typeAttrInObject)
            {
                var propIndex = typeAttrInObject.Length;
                var typeName  = Serializer.UnescapeSafeString(Serializer.EatValue(strType, ref propIndex));

                var type = JsConfig.TypeFinder.Invoke(typeName);

                if (type == null)
                {
                    Tracer.Instance.WriteWarning("Could not find type: " + typeName);
                    return(null);
                }

                if (type.IsInterface || type.IsAbstract)
                {
#if !SILVERLIGHT && !MONOTOUCH && !NETCF
                    return(DynamicProxy.GetInstanceFor(type).GetType());
#else
                    throw new NotImplementedException("Deserialization from Interface and Abstract type does not supported");
#endif
                }


                return(type);
            }
            return(null);
        }
        public static Type ExtractType(string strType)
        {
            var typeAttrInObject = Serializer.TypeAttrInObject;

            if (strType != null &&
                strType.Length > typeAttrInObject.Length &&
                strType.Substring(0, typeAttrInObject.Length) == typeAttrInObject)
            {
                var propIndex = typeAttrInObject.Length;
                var typeName  = Serializer.UnescapeSafeString(Serializer.EatValue(strType, ref propIndex));

                var type = JsConfig.TypeFinder.Invoke(typeName);

                if (type == null)
                {
                    Tracer.Instance.WriteWarning("Could not find type: " + typeName);
                    return(null);
                }

#if !SILVERLIGHT && !MONOTOUCH
                if (type.IsInterface || type.IsAbstract)
                {
                    return(DynamicProxy.GetInstanceFor(type).GetType());
                }
#endif

                return(type);
            }
            return(null);
        }
        public static Type ExtractType(string strType)
        {
            if (strType != null &&
                strType.Length > TypeAttrInObject.Length &&
                strType.Substring(0, TypeAttrInObject.Length) == TypeAttrInObject)
            {
                var propIndex = TypeAttrInObject.Length;
                var typeName  = Serializer.UnescapeSafeString(Serializer.EatValue(strType, ref propIndex));
                var type      = AssemblyUtils.FindType(typeName);

                if (type == null)
                {
                    Tracer.Instance.WriteWarning("Could not find type: " + typeName);
                    return(null);
                }

                if (type.IsInterface || type.IsAbstract)
                {
                    return(DynamicProxy.GetInstanceFor(type).GetType());
                }

                return(type);
            }
            return(null);
        }
 /// <summary>
 /// Returns an instatiable class that implements the given interface class
 /// </summary>
 [CanBeNull] public Type WrapperTypeFor(Type t)
 {
     if (t == null)
     {
         return(null);
     }
     return((t.IsInterface) ? (DynamicProxy.GetInstanceFor(t)?.GetType()) : (t));
 }
Exemple #5
0
        private static void SendSampleMessage()
        {
            var senderNode = ObjectFactory.GetInstance <ISenderNode>();

            var sampleMessage = DynamicProxy.GetInstanceFor <ISampleMessage>();

            sampleMessage.Text = "sample message";

            senderNode.SendMessage(sampleMessage);
        }
Exemple #6
0
        private T Convert <T>(JToken obj)
        {
            // ReSharper disable once RedundantCast
            if (obj as object == null)
            {
                return(default(T));
            }

            // Because newtonsoft json can't handle interfaces.
            if (!typeof(T).IsInterface && !typeof(T).IsAbstract)
            {
                return(obj.ToObject <T>(_proxy.JsonSerializer));
            }
            var dummy = DynamicProxy.GetInstanceFor <T>();

            return((T)obj.ToObject(dummy.GetType(), _proxy.JsonSerializer));
        }
Exemple #7
0
        public static Type ExtractType(string strType)
        {
            var typeAttrInObject = Serializer.TypeAttrInObject;

            if (strType == null || strType.Length <= 1)
            {
                return(null);
            }

            var hasWhitespace = JsonUtils.WhiteSpaceChars.Contains(strType[1]);

            if (hasWhitespace)
            {
                var pos = strType.IndexOf('"');
                if (pos >= 0)
                {
                    strType = "{" + strType.Substring(pos);
                }
            }

            if (strType.Length > typeAttrInObject.Length &&
                strType.Substring(0, typeAttrInObject.Length) == typeAttrInObject)
            {
                var propIndex = typeAttrInObject.Length;
                var typeName  = Serializer.UnescapeSafeString(Serializer.EatValue(strType, ref propIndex));

                var type = JsConfig.TypeFinder.Invoke(typeName);

                if (type == null)
                {
                    Tracer.Instance.WriteWarning("Could not find type: " + typeName);
                    return(null);
                }

#if !SILVERLIGHT && !MONOTOUCH
                if (type.IsInterface || type.IsAbstract)
                {
                    return(DynamicProxy.GetInstanceFor(type).GetType());
                }
#endif

                return(type);
            }
            return(null);
        }
 /// <summary>
 /// Returns an instatiable class that implements the given interface class
 /// </summary>
 [CanBeNull] public Type WrapperTypeFor <T>()
 {
     return((typeof(T).IsInterface) ? (DynamicProxy.GetInstanceFor <T>()?.GetType()) : (typeof(T)));
 }