Akka.Interfaced.InterfacedObserver.Create C# (CSharp) Method

Create() public static method

public static Create ( Type type ) : InterfacedObserver
type System.Type
return InterfacedObserver
        public static InterfacedObserver Create(Type type)
        {
            if (type.IsInterface)
            {
                // Namespace.IExampleObserver -> Namespace.ExampleObserver
                var proxyTypeName = (type.Namespace.Length > 0 ? type.Namespace + "." : "") + type.Name.Substring(1);
                var proxyType = type.Assembly.GetType(proxyTypeName);
                if (proxyType != null && proxyType.IsGenericType)
                    proxyType = proxyType.MakeGenericType(type.GetGenericArguments());
                if (proxyType == null || proxyType.BaseType != typeof(InterfacedObserver))
                    throw new ArgumentException("Cannot resolve the observer type from " + type.FullName);

                var proxy = Activator.CreateInstance(proxyType);
                return (InterfacedObserver)proxy;
            }
            else if (type.IsClass)
            {
                // Namespace.ExampleObserver
                if (type.BaseType != typeof(InterfacedObserver))
                    throw new ArgumentException("Cannot create observer with " + type.FullName);

                var proxy = Activator.CreateInstance(type);
                return (InterfacedObserver)proxy;
            }
            else
            {
                throw new ArgumentException("Cannot create observer from " + type.FullName);
            }
        }
    }

Usage Example

        public static NotificationMessage Notification <T>(Action <T> action)
            where T : IInterfacedObserver
        {
            var channel  = new SinkNotificationChannel();
            var observer = InterfacedObserver.Create(typeof(T));

            observer.Channel = channel;
            action((T)(object)observer);
            return(channel.Message);
        }
All Usage Examples Of Akka.Interfaced.InterfacedObserver::Create