Exemple #1
0
        private void Initialize()
        {
            if (!_IsInitialized)
            {
                lock (_InitLock)
                {
                    if (!_IsInitialized)
                    {
                        var jsonObjectType = JsonUtility.GetJsonObjectType(Type);

                        // only parse json dictionary object
                        if (jsonObjectType == JsonObjectType.Dictionary)
                        {
                            foreach (var propertyInfo in Type.GetProperties().Where(x => x.CanRead && x.CanWrite &&
                                                                                    !Reflector.ContainsCustomAttribute <JsonIngoreAttribute>(x)))
                            {
                                JsonProperty jsonProperty = null;

                                var attribute = Reflector.GetCustomAttribute <JsonPropertyAttribute>(propertyInfo);
                                if (attribute == null)
                                {
                                    jsonProperty = new JsonProperty(propertyInfo, null, false);
                                }
                                else if (attribute is JsonObjectAttribute)
                                {
                                    jsonProperty = new JsonProperty(propertyInfo, attribute.Alias, true);
                                }
                                else
                                {
                                    jsonProperty = new JsonProperty(propertyInfo, attribute.Alias, false);
                                }

                                JsonProperties.TryAdd(jsonProperty.Key, jsonProperty);
                            }
                        }

                        _IsInitialized = true;
                    }
                }
            }
        }