Exemple #1
0
 /// <summary>
 /// Clears the value of the specified extension
 /// </summary>
 public static void Clear <TTarget, TValue>(ref ExtensionSet <TTarget> set, RepeatedExtension <TTarget, TValue> extension) where TTarget : IExtendableMessage <TTarget>
 {
     if (set == null)
     {
         return;
     }
     set.ValuesByNumber.Remove(extension.FieldNumber);
     if (set.ValuesByNumber.Count == 0)
     {
         set = null;
     }
 }
Exemple #2
0
        /// <summary>
        /// Gets the value of the specified repeated extension, registering it if it doesn't exist
        /// </summary>
        public static RepeatedField <TValue> GetOrInitialize <TTarget, TValue>(ref ExtensionSet <TTarget> set, RepeatedExtension <TTarget, TValue> extension) where TTarget : IExtendableMessage <TTarget>
        {
            IExtensionValue value;

            if (set == null)
            {
                value = extension.CreateValue();
                set   = new ExtensionSet <TTarget>();
                set.ValuesByNumber.Add(extension.FieldNumber, value);
            }
            else
            {
                if (!set.ValuesByNumber.TryGetValue(extension.FieldNumber, out value))
                {
                    value = extension.CreateValue();
                    set.ValuesByNumber.Add(extension.FieldNumber, value);
                }
            }

            return(((RepeatedExtensionValue <TValue>)value).GetValue());
        }
Exemple #3
0
        /// <summary>
        /// Gets the value of the specified repeated extension or null if it doesn't exist in this set
        /// </summary>
        public static RepeatedField <TValue> Get <TTarget, TValue>(ref ExtensionSet <TTarget> set, RepeatedExtension <TTarget, TValue> extension) where TTarget : IExtendableMessage <TTarget>
        {
            IExtensionValue value;

            if (TryGetValue(ref set, extension, out value))
            {
                return(((RepeatedExtensionValue <TValue>)value).GetValue());
            }
            else
            {
                return(null);
            }
        }