예제 #1
0
파일: Extensions.cs 프로젝트: gfl94/Goose
        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));
        }
예제 #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>();
 }
예제 #3
0
파일: GooseProxy.cs 프로젝트: gfl94/Goose
        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));
        }