Пример #1
0
 private static void MakeDeferredAccessors(Type declaringType, MetaAccessor accessor, out MetaAccessor accessorValue, out MetaAccessor accessorDeferredValue, out MetaAccessor accessorDeferredSource)
 {
     if (accessor.Type.IsGenericType)
     {
         Type genericTypeDefinition = accessor.Type.GetGenericTypeDefinition();
         Type type2 = accessor.Type.GetGenericArguments()[0];
         if (genericTypeDefinition == typeof(Link <>))
         {
             accessorValue          = CreateAccessor(typeof(LinkValueAccessor <,>).MakeGenericType(new Type[] { declaringType, type2 }), new object[] { accessor });
             accessorDeferredValue  = CreateAccessor(typeof(LinkDefValueAccessor <,>).MakeGenericType(new Type[] { declaringType, type2 }), new object[] { accessor });
             accessorDeferredSource = CreateAccessor(typeof(LinkDefSourceAccessor <,>).MakeGenericType(new Type[] { declaringType, type2 }), new object[] { accessor });
             return;
         }
         if (typeof(EntityRef <>).IsAssignableFrom(genericTypeDefinition))
         {
             accessorValue          = CreateAccessor(typeof(EntityRefValueAccessor <,>).MakeGenericType(new Type[] { declaringType, type2 }), new object[] { accessor });
             accessorDeferredValue  = CreateAccessor(typeof(EntityRefDefValueAccessor <,>).MakeGenericType(new Type[] { declaringType, type2 }), new object[] { accessor });
             accessorDeferredSource = CreateAccessor(typeof(EntityRefDefSourceAccessor <,>).MakeGenericType(new Type[] { declaringType, type2 }), new object[] { accessor });
             return;
         }
         if (typeof(EntitySet <>).IsAssignableFrom(genericTypeDefinition))
         {
             accessorValue          = CreateAccessor(typeof(EntitySetValueAccessor <,>).MakeGenericType(new Type[] { declaringType, type2 }), new object[] { accessor });
             accessorDeferredValue  = CreateAccessor(typeof(EntitySetDefValueAccessor <,>).MakeGenericType(new Type[] { declaringType, type2 }), new object[] { accessor });
             accessorDeferredSource = CreateAccessor(typeof(EntitySetDefSourceAccessor <,>).MakeGenericType(new Type[] { declaringType, type2 }), new object[] { accessor });
             return;
         }
     }
     throw Error.UnhandledDeferredStorageType(accessor.Type);
 }
Пример #2
0
 private void InitAccessors()
 {
     if (!this.hasAccessors)
     {
         lock (this.locktarget)
         {
             if (!this.hasAccessors)
             {
                 if (this.storageMember != null)
                 {
                     this.accPrivate = MakeMemberAccessor(this.member.ReflectedType, this.storageMember, null);
                     if (this.isDeferred)
                     {
                         MakeDeferredAccessors(this.member.ReflectedType, this.accPrivate, out this.accPrivate, out this.accDefValue, out this.accDefSource);
                     }
                     this.accPublic = MakeMemberAccessor(this.member.ReflectedType, this.member, this.accPrivate);
                 }
                 else
                 {
                     this.accPublic = this.accPrivate = MakeMemberAccessor(this.member.ReflectedType, this.member, null);
                     if (this.isDeferred)
                     {
                         MakeDeferredAccessors(this.member.ReflectedType, this.accPrivate, out this.accPrivate, out this.accDefValue, out this.accDefSource);
                     }
                 }
                 this.hasAccessors = true;
             }
         }
     }
 }
Пример #3
0
 private void InitAccessors()
 {
     if (this.accPublic == null)
     {
         lock (this.lockTarget)
         {
             if (this.accPublic == null)
             {
                 this.accPublic = MakeMemberAccessor(this.member.ReflectedType, this.member);
             }
         }
     }
 }
Пример #4
0
        // Methods
        internal static MetaAccessor Create(Type objectType, PropertyInfo pi, MetaAccessor storageAccessor)
        {
            if (objectType == null)
            {
                throw Error.ArgumentNull("objectType");
            }

            if (pi == null)
            {
                throw Error.ArgumentNull("pi");
            }

            //if (storageAccessor == null)
            //    throw Error.ArgumentNull("storageAccessor");

            Delegate   delegate2    = null;
            Delegate   delegate3    = null;
            MethodInfo getMethod    = pi.GetGetMethod(true);
            var        isItemMethod = getMethod.Name == "get_Item";
            Delegate   delegate4;

            if (!isItemMethod)
            {
                Type type = typeof(DGet <,>).MakeGenericType(new Type[] { objectType, pi.PropertyType });
                delegate4 = Delegate.CreateDelegate(type, getMethod, true);
            }
            else
            {
                Type type = typeof(DItemGet <>).MakeGenericType(new Type[] { objectType });
                delegate4 = Delegate.CreateDelegate(type, getMethod, true);
            }

            if (delegate4 == null)
            {
                throw Error.CouldNotCreateAccessorToProperty(objectType, pi.PropertyType, pi);
            }
            if (pi.CanWrite)
            {
                if (!objectType.IsValueType)
                {
                    if (!isItemMethod)
                    {
                        var type = typeof(DSet <,>).MakeGenericType(new[] { objectType, pi.PropertyType });
                        delegate2 = Delegate.CreateDelegate(type, pi.GetSetMethod(true), true);
                    }
                    else
                    {
                        var type = typeof(DItemSet <>).MakeGenericType(new[] { objectType });
                        delegate2 = Delegate.CreateDelegate(type, pi.GetSetMethod(true), true);
                    }
                }
                else
                {
                    DynamicMethod method      = new DynamicMethod("xset_" + pi.Name, typeof(void), new Type[] { objectType.MakeByRefType(), pi.PropertyType }, true);
                    ILGenerator   iLGenerator = method.GetILGenerator();
                    iLGenerator.Emit(OpCodes.Ldarg_0);
                    if (!objectType.IsValueType)
                    {
                        iLGenerator.Emit(OpCodes.Ldind_Ref);
                    }
                    iLGenerator.Emit(OpCodes.Ldarg_1);
                    iLGenerator.Emit(OpCodes.Call, pi.GetSetMethod(true));
                    iLGenerator.Emit(OpCodes.Ret);
                    delegate3 = method.CreateDelegate(typeof(DRSet <,>).MakeGenericType(new Type[] { objectType, pi.PropertyType }));
                }
            }
            Type type2 = (storageAccessor != null) ? storageAccessor.Type : pi.PropertyType;
            var  t1    = typeof(Accessor <, ,>).MakeGenericType(new[] { objectType, pi.PropertyType, type2 });
            var  bf    = BindingFlags.NonPublic | BindingFlags.Instance;

            object[] args;
            if (!isItemMethod)
            {
                args = new object[] { pi, delegate4, delegate2, delegate3, storageAccessor }
            }
            ;
            else
            {
                args = new object[] { pi, delegate4, delegate2, delegate3, storageAccessor, pi.Name }
            };

            return((MetaAccessor)Activator.CreateInstance(t1, bf, null, args, null));
        }
Пример #5
0
 internal Accessor(PropertyInfo pi, DItemGet <T> dget, DItemSet <T> dset, DRItemSet <T> drset, MetaAccessor <T, V2> storage, string key)
     : this(true, pi, storage)
 {
     this.dItemGet  = dget;
     this.dItemSet  = dset;
     this.drItemSet = drset;
     this.key       = key;
 }
Пример #6
0
 // Methods
 internal Accessor(PropertyInfo pi, DGet <T, V> dget, DSet <T, V> dset, DRSet <T, V> drset, MetaAccessor <T, V2> storage)
     : this(false, pi, storage)
 {
     this.dget  = dget;
     this.dset  = dset;
     this.drset = drset;
 }
Пример #7
0
 private Accessor(bool isItem, PropertyInfo pi, MetaAccessor <T, V2> storage)
 {
     this.isItem  = isItem;
     this.pi      = pi;
     this.storage = storage;
 }
Пример #8
0
 // Methods
 internal EntitySetDefValueAccessor(MetaAccessor <T, EntitySet <V> > acc)
 {
     this.acc = acc;
 }
Пример #9
0
        private static MetaAccessor MakeMemberAccessor(Type accessorType, MemberInfo mi, MetaAccessor storage)
        {
            FieldInfo fi = mi as FieldInfo;

            if (fi != null)
            {
                return(FieldAccessor.Create(accessorType, fi));
            }
            PropertyInfo pi = (PropertyInfo)mi;

            return(PropertyAccessor.Create(accessorType, pi, storage));
        }
Пример #10
0
 // Methods
 internal LinkValueAccessor(MetaAccessor <T, Link <V> > acc)
 {
     this.acc = acc;
 }
Пример #11
0
 // Methods
 internal LinkDefSourceAccessor(MetaAccessor <T, Link <V> > acc)
 {
     this.acc = acc;
 }
Пример #12
0
 // Methods
 internal EntityRefDefSourceAccessor(MetaAccessor <T, EntityRef <V> > acc)
 {
     this.acc = acc;
 }