Esempio n. 1
0
 public PropertyInfoItemASM(IPropertyInfo property, bool allowNullEquivalentValue)
     : base(property, allowNullEquivalentValue)
 {
     if (property.IsReadable)
     {
         getDelegate = TypeUtility.GetMemberGetDelegate(property.DeclaringType, property.Name);
     }
     if (property.IsWritable)
     {
         setDelegate = TypeUtility.GetMemberSetDelegate(property.DeclaringType, property.Name);
     }
 }
Esempio n. 2
0
 public override void RefreshAccessors(Type realType)
 {
     base.RefreshAccessors(realType);
     if (Getter != null)
     {
         getDelegate = TypeUtility.GetMemberGetDelegate(Getter.DeclaringType, Getter.Name);
     }
     if (Getter != null)
     {
         setDelegate = TypeUtility.GetMemberSetDelegate(Getter.DeclaringType, Setter.Name);
     }
     IsReadable = getDelegate != null;
     IsWritable = setDelegate != null;
 }
Esempio n. 3
0
 public MethodPropertyInfoASM(Type entityType, String propertyName, MethodInfo getter, MethodInfo setter)
     : base(entityType, propertyName, getter, setter)
 {
     if (Getter != null)
     {
         getDelegate = TypeUtility.GetMemberGetDelegate(getter.DeclaringType, getter.Name);
     }
     if (Getter != null)
     {
         setDelegate = TypeUtility.GetMemberSetDelegate(setter.DeclaringType, setter.Name);
     }
     IsReadable = getDelegate != null;
     IsWritable = setDelegate != null;
 }
Esempio n. 4
0
        public static MemberGetDelegate <MemberType> GetCachedMemberGetDelegate <MemberType>(string memberName)
        {
            if (_memberGetDelegates.ContainsKey(memberName))
            {
                return((MemberGetDelegate <MemberType>)_memberGetDelegates[memberName]);
            }

            MemberGetDelegate <MemberType> returnValue = GetMemberGetDelegate <MemberType>(memberName);

            lock (_memberGetDelegates)
            {
                _memberGetDelegates[memberName] = returnValue;
            }
            return(returnValue);
        }
Esempio n. 5
0
        GetCachedMemberGetDelegate(Type type, string memberName)
        {
            if (_memberGetDelegates.ContainsKey(memberName))
            {
                return((MemberGetDelegate)_memberGetDelegates[memberName]);
            }

            MemberGetDelegate returnValue = GetMemberGetDelegate(type, memberName);

            lock (_memberGetDelegates)
            {
                _memberGetDelegates[memberName] = returnValue;
            }
            return(returnValue);
        }
Esempio n. 6
0
            public FieldValueSource(FieldInfo field)
            {
                _field = field;

                var dm = new DynamicMethod("Get" + field.Name, typeof(TValue), new Type[] { typeof(TTarget) }, typeof(TTarget));
                var il = dm.GetILGenerator();

                // Load the instance of the object (argument 0) onto the stack
                il.Emit(OpCodes.Ldarg_0);
                // Load the value of the object's field (fi) onto the stack
                il.Emit(OpCodes.Ldfld, field);
                // return the value on the top of the stack
                il.Emit(OpCodes.Ret);

                _getter = (MemberGetDelegate)dm.CreateDelegate(typeof(MemberGetDelegate));
            }
Esempio n. 7
0
        public static MemberGetDelegate GetMemberGetDelegate(Type type, String memberName, bool tryOnly = false)
        {
            GetDelegateKey    key   = new GetDelegateKey(type, memberName);
            MemberGetDelegate value = _memberGetDelegates.Get(key);

            if (value != null)
            {
                return(value);
            }
            MemberGetDelegate delegates = GetMemberGetDelegateIntern(type, memberName, tryOnly);

            if (delegates == null)
            {
                return(null);
            }
            _memberGetDelegates.Put(key, delegates);
            return(delegates);
        }
Esempio n. 8
0
        /// <summary>
        /// 委托动态获取对象和对象值
        /// </summary>
        /// <param name="fieldInfo"></param>
        private void GetPropertyNameAndValue2(object fieldInfo)
        {
            Type type = fieldInfo.GetType();

            PropertyInfo[] propertyInfos = type.GetProperties();
            foreach (PropertyInfo item in propertyInfos)
            {
                string            name      = item.Name;
                MemberGetDelegate memberGet = (MemberGetDelegate)Delegate.CreateDelegate(typeof(Action <object, object>), item.GetGetMethod());
                var value = memberGet(fieldInfo);
                //var value = item.GetValue(fieldInfo, null);

                if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String") || value == null)
                {
                    columnInfos.Add(new ColumnInfo {
                        ColumnProperty = name, ColumnValue = value
                    });
                }
                else
                {
                    GetPropertyNameAndValue2(value);
                }
            }
        }
Esempio n. 9
0
            public PropertyEntry(Type type, String propertyName)
            {
                this.propertyName = propertyName;
                LinkedHashSet <String> propertyNames = new LinkedHashSet <String>();

                propertyNames.Add(propertyName);
                PropertyInfo prop = type.GetProperty(propertyName);

                doesModifyToBeUpdated        = !AnnotationUtil.IsAnnotationPresent <IgnoreToBeUpdated>(prop, false);
                isParentChildSetter          = AnnotationUtil.IsAnnotationPresent <ParentChild>(prop, false);
                isAddedRemovedCheckNecessary = !prop.PropertyType.IsPrimitive && ImmutableTypeSet.GetUnwrappedType(prop.PropertyType) == null &&
                                               !typeof(String).Equals(prop.PropertyType) && !prop.PropertyType.IsValueType;

                EvaluateDependentProperties(type, prop, propertyNames);

                while (true)
                {
                    int startCount = propertyNames.Count;

                    foreach (String currPropertyName in new List <String>(propertyNames))
                    {
                        PropertyInfo currProp = type.GetProperty(currPropertyName);
                        if (currProp.CanWrite)
                        {
                            continue;
                        }
                        // Is is just an evaluating property which has to be re-evaluated because of the change on the current property
                        EvaluateDependentProperties(type, currProp, propertyNames);
                    }
                    if (startCount == propertyNames.Count)
                    {
                        break;
                    }
                }
                this.propertyNames = propertyNames.ToArray();
                bool firesToBeCreatedPCE = false;

                unknownValues = CreateArrayOfValues(UNKNOWN_VALUE, this.propertyNames.Length);
                pceArgs       = new PropertyChangedEventArgs[propertyNames.Count];
                int index = 0;

                foreach (String invokedPropertyName in propertyNames)
                {
                    pceArgs[index] = new PropertyChangedEventArgs(invokedPropertyName);
                    index++;
                    firesToBeCreatedPCE |= "ToBeCreated".Equals(invokedPropertyName);
                }
                this.firesToBeCreatedPCE = firesToBeCreatedPCE;
                if (prop.CanRead)
                {
                    getDelegate = TypeUtility.GetMemberGetDelegate(type, ValueHolderIEC.GetGetterNameOfRelationPropertyWithNoInit(prop.Name), true);
                    if (getDelegate == null)
                    {
                        getDelegate = TypeUtility.GetMemberGetDelegate(type, prop.Name);
                    }
                }
                if (prop.CanWrite)
                {
                    setDelegate = TypeUtility.GetMemberSetDelegate(type, ValueHolderIEC.GetSetterNameOfRelationPropertyWithNoInit(prop.Name), true);
                    if (setDelegate == null)
                    {
                        setDelegate = TypeUtility.GetMemberSetDelegate(type, prop.Name);
                    }
                }
            }
Esempio n. 10
0
 public FieldPropertyInfoASM(Type entityType, String propertyName, FieldInfo field)
     : base(entityType, propertyName, field)
 {
     getDelegate = TypeUtility.GetMemberGetDelegate(field.DeclaringType, field.Name);
     setDelegate = TypeUtility.GetMemberSetDelegate(field.DeclaringType, field.Name);
 }
Esempio n. 11
0
        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public object Get(string name)
        {
            MemberGetDelegate memberGet = _memberGetDelegate.GetOrAdd(name, BuildDelegate);

            return(memberGet(Target));
        }
Esempio n. 12
0
 public FieldInfoItemASM(FieldInfo field, bool allowNullEquivalentValue, String propertyName)
     : base(field, allowNullEquivalentValue, propertyName)
 {
     getDelegate = TypeUtility.GetMemberGetDelegate(field.DeclaringType, field.Name);
     setDelegate = TypeUtility.GetMemberSetDelegate(field.DeclaringType, field.Name);
 }