コード例 #1
0
ファイル: Extensible.cs プロジェクト: icprog/UcAsp.RPC
        /// <summary>
        /// Queries an extensible object for an additional (unexpected) data-field for the instance.
        /// The value returned (in "value") is the composed value after merging any duplicated content;
        /// if the value is "repeated" (a list), then use GetValues instead.
        /// </summary>
        /// <param name="type">The data-type of the field.</param>
        /// <param name="model">The model to use for configuration.</param>
        /// <param name="value">The effective value of the field, or the default value if not found.</param>
        /// <param name="instance">The extensible object to obtain the value from.</param>
        /// <param name="tag">The field identifier; the tag should not be defined as a known data-field for the instance.</param>
        /// <param name="format">The data-format to use when decoding the value.</param>
        /// <param name="allowDefinedTag">Allow tags that are present as part of the definition; for example, to query unknown enum values.</param>
        /// <returns>True if data for the field was present, false otherwise.</returns>
        public static bool TryGetValue(TypeModel model, System.Type type, IExtensible instance, int tag, DataFormat format, bool allowDefinedTag, out object value)
        {
            value = null;
            bool set = false;

            foreach (object val in ExtensibleUtil.GetExtendedValues(model, type, instance, tag, format, true, allowDefinedTag))
            {
                // expecting at most one yield...
                // but don't break; need to read entire stream
                value = val;
                set   = true;
            }

            return(set);
        }
コード例 #2
0
ファイル: Extensible.cs プロジェクト: icprog/UcAsp.RPC
        /// <summary>
        /// Queries an extensible object for an additional (unexpected) data-field for the instance.
        /// The value returned (in "value") is the composed value after merging any duplicated content;
        /// if the value is "repeated" (a list), then use GetValues instead.
        /// </summary>
        /// <typeparam name="TValue">The data-type of the field.</typeparam>
        /// <param name="value">The effective value of the field, or the default value if not found.</param>
        /// <param name="instance">The extensible object to obtain the value from.</param>
        /// <param name="tag">The field identifier; the tag should not be defined as a known data-field for the instance.</param>
        /// <param name="format">The data-format to use when decoding the value.</param>
        /// <param name="allowDefinedTag">Allow tags that are present as part of the definition; for example, to query unknown enum values.</param>
        /// <returns>True if data for the field was present, false otherwise.</returns>
        public static bool TryGetValue <TValue>(IExtensible instance, int tag, DataFormat format, bool allowDefinedTag, out TValue value)
        {
            value = default(TValue);
            bool set = false;

            foreach (TValue val in ExtensibleUtil.GetExtendedValues <TValue>(instance, tag, format, true, allowDefinedTag))
            {
                // expecting at most one yield...
                // but don't break; need to read entire stream
                value = val;
                set   = true;
            }

            return(set);
        }
コード例 #3
0
ファイル: Extensible.cs プロジェクト: icprog/UcAsp.RPC
 /// <summary>
 /// Queries an extensible object for an additional (unexpected) data-field for the instance.
 /// Each occurrence of the field is yielded separately, making this usage suitable for "repeated"
 /// (list) fields.
 /// </summary>
 /// <remarks>The extended data is processed lazily as the enumerator is iterated.</remarks>
 /// <param name="model">The model to use for configuration.</param>
 /// <param name="type">The data-type of the field.</param>
 /// <param name="instance">The extensible object to obtain the value from.</param>
 /// <param name="tag">The field identifier; the tag should not be defined as a known data-field for the instance.</param>
 /// <param name="format">The data-format to use when decoding the value.</param>
 /// <returns>An enumerator that yields each occurrence of the field.</returns>
 public static IEnumerable GetValues(TypeModel model, System.Type type, IExtensible instance, int tag, DataFormat format)
 {
     return(ExtensibleUtil.GetExtendedValues(model, type, instance, tag, format, false, false));
 }
コード例 #4
0
ファイル: Extensible.cs プロジェクト: icprog/UcAsp.RPC
 /// <summary>
 /// Queries an extensible object for an additional (unexpected) data-field for the instance.
 /// Each occurrence of the field is yielded separately, making this usage suitable for "repeated"
 /// (list) fields.
 /// </summary>
 /// <remarks>The extended data is processed lazily as the enumerator is iterated.</remarks>
 /// <typeparam name="TValue">The data-type of the field.</typeparam>
 /// <param name="instance">The extensible object to obtain the value from.</param>
 /// <param name="tag">The field identifier; the tag should not be defined as a known data-field for the instance.</param>
 /// <param name="format">The data-format to use when decoding the value.</param>
 /// <returns>An enumerator that yields each occurrence of the field.</returns>
 public static IEnumerable <TValue> GetValues <TValue>(IExtensible instance, int tag, DataFormat format)
 {
     return(ExtensibleUtil.GetExtendedValues <TValue>(instance, tag, format, false, false));
 }