/// <summary> /// Converts this grain to a <c>GrainReference</c> /// </summary> /// <param name="grain">The grain to convert.</param> /// <returns>A <c>GrainReference</c> for this grain.</returns> public static GrainReference AsReference(this Runtime.IAddressable grain) { var reference = grain as Runtime.GrainReference; // When called against an instance of a grain reference class, do nothing if (reference != null) { return(reference); } var grainBase = grain as Grain; if (grainBase != null) { return(((Grain)grain).GrainReference); } var systemTarget = grain as ISystemTargetBase; if (systemTarget != null) { return(GrainReference.FromGrainId(systemTarget.GrainId, null, systemTarget.Silo)); } throw new OrleansException(String.Format("AsReference has been called on an unexpected type: {0}.", grain.GetType().FullName)); }
/// <summary> /// Casts a grain to a specific grain interface. /// </summary> /// <typeparam name="TGrainInterface">The type of the grain interface.</typeparam> /// <param name="grain">The grain to cast.</param> public static TGrainInterface Cast <TGrainInterface>(this Runtime.IAddressable grain) { return(GrainFactory.Cast <TGrainInterface>(grain)); }
/// <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 Runtime.IAddressable grain) { return(GrainFactory.Cast <TGrainInterface>(grain.AsWeaklyTypedReference())); }