Esempio n. 1
0
        public static string GetEntityId <T>(T entity)
        {
            if (entity is Dictionary <string, object> )
            {
                object untypedDictionary = entity;
                Dictionary <string, object> dictionary = (Dictionary <string, object>)untypedDictionary;
                return((string)dictionary[DEFAULT_OBJECT_ID_PROPERTY_NAME_JAVA_STYLE]);
            }

            try
            {
                Type entityType = entity.GetType();

                if (entityType.Equals(typeof(BackendlessUser)))
                {
                    object entityObject = entity;
                    return(((BackendlessUser)entityObject).ObjectId);
                }

                PropertyInfo objectIdProp = entityType.GetProperty(DEFAULT_OBJECT_ID_PROPERTY_NAME_DOTNET_STYLE);

                if (objectIdProp == null)
                {
                    objectIdProp = entityType.GetProperty(DEFAULT_OBJECT_ID_PROPERTY_NAME_JAVA_STYLE);
                }

                if (objectIdProp != null)
                {
                    return(objectIdProp.GetValue(entity, null) as string);
                }

                FieldInfo objectIdField = entityType.GetField(DEFAULT_OBJECT_ID_PROPERTY_NAME_JAVA_STYLE);

                if (objectIdField == null)
                {
                    objectIdField = entityType.GetField(DEFAULT_OBJECT_ID_PROPERTY_NAME_DOTNET_STYLE);
                }

                if (objectIdField != null)
                {
                    return(objectIdField.GetValue(entity) as string);
                }

                IDictionary <string, object> underflow = UnderflowStore.GetObjectUnderflow(entity);

                if (underflow != null && underflow.ContainsKey(DEFAULT_OBJECT_ID_PROPERTY_NAME_JAVA_STYLE))
                {
                    return((string)underflow[DEFAULT_OBJECT_ID_PROPERTY_NAME_JAVA_STYLE]);
                }
            }
            catch (System.Exception)
            {
            }

            return(null);
        }
Esempio n. 2
0
        protected override void onWriteObject(object obj, string className, IDictionary objectFields, IProtocolFormatter writer)
        {
            IDictionary <string, object> underflowData = UnderflowStore.GetObjectUnderflow(obj);

            if (underflowData != null)
            {
                int lastIndex = className.LastIndexOf('.');

                if (lastIndex > -1)
                {
                    className = className.Substring(lastIndex + 1);
                }

                foreach (string key in underflowData.Keys)
                {
                    if (!objectFields.Contains(key) && underflowData[key] != null)
                    {
                        objectFields[key] = underflowData[key];
                    }
                }
            }

            if (!className.StartsWith("flex.messaging.messages") && !className.StartsWith("com.backendless"))
            {
                if (objectFields.Contains("___class"))
                {
                    className = (String)objectFields["___class"];
                }
                else
                {
                    int dotIndex = className.LastIndexOf('+');

                    if (dotIndex == -1)
                    {
                        dotIndex = className.LastIndexOf('.');
                    }

                    if (dotIndex > -1)
                    {
                        className = className.Substring(dotIndex + 1);
                    }

                    objectFields.Add("___class", className);
                }

                className = null;
            }

            writer.GetObjectSerializer().WriteObject(className, objectFields, writer);
        }