コード例 #1
0
        /// <summary>
        ///     NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="und">underlying</param>
        /// <param name="propertyName">property name</param>
        /// <param name="fragmentType">event type</param>
        /// <param name="factory">factory</param>
        /// <returns>event bean or null</returns>
        public static EventBean HandleJsonCreateFragmentSimple(
            JsonEventObjectBase und,
            string propertyName,
            EventType fragmentType,
            EventBeanTypedEventFactory factory)
        {
            if (und.TryGetNativeValue(propertyName, out var prop)) {
                if (prop == null) {
                    return null;
                }

                return factory.AdapterForTypedJson(prop, fragmentType);
            }

            throw new KeyNotFoundException(propertyName);
        }
コード例 #2
0
        /// <summary>
        ///     NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="und">underlying</param>
        /// <param name="propertyName">property name</param>
        /// <param name="fragmentType">event type</param>
        /// <param name="factory">factory</param>
        /// <param name="index">index</param>
        /// <returns>event bean or null</returns>
        public static EventBean HandleJsonCreateFragmentIndexed(
            JsonEventObjectBase und,
            string propertyName,
            int index,
            EventType fragmentType,
            EventBeanTypedEventFactory factory)
        {
            if (und.TryGetNativeValue(propertyName, out var prop)) {
                if (prop is Array array) {
                    prop = CollectionUtil.ArrayValueAtIndex(array, index);
                    if (prop == null) {
                        return null;
                    }

                    return factory.AdapterForTypedJson(prop, fragmentType);
                }

                throw new InvalidOperationException(MESSAGE_VALUE_NOT_AN_ARRAY);
            }

            throw new KeyNotFoundException(propertyName);
        }
コード例 #3
0
        /// <summary>
        ///     NOTE: Code-generation-invoked method, method name and parameter order matters
        /// </summary>
        /// <param name="und">underlying</param>
        /// <param name="propertyName">property name</param>
        /// <param name="fragmentType">event type</param>
        /// <param name="factory">factory</param>
        /// <returns>event bean or null</returns>
        public static EventBean[] HandleJsonCreateFragmentArray(
            JsonEventObjectBase und,
            string propertyName,
            EventType fragmentType,
            EventBeanTypedEventFactory factory)
        {
            if (und.TryGetNativeValue(propertyName, out var value)) {
                if (value == null) {
                    return null;
                }

                var asArray = (Array) value;
                var len = asArray.Length;
                var events = new EventBean[len];
                for (var i = 0; i < len; i++) {
                    object item = asArray.GetValue(i);
                    events[i] = factory.AdapterForTypedJson(item, fragmentType);
                }

                return events;
            }
            
            throw new KeyNotFoundException(propertyName);
        }