Exemple #1
0
        public static object As(this object source, Type targetType, params GooseTypePair[] knownTypes)
        {
            if (targetType == null)
            {
                throw new ArgumentNullException(nameof(targetType));
            }

            if (source != null && targetType.IsAssignableFrom(source.GetType()))
            {
                return(source);
            }

            var options = new GooseOptions
            {
                KnownTypes = knownTypes?.Length > 0
                    ? new HashSet <GooseTypePair>(knownTypes)
                    : new HashSet <GooseTypePair>()
            };

            if (source != null)
            {
                var selfKnownPair = GooseTypePair.Create(source.GetType(), targetType);
                options.KnownTypes.Add(selfKnownPair);
            }

            return(GooseProxy.Build(source, targetType, options));
        }
Exemple #2
0
 public GooseInterceptor(object source, Type targetType, GooseOptions options)
 {
     _source        = source;
     _targetType    = targetType;
     _options       = options;
     _knownHandlers = new Dictionary <MethodInfo, Func <object[], object> >();
     _blacklist     = new HashSet <MethodInfo>();
 }
Exemple #3
0
        public static object Build(object source, Type targetType, GooseOptions options)
        {
            var interceptor = new GooseInterceptor(source, targetType, options);

            return(ProxyGenerator.CreateInterfaceProxyWithoutTarget(targetType, new[] { typeof(IGooseTyped) }, interceptor));
        }