private string GetTypeId(Type type, bool explicitOnly)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(type);

            if (containerAttribute != null && !string.IsNullOrEmpty(containerAttribute.Id))
            {
                return(containerAttribute.Id);
            }

            if (explicitOnly)
            {
                return(null);
            }

            switch (UndefinedSchemaIdHandling)
            {
            case UndefinedSchemaIdHandling.UseTypeName:
                return(type.FullName);

            case UndefinedSchemaIdHandling.UseAssemblyQualifiedName:
                return(type.AssemblyQualifiedName);

            default:
                return(null);
            }
        }
        private string GetTypeId(Type type, bool explicitOnly)
        {
            string id;
            JsonContainerAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(type);

            if (cachedAttribute != null)
            {
                id = cachedAttribute.Id;
            }
            else
            {
                id = null;
            }
            if (!string.IsNullOrEmpty(id))
            {
                return(cachedAttribute.Id);
            }
            if (explicitOnly)
            {
                return(null);
            }
            Newtonsoft.Json.Schema.UndefinedSchemaIdHandling undefinedSchemaIdHandling = this.UndefinedSchemaIdHandling;
            if (undefinedSchemaIdHandling == Newtonsoft.Json.Schema.UndefinedSchemaIdHandling.UseTypeName)
            {
                return(type.FullName);
            }
            if (undefinedSchemaIdHandling != Newtonsoft.Json.Schema.UndefinedSchemaIdHandling.UseAssemblyQualifiedName)
            {
                return(null);
            }
            return(type.AssemblyQualifiedName);
        }
Exemple #3
0
        private void InitializeContract(JsonContract contract)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType);

            if (containerAttribute != null)
            {
                contract.IsReference = containerAttribute._isReference;
            }

#if !PocketPC && !SILVERLIGHT
            foreach (MethodInfo method in contract.UnderlyingType.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                Type            prevAttributeType = null;
                ParameterInfo[] parameters        = method.GetParameters();

                if (IsValidCallback(method, parameters, typeof(OnSerializingAttribute), contract.OnSerializing, ref prevAttributeType))
                {
                    contract.OnSerializing = method;
                }
                if (IsValidCallback(method, parameters, typeof(OnSerializedAttribute), contract.OnSerialized, ref prevAttributeType))
                {
                    contract.OnSerialized = method;
                }
                if (IsValidCallback(method, parameters, typeof(OnDeserializingAttribute), contract.OnDeserializing, ref prevAttributeType))
                {
                    contract.OnDeserializing = method;
                }
                if (IsValidCallback(method, parameters, typeof(OnDeserializedAttribute), contract.OnDeserialized, ref prevAttributeType))
                {
                    contract.OnDeserialized = method;
                }
            }
#endif
        }
        private string GetDescription(Type type)
        {
            string description;
            JsonContainerAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(type);

            if (cachedAttribute != null)
            {
                description = cachedAttribute.Description;
            }
            else
            {
                description = null;
            }
            if (!string.IsNullOrEmpty(description))
            {
                return(cachedAttribute.Description);
            }
            DescriptionAttribute attribute = ReflectionUtils.GetAttribute <DescriptionAttribute>(type);

            if (attribute != null)
            {
                return(attribute.Description);
            }
            return(null);
        }
        private void method_7(JsonContract jsonContract_0)
        {
            JsonContainerAttribute attribute = Class139.smethod_0(jsonContract_0.type_0);

            if (attribute != null)
            {
                jsonContract_0.IsReference = attribute.nullable_0;
            }
            else
            {
                DataContractAttribute attribute2 = Class139.smethod_5(jsonContract_0.type_0);
                if ((attribute2 != null) && attribute2.IsReference)
                {
                    jsonContract_0.IsReference = true;
                }
            }
            jsonContract_0.Converter       = this.ResolveContractConverter(jsonContract_0.type_0);
            jsonContract_0.JsonConverter_0 = JsonSerializer.smethod_1(ilist_0, jsonContract_0.type_0);
            if (Class194.smethod_6(jsonContract_0.CreatedType, true) || jsonContract_0.CreatedType.smethod_12())
            {
                jsonContract_0.DefaultCreator          = this.method_6(jsonContract_0.CreatedType);
                jsonContract_0.DefaultCreatorNonPublic = !jsonContract_0.CreatedType.smethod_12() && (Class194.smethod_7(jsonContract_0.CreatedType) == null);
            }
            this.method_8(jsonContract_0, jsonContract_0.type_0);
        }
        private void InitializeContract(JsonContract contract)
        {
            JsonContainerAttribute jsonContainerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType);

            if (jsonContainerAttribute != null)
            {
                contract.IsReference = jsonContainerAttribute._isReference;
            }
            else
            {
                DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(contract.UnderlyingType);
                if (dataContractAttribute != null && dataContractAttribute.IsReference)
                {
                    contract.IsReference = new bool?(true);
                }
            }
            contract.Converter         = this.ResolveContractConverter(contract.UnderlyingType);
            contract.InternalConverter = JsonSerializer.GetMatchingConverter(DefaultContractResolver.BuiltInConverters, contract.UnderlyingType);
            if (ReflectionUtils.HasDefaultConstructor(contract.CreatedType, true) || contract.CreatedType.IsValueType)
            {
                contract.DefaultCreator          = this.GetDefaultCreator(contract.CreatedType);
                contract.DefaultCreatorNonPublic = (!contract.CreatedType.IsValueType && ReflectionUtils.GetDefaultConstructor(contract.CreatedType) == null);
            }
            this.ResolveCallbackMethods(contract, contract.UnderlyingType);
        }
        private void InitializeContract(JsonContract contract)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType);

            if (containerAttribute != null)
            {
                contract.IsReference = containerAttribute._isReference;
            }
            else
            {
                DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(contract.UnderlyingType);
                // doesn't have a null value
                if (dataContractAttribute != null && dataContractAttribute.IsReference)
                {
                    contract.IsReference = true;
                }
            }

            contract.Converter = ResolveContractConverter(contract.UnderlyingType);

            // then see whether object is compadible with any of the built in converters
            contract.InternalConverter = JsonSerializer.GetMatchingConverter(BuiltInConverters, contract.UnderlyingType);

            if (ReflectionUtils.HasDefaultConstructor(contract.CreatedType, true) ||
                contract.CreatedType.IsValueType)
            {
                contract.DefaultCreator = GetDefaultCreator(contract.CreatedType);

                contract.DefaultCreatorNonPublic = (!contract.CreatedType.IsValueType &&
                                                    ReflectionUtils.GetDefaultConstructor(contract.CreatedType) == null);
            }

            ResolveCallbackMethods(contract, contract.UnderlyingType);
        }
        public JsonContainerAttributeInternals Internal(JsonContainerAttribute attribute)
        {
            switch (attribute.Kind)
            {
            case JsonContainerKind.Array:
            {
                return(XJsonReflection.Api.ArrayAttributes.Internal((JsonArrayAttribute)attribute));
            }

            case JsonContainerKind.Dictionary:
            {
                return(XJsonReflection.Api.DictionaryAttributes.Internal((JsonDictionaryAttribute)attribute));

                break;
            }

            case JsonContainerKind.Object:
            {
                return(XJsonReflection.Api.ObjectAttributes.Internal((JsonObjectAttribute)attribute));

                break;
            }

            default:
            {
                throw XExceptions.NotSupported.EnumerationValueIsNotValid();
            }
            }
        }
Exemple #9
0
        private string GetTitle(Type type)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute<JsonContainerAttribute>(type);

            if (containerAttribute != null && !string.IsNullOrEmpty(containerAttribute.Title))
                return containerAttribute.Title;

            return null;
        }
        private string GetTitle(Type type)
        {
            JsonContainerAttribute jsonContainerAttribute = JsonTypeReflector.GetJsonContainerAttribute(type);

            if (jsonContainerAttribute != null && !string.IsNullOrEmpty(jsonContainerAttribute.Title))
            {
                return(jsonContainerAttribute.Title);
            }
            return(null);
        }
Exemple #11
0
        private string GetDescription(Type type)
        {
            JsonContainerAttribute jsonContainerAttribute = JsonTypeReflector.GetJsonContainerAttribute(type);

            if (jsonContainerAttribute != null && !string.IsNullOrEmpty(jsonContainerAttribute.Description))
            {
                return(jsonContainerAttribute.Description);
            }
            return(ReflectionUtils.GetAttribute <DescriptionAttribute>(type)?.Description);
        }
Exemple #12
0
        private string method_2(Type type_0)
        {
            JsonContainerAttribute attribute = Class139.smethod_0(type_0);

            if ((attribute != null) && !string.IsNullOrEmpty(attribute.Title))
            {
                return(attribute.Title);
            }
            return(null);
        }
Exemple #13
0
        // Token: 0x0600118B RID: 4491 RVA: 0x00061664 File Offset: 0x0005F864
        private string GetTitle(Type type)
        {
            JsonContainerAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(type);

            if (!StringUtils.IsNullOrEmpty((cachedAttribute != null) ? cachedAttribute.Title : null))
            {
                return(cachedAttribute.Title);
            }
            return(null);
        }
Exemple #14
0
        private string GetTitle(Type type)
        {
            JsonContainerAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>((object)type);

            if (!string.IsNullOrEmpty(cachedAttribute?.Title))
            {
                return(cachedAttribute.Title);
            }
            return((string)null);
        }
Exemple #15
0
        private string GetDescription(Type type)
        {
            JsonContainerAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>((object)type);

            if (!string.IsNullOrEmpty(cachedAttribute?.Description))
            {
                return(cachedAttribute.Description);
            }
            return(ReflectionUtils.GetAttribute <DescriptionAttribute>((object)type)?.Description);
        }
        private string GetTitle(Type type, JsonProperty memberProperty)
        {
            JsonContainerAttribute containerAttribute = GetAttributeFromTypeOrProperty <JsonContainerAttribute>(type, memberProperty);

            if (!string.IsNullOrEmpty(containerAttribute?.Title))
            {
                return(containerAttribute.Title);
            }

            return(null);
        }
Exemple #17
0
        private string GetDescription(Type type)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(type);

            if (containerAttribute != null && !string.IsNullOrEmpty(containerAttribute.Description))
            {
                return(containerAttribute.Description);
            }

            return(null);
        }
Exemple #18
0
 public static NamingStrategy GetContainerNamingStrategy(JsonContainerAttribute containerAttribute)
 {
     if (containerAttribute.NamingStrategyInstance == null)
     {
         if (containerAttribute.NamingStrategyType == null)
         {
             return(null);
         }
         containerAttribute.NamingStrategyInstance = JsonTypeReflector.CreateNamingStrategyInstance(containerAttribute.NamingStrategyType, containerAttribute.NamingStrategyParameters);
     }
     return(containerAttribute.NamingStrategyInstance);
 }
        private string GetDescription(Type type, JsonProperty memberProperty)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(type);

            if (!string.IsNullOrEmpty(containerAttribute?.Description))
            {
                return(containerAttribute.Description);
            }

            AttributeHelpers.GetDescription(type, memberProperty, out string description);
            return(description);
        }
        private string GetTitle(Type type, JsonProperty memberProperty)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(type);

            if (!string.IsNullOrEmpty(containerAttribute?.Title))
            {
                return(containerAttribute.Title);
            }

            AttributeHelpers.GetDisplayName(type, memberProperty, out string displayName);
            return(displayName);
        }
Exemple #21
0
        private void InitializeContract(JsonContract contract)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(contract.UnderlyingType);

            if (containerAttribute != null)
            {
                contract.IsReference = containerAttribute._isReference;
            }
#if !PocketPC && !NET20
            else
            {
                DataContractAttribute dataContractAttribute = JsonTypeReflector.GetDataContractAttribute(contract.UnderlyingType);
                // doesn't have a null value
                if (dataContractAttribute != null && dataContractAttribute.IsReference)
                {
                    contract.IsReference = true;
                }
            }
#endif

            contract.DefaultContstructor =
                ReflectionUtils.GetDefaultConstructor(contract.CreatedType, false) ??
                ReflectionUtils.GetDefaultConstructor(contract.CreatedType, true);

            foreach (MethodInfo method in contract.UnderlyingType.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                Type            prevAttributeType = null;
                ParameterInfo[] parameters        = method.GetParameters();

#if !PocketPC && !SILVERLIGHT && !NET20
                if (IsValidCallback(method, parameters, typeof(OnSerializingAttribute), contract.OnSerializing, ref prevAttributeType))
                {
                    contract.OnSerializing = method;
                }
                if (IsValidCallback(method, parameters, typeof(OnSerializedAttribute), contract.OnSerialized, ref prevAttributeType))
                {
                    contract.OnSerialized = method;
                }
                if (IsValidCallback(method, parameters, typeof(OnDeserializingAttribute), contract.OnDeserializing, ref prevAttributeType))
                {
                    contract.OnDeserializing = method;
                }
                if (IsValidCallback(method, parameters, typeof(OnDeserializedAttribute), contract.OnDeserialized, ref prevAttributeType))
                {
                    contract.OnDeserialized = method;
                }
#endif
                if (IsValidCallback(method, parameters, typeof(OnErrorAttribute), contract.OnError, ref prevAttributeType))
                {
                    contract.OnError = method;
                }
            }
        }
Exemple #22
0
 // Token: 0x060009FA RID: 2554 RVA: 0x00009542 File Offset: 0x00007742
 public static NamingStrategy smethod_8(JsonContainerAttribute jsonContainerAttribute_0)
 {
     if (jsonContainerAttribute_0.method_0() == null)
     {
         if (jsonContainerAttribute_0.NamingStrategyType == null)
         {
             return(null);
         }
         jsonContainerAttribute_0.method_1(Class124.smethod_7(jsonContainerAttribute_0.NamingStrategyType, jsonContainerAttribute_0.NamingStrategyParameters));
     }
     return(jsonContainerAttribute_0.method_0());
 }
Exemple #23
0
        private string GetTitle(Type type)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetJsonContainerAttribute(type);

            if (containerAttribute != null && !string.IsNullOrEmpty(containerAttribute.Title))
            {
                return(containerAttribute.Title);
            }
            else
            {
                return((string)null);
            }
        }
Exemple #24
0
        /// <summary>
        /// Returns a table name for a type and accounts for table renaming
        /// via the DataContractAttribute, DataTableAttribute and/or the JsonObjectAttribute.
        /// </summary>
        /// <param name="type">
        /// The type for which to return the table name.
        /// </param>
        /// <returns>
        /// The table name.
        /// </returns>
        public virtual string ResolveTableName(Type type)
        {
            // Lookup the Mobile Services name of the Type and use that
            string name = null;

            lock (tableNameCache)
            {
                if (!this.tableNameCache.TryGetValue(type, out name))
                {
                    // By default, use the type name itself
                    name = type.Name;

                    DataContractAttribute dataContractAttribute = type.GetTypeInfo().GetCustomAttributes(typeof(DataContractAttribute), true)
                                                                  .FirstOrDefault() as DataContractAttribute;
                    if (dataContractAttribute != null)
                    {
                        if (!string.IsNullOrWhiteSpace(dataContractAttribute.Name))
                        {
                            name = dataContractAttribute.Name;
                        }
                    }

                    JsonContainerAttribute jsonContainerAttribute = type.GetTypeInfo().GetCustomAttributes(typeof(JsonContainerAttribute), true)
                                                                    .FirstOrDefault() as JsonContainerAttribute;
                    if (jsonContainerAttribute != null)
                    {
                        if (!string.IsNullOrWhiteSpace(jsonContainerAttribute.Title))
                        {
                            name = jsonContainerAttribute.Title;
                        }
                    }

                    DataTableAttribute dataTableAttribute = type.GetTypeInfo().GetCustomAttributes(typeof(DataTableAttribute), true)
                                                            .FirstOrDefault() as DataTableAttribute;
                    if (dataTableAttribute != null)
                    {
                        if (!string.IsNullOrEmpty(dataTableAttribute.Name))
                        {
                            name = dataTableAttribute.Name;
                        }
                    }

                    this.tableNameCache[type] = name;

                    // Build the JsonContract now to catch any contract errors early
                    this.CreateContract(type);
                }
            }

            return(name);
        }
Exemple #25
0
        public NamingStrategy GetContainerNamingStrategy(JsonContainerAttribute containerAttribute)
        {
            if (containerAttribute.Internal().NamingStrategyInstance == null)
            {
                if (containerAttribute.Internal().NamingStrategyType == null)
                {
                    return(null);
                }

                containerAttribute.Internal().NamingStrategyInstance = CreateNamingStrategyInstance(containerAttribute.Internal().NamingStrategyType, containerAttribute.Internal().NamingStrategyParameters);
            }

            return(containerAttribute.Internal().NamingStrategyInstance);
        }
Exemple #26
0
        internal JsonContainerContract(Type underlyingType) : base(underlyingType)
        {
            JsonContainerAttribute attribute = Class139.smethod_0(underlyingType);

            if (attribute != null)
            {
                if (attribute.ItemConverterType != null)
                {
                    this.ItemConverter = JsonConverterAttribute.smethod_0(attribute.ItemConverterType);
                }
                this.ItemIsReference           = attribute.nullable_1;
                this.ItemReferenceLoopHandling = attribute.nullable_2;
                this.ItemTypeNameHandling      = attribute.nullable_3;
            }
        }
        internal JsonContainerContract(Type underlyingType) : base(underlyingType)
        {
            JsonContainerAttribute cachedAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(underlyingType);

            if (cachedAttribute != null)
            {
                if (cachedAttribute.ItemConverterType != null)
                {
                    this.ItemConverter = JsonTypeReflector.CreateJsonConverterInstance(cachedAttribute.ItemConverterType, cachedAttribute.ItemConverterParameters);
                }
                this.ItemIsReference           = cachedAttribute._itemIsReference;
                this.ItemReferenceLoopHandling = cachedAttribute._itemReferenceLoopHandling;
                this.ItemTypeNameHandling      = cachedAttribute._itemTypeNameHandling;
            }
        }
Exemple #28
0
        private string GetDescription(Type type)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute<JsonContainerAttribute>(type);

            if (containerAttribute != null && !string.IsNullOrEmpty(containerAttribute.Description))
                return containerAttribute.Description;

#if !(DOTNET || PORTABLE40 || PORTABLE)
            DescriptionAttribute descriptionAttribute = ReflectionUtils.GetAttribute<DescriptionAttribute>(type);
            if (descriptionAttribute != null)
                return descriptionAttribute.Description;
#endif

            return null;
        }
Exemple #29
0
        internal JsonContainerContract(Type underlyingType) : base(underlyingType)
        {
            JsonContainerAttribute jsonContainerAttribute = JsonTypeReflector.GetJsonContainerAttribute(underlyingType);

            if (jsonContainerAttribute != null)
            {
                if (jsonContainerAttribute.ItemConverterType != null)
                {
                    this.ItemConverter = JsonConverterAttribute.CreateJsonConverterInstance(jsonContainerAttribute.ItemConverterType);
                }
                this.ItemIsReference           = jsonContainerAttribute._itemIsReference;
                this.ItemReferenceLoopHandling = jsonContainerAttribute._itemReferenceLoopHandling;
                this.ItemTypeNameHandling      = jsonContainerAttribute._itemTypeNameHandling;
            }
        }
        private Uri GetTypeId(Type type, bool explicitOnly)
        {
            JsonContainerAttribute containerAttribute = JsonTypeReflector.GetCachedAttribute <JsonContainerAttribute>(type);

            Uri typeId;

            if (!string.IsNullOrEmpty(containerAttribute?.Id))
            {
                typeId = new Uri(containerAttribute.Id, UriKind.RelativeOrAbsolute);
            }
            else
            {
                if (explicitOnly)
                {
                    return(null);
                }

                switch (_generator.SchemaIdGenerationHandling)
                {
                case SchemaIdGenerationHandling.TypeName:
                    typeId = new Uri(type.Name, UriKind.RelativeOrAbsolute);
                    break;

                case SchemaIdGenerationHandling.FullTypeName:
                    typeId = new Uri(type.FullName, UriKind.RelativeOrAbsolute);
                    break;

                case SchemaIdGenerationHandling.AssemblyQualifiedName:
                    typeId = new Uri(type.AssemblyQualifiedName, UriKind.RelativeOrAbsolute);
                    break;

                default:
                    return(null);
                }
            }

            // avoid id conflicts
            Uri resolvedTypeId = typeId;
            int i = 1;

            while (_typeSchemas.Any(s => s.Schema.Id == resolvedTypeId))
            {
                resolvedTypeId = new Uri(typeId.OriginalString + "-" + i, UriKind.RelativeOrAbsolute);
                i++;
            }

            return(resolvedTypeId);
        }