Example #1
0
        /// <summary>
        /// Converts this grain to a specific grain interface.
        /// </summary>
        /// <typeparam name="TGrainInterface">The type of the grain interface.</typeparam>
        /// <param name="grain">The grain to convert.</param>
        /// <returns>A strongly typed <c>GrainReference</c> of grain interface type TGrainInterface.</returns>
        public static TGrainInterface AsReference <TGrainInterface>(this IAddressable grain)
        {
            ThrowIfNullGrain(grain);
            var grainReference = grain.AsWeaklyTypedReference();

            return(grainReference.Runtime.Convert <TGrainInterface>(grainReference));
        }
Example #2
0
        /// <summary>
        /// Converts this grain to a specific grain interface.
        /// </summary>
        /// <typeparam name="TGrainInterface">The type of the grain interface.</typeparam>
        /// <param name="grain">The grain to convert.</param>
        /// <returns>A strongly typed <c>GrainReference</c> of grain interface type TGrainInterface.</returns>
        public static TGrainInterface AsReference <TGrainInterface>(this IAddressable grain)
        {
            ThrowIfNullGrain(grain);
            var grainReference = grain.AsWeaklyTypedReference();

            return(grainReference.RuntimeClient.InternalGrainFactory.Cast <TGrainInterface>(grainReference));
        }
Example #3
0
        /// <summary>
        /// Converts this grain to a specific grain interface.
        /// </summary>
        /// <typeparam name="TGrainInterface">The type of the grain interface.</typeparam>
        /// <param name="grain">The grain to convert.</param>
        /// <returns>A strongly typed <c>GrainReference</c> of grain interface type TGrainInterface.</returns>
        public static TGrainInterface AsReference <TGrainInterface>(this IAddressable grain)
        {
            if (grain == null)
            {
                throw new ArgumentNullException("grain", "Cannot pass null as an argument to AsReference");
            }

            return(RuntimeClient.Current.InternalGrainFactory.Cast <TGrainInterface>(grain.AsWeaklyTypedReference()));
        }
        /// <summary>
        /// Converts this grain to the grain interface identified by iGrainType.
        ///
        /// Finally, it casts it to the type provided as TGrainInterface.
        /// The caller should make sure that iGrainType extends TGrainInterface.
        /// </summary>
        /// <typeparam name="TGrainInterface">output grain interface type, which
        /// iGrainType extends it</typeparam>
        /// <param name="grain">the target grain to be casted</param>
        /// <param name="gf">the grain factory object</param>
        /// <returns>A strongly typed <c>GrainReference</c> of grain interface
        /// type iGrainType casted to TGrainInterface.</returns>
        /// <returns></returns>
        public static TGrainInterface AsReference <TGrainInterface>(this IAddressable grain, IGrainFactory gf, Type iGrainType)
        {
            if (grain == null)
            {
                throw new ArgumentNullException("grain", "Cannot pass null as an argument to AsReference");
            }

            return((TGrainInterface)((GrainFactory)gf).Cast(grain.AsWeaklyTypedReference(), iGrainType));
        }
 /// <summary>
 /// Converts this grain to the grain interface identified by grainInterfaceType.
 ///
 /// Finally, it casts it to the type provided as TGrainInterface. The caller should make sure that grainInterfaceType extends TGrainInterface.
 /// </summary>
 /// <typeparam name="TGrainInterface">output grain interface type, which grainInterfaceType extends it</typeparam>
 /// <param name="grain">the target grain to be casted</param>
 /// <param name="siloIndexManager">the Index manager for this silo</param>
 /// <param name="grainInterfaceType">the grain implementation type</param>
 /// <returns>A strongly typed <c>GrainReference</c> of grain interface type <paramref name="grainInterfaceType"/> cast to TGrainInterface.</returns>
 /// <returns></returns>
 internal static TGrainInterface AsReference <TGrainInterface>(this IAddressable grain, SiloIndexManager siloIndexManager, Type grainInterfaceType) where TGrainInterface : IGrain
 => (grain != null)
         ? (TGrainInterface)siloIndexManager.GrainReferenceRuntime.Convert(grain.AsWeaklyTypedReference(), grainInterfaceType)
 : throw new ArgumentNullException("grain", "Cannot pass null as an argument to AsReference");
Example #6
0
 /// <summary>
 /// Casts the provided <paramref name="grain"/> to the provided <paramref name="interfaceType"/>.
 /// </summary>
 /// <param name="grain">The grain.</param>
 /// <param name="interfaceType">The resulting interface type.</param>
 /// <returns>A reference to <paramref name="grain"/> which implements <paramref name="interfaceType"/>.</returns>
 public static object Cast(this IAddressable grain, Type interfaceType)
 {
     return(grain.AsWeaklyTypedReference().Runtime.Convert(grain, interfaceType));
 }
Example #7
0
 /// <summary>
 /// Converts this grain to a specific grain interface.
 /// </summary>
 /// <typeparam name="TGrainInterface">The type of the grain interface.</typeparam>
 /// <param name="grain">The grain to convert.</param>
 /// <param name="siloIndexManager">the Index manager for this silo</param>
 /// <returns>A strongly typed <c>GrainReference</c> of grain interface type TGrainInterface.</returns>
 internal static TGrainInterface AsReference <TGrainInterface>(this IAddressable grain, SiloIndexManager siloIndexManager) where TGrainInterface : IGrain
 => (grain != null)
         ? siloIndexManager.Silo.Cast <TGrainInterface>(grain.AsWeaklyTypedReference())
 : throw new ArgumentNullException("grain", "Cannot pass null as an argument to AsReference");