コード例 #1
0
ファイル: ResourceConfig.cs プロジェクト: retsimx/Bridge
 public void Prepare(ResourceConfigItem @default, ResourceConfigItem[] embedItems, ResourceConfigItem[] extractItems)
 {
     this.@default     = @default;
     this.extractItems = extractItems;
     this.embedItems   = embedItems;
     this.IsPrepared   = true;
 }
コード例 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            ResourceConfigItem[] items = null;

            if (reader.TokenType == JsonToken.Boolean)
            {
                // Check if the resource setting format used is "resources": true/false
                var inject = serializer.Deserialize <bool>(reader);

                items = new ResourceConfigItem[]
                {
                    new ResourceConfigItem()
                    {
                        Inject = inject
                    }
                };
            }
            else if (reader.TokenType == JsonToken.StartArray)
            {
                // Check if the resource setting format used is "resources": [ {} ]
                items = serializer.Deserialize <ResourceConfigItem[]>(reader);
            }
            else if (reader.TokenType == JsonToken.Null || reader.TokenType == JsonToken.None)
            {
                return(existingValue);
            }
            else
            {
                throw new JsonReaderException(
                          string.Format(
                              Messages.Exceptions.ERROR_CONFIG_DESERIALIZATION_NODE,
                              "Resources. It should be either bool value false/true or an array of objects [{ ... }].")
                          );
            }

            var resourceConfig = existingValue as ResourceConfig;

            resourceConfig.Items = items;

            return(resourceConfig);
        }
コード例 #3
0
ファイル: ResourceConfig.cs プロジェクト: retsimx/Bridge
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var resourceConfig = existingValue as ResourceConfig;

            ResourceConfigItem[] items = null;

            var failed = false;

            try
            {
                // Check if the resource setting format used is "resources": true/false
                // This case has low possibility
                // but to have a more meaningful exception details for the second case (below)
                // it is done at first
                var inject = serializer.Deserialize <bool>(reader);

                items = new ResourceConfigItem[]
                {
                    new ResourceConfigItem()
                    {
                        Inject = inject
                    }
                };
            }
            catch (JsonSerializationException)
            {
                failed = true;
            }

            if (failed)
            {
                // Check if the resource setting format used is "resources": [ {} ]
                items = serializer.Deserialize <ResourceConfigItem[]>(reader);
            }

            resourceConfig.Items = items;

            return(resourceConfig);
        }