コード例 #1
0
            public IGrainMethodInvoker GetInvoker(string genericGrainType = null)
            {
                // if the grain class is non-generic
                if (cachedGenericInvokersLockObj == null)
                {
                    return(invoker ?? (invoker = (IGrainMethodInvoker)Activator.CreateInstance(baseInvokerType)));
                }
                else
                {
                    lock (cachedGenericInvokersLockObj)
                    {
                        if (cachedGenericInvokers.ContainsKey(genericGrainType))
                        {
                            return(cachedGenericInvokers[genericGrainType]);
                        }
                    }
                    var typeArgs     = TypeUtils.GenericTypeArgsFromArgsString(genericGrainType);
                    var concreteType = baseInvokerType.MakeGenericType(typeArgs);
                    var inv          = (IGrainMethodInvoker)Activator.CreateInstance(concreteType);

                    lock (cachedGenericInvokersLockObj)
                    {
                        if (!cachedGenericInvokers.ContainsKey(genericGrainType))
                        {
                            cachedGenericInvokers[genericGrainType] = inv;
                        }
                    }

                    return(inv);
                }
            }
コード例 #2
0
            public IGrainMethodInvoker GetInvoker(string genericGrainType = null)
            {
                // if the grain class is non-generic
                if (!this.isGeneric)
                {
                    return(invoker ?? (invoker = (IGrainMethodInvoker)Activator.CreateInstance(baseInvokerType)));
                }

                if (this.cachedGenericInvokers.TryGetValue(genericGrainType, out IGrainMethodInvoker result))
                {
                    return(result);
                }

                var typeArgs     = TypeUtils.GenericTypeArgsFromArgsString(genericGrainType);
                var concreteType = this.baseInvokerType.MakeGenericType(typeArgs);
                var inv          = (IGrainMethodInvoker)Activator.CreateInstance(concreteType);

                this.cachedGenericInvokers.TryAdd(genericGrainType, inv);

                return(inv);
            }