public HoconImmutableArrayBuilder AddRange(HoconValue value)
 {
     foreach (var element in value.GetArray())
     {
         Add(element.ToHoconImmutable());
     }
     return(this);
 }
        public static JToken?ToJToken(this HoconValue hoconValue, Func <JValue, JValue>?jValueHandler = null)
        {
            if (hoconValue == null)
            {
                throw new ArgumentNullException(nameof(hoconValue));
            }

            switch (hoconValue.Type)
            {
            case HoconType.Object:
                return(hoconValue.GetObject().ToJObject(jValueHandler));

            case HoconType.Array:
                return(hoconValue.GetArray().ToJArray(jValueHandler));

            case HoconType.String:
            case HoconType.Boolean:
            case HoconType.Number:
                if (hoconValue.Count == 1)
                {
                    var hoconElement = hoconValue[0];
                    if (hoconElement is HoconSubstitution hoconSubstitution)
                    {
                        return(hoconSubstitution.ResolvedValue.ToJToken(jValueHandler));
                    }

                    if (hoconElement is HoconLiteral hoconLiteral)
                    {
                        return(hoconLiteral.ToJValue(jValueHandler));
                    }

                    throw new InvalidOperationException($"Invalid Hocon element type when hocon type is Literal and has only one element: {hoconElement.GetType().FullName}");
                }
                else
                {
                    var jValue = JValue.CreateString(hoconValue.GetString());
                    if (jValueHandler != null)
                    {
                        return(jValueHandler(jValue));
                    }
                    else
                    {
                        return(jValue);
                    }
                }

            case HoconType.Empty:
#pragma warning disable S1168 // Empty arrays and collections should be returned instead of null
                return(null);

#pragma warning restore S1168 // Empty arrays and collections should be returned instead of null
            default:
                throw new InvalidOperationException($"Unknown Type: {hoconValue.Type}");
            }
        }
예제 #3
0
        private void VisitObject(HoconValue value)
        {
            switch (value.Type)
            {
            case HoconType.Object:
                VisitHoconObject(value.GetObject());
                break;

            case HoconType.Array:
                VisitArray(value.GetArray());
                break;

            case HoconType.Literal:
                VisitPrimitive(value);
                break;
            }
        }
        private void VisitObject(HoconValue value)
        {
            switch (value.Type)
            {
            case HoconType.Object:
                VisitHoconObject(value.GetObject());
                break;

            case HoconType.Array:
                VisitArray(value.GetArray());
                break;

            case HoconType.Boolean:
            case HoconType.Number:
            case HoconType.String:
                VisitPrimitive(value);
                break;
            }
        }
예제 #5
0
        private void VisitHoconValue(string path, HoconValue value)
        {
            if (value.IsEmpty)
            {
                return;
            }

            if (value.IsString())
            {
                Data.Add(path, value.GetString());
            }
            else if (value.IsObject())
            {
                VisitHoconObject(path, value.GetObject());
            }
            else if (value.IsArray())
            {
                VisitHoconArray(path, value.GetArray());
            }
        }
예제 #6
0
        private void VisitHoconValue(string path, HoconValue value)
        {
            if (value.IsEmpty)
            {
                return;
            }

            if (value.IsObject())
            {
                VisitHoconObject(path, value.GetObject());
            }
            else if (value.IsArray())
            {
                VisitHoconArray(path, value.GetArray());
            }
            else if (value.IsString())
            {
                Output.WriteLine($"{path} = {value.GetString()}");
            }
        }
        public static AnimationCurve ParseHocon(HoconValue e)
        {
            if (e.Type != HoconType.Array)
            {
                throw new ArgumentException($"The element {e} must be an array");
            }

            var keyFrames = new List <Keyframe>();
            var arr       = e.GetArray();

            foreach (var i in arr)
            {
                if (i.Type != HoconType.Array)
                {
                    throw new ArgumentException($"The element {i} inside an AnimationCurve structure must be an array", nameof(i));
                }
                var iarr = i.GetArray();
                var farr = iarr.ConvertAll((HoconValue v) => v.GetFloat());
                // key | value | inTangent | outTangent | inWeight | outWeight
                if (farr.Count == 2)
                {
                    keyFrames.Add(new Keyframe(farr[0], farr[1]));
                }
                else if (farr.Count == 4)
                {
                    keyFrames.Add(new Keyframe(farr[0], farr[1], farr[2], farr[3]));
                }
                else if (farr.Count == 6)
                {
                    keyFrames.Add(new Keyframe(farr[0], farr[1], farr[2], farr[3], farr[4], farr[5]));
                }
                else
                {
                    throw new ArgumentException($"{farr} is not a valid keyframe representation");
                }
            }

            return(new AnimationCurve(keyFrames.ToArray()));
        }
 public static object ParseShortList(HoconValue e)
 {
     return(e.GetArray().ConvertAll((HoconValue val) => (short)val.GetInt()));
 }