Esempio n. 1
0
        public ReflectedType(Type type)
        {
            UnderlyingType = type;
            TypeName       = type.GetFriendlyName();
            FullTypeName   = type.FullName;
            var interfaceType = Reflector.GetInterface(type);

            if (interfaceType != null)
            {
                InterfaceType     = interfaceType;
                InterfaceTypeName = interfaceType.FullName;
            }
            IsArray      = type.IsArray;
            IsList       = Reflector.IsList(type);
            IsDictionary = Reflector.IsDictionary(type);
            IsSimpleList = Reflector.IsSimpleList(type);
            IsDataEntity = Reflector.IsDataEntity(type) || (!Reflector.IsSimpleType(type) && !IsArray && !IsList && !IsDictionary);
            Type elementType;

            IsDataEntityList = Reflector.IsDataEntityList(type, out elementType);
            ElementType      = elementType;
            if (IsDataEntityList)
            {
                IsPolymorphicList = elementType != null && elementType.IsAbstract && (!elementType.IsInterface || !Reflector.IsDataEntity(elementType));
                IsListInterface   = type.GetGenericTypeDefinition() == typeof(IList <>);
            }
            IsSimpleType      = Reflector.IsSimpleType(type);
            IsNullableType    = Reflector.IsNullableType(type);
            IsMarkerInterface = Reflector.IsMarkerInterface(type);
            HashCode          = type.GetHashCode();
            IsGenericType     = type.IsGenericType;
            IsInterface       = type.IsInterface;
            IsAnonymous       = Reflector.IsAnonymousType(type);
            IsEmitted         = Reflector.IsEmitted(type);
        }
Esempio n. 2
0
        internal static ObjectActivator InternalBind(Type interfaceType, Type objectType)
        {
            var key  = Tuple.Create(objectType, interfaceType, "Adapter");
            var type = Types.GetOrAdd(key, n =>
            {
                var isAnonymous = Reflector.IsAnonymousType(n.Item1);
                var name        = string.Format("{0}_{1}_{2}", isAnonymous ? n.Item1.Name : n.Item1.FullName, n.Item2.FullName, n.Item3);
                // creates the assembly and module.
#if NETSTANDARD
                var builder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(name), AssemblyBuilderAccess.Run);
#else
                var builder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(name), AssemblyBuilderAccess.Run);
#endif
                var module = builder.DefineDynamicModule(name);
                // create the type that is used to wrap the object given. This
                // type will also implement the interface.
                return(CreateType(objectType, name, interfaceType, module, DynamicProxyType.Adapter));
            });

            var activator = Activator.CreateDelegate(type, objectType);

            return(activator);
        }