/// <summary>
 /// Injects the introduced field.
 /// </summary>
 /// <param name="advice">The advice.</param>
 /// <param name="adviceMemberInfo">The member information.</param>
 /// <param name="advisedType">Type of the advised.</param>
 /// <exception cref="System.InvalidOperationException">Internal error, can not find matching introduced field</exception>
 private static void InjectIntroducedField(IAdvice advice, MemberInfo adviceMemberInfo, Type advisedType)
 {
     adviceMemberInfo.SetValue(advice, Activator.CreateInstance(adviceMemberInfo.GetMemberType(), advice, adviceMemberInfo));
 }
        public static T[] GetAttributesAndPropertyAttributesInterface <T>(this System.Reflection.MemberInfo member,
                                                                          bool inherit = false)
        {
            if (!typeof(T).IsInterface)
            {
                throw new ArgumentException($"{typeof(T).FullName} is not an interface.");
            }
            var attributes = member.GetCustomAttributes(inherit)
                             .Where(attr => typeof(T).IsAssignableFrom(attr.GetType()))
                             .Select(attr => (T)attr)
                             .ToArray();

            var memberAttributes = GetMemberAttributes();

            return(attributes.Concat(memberAttributes).Distinct().ToArray());

            IEnumerable <T> GetMemberAttributes()
            {
                foreach (var subMember in member.GetMemberType().GetMembers(BindingFlags.Public))
                {
                    foreach (var attr in subMember.GetAttributesInterface <T>(inherit))
                    {
                        yield return(attr);
                    }
                }
            }
        }
Esempio n. 3
0
 protected object GetDynamically(MemberInfo member, object target)
 {
     var binder = Binder.GetMember(CSharpBinderFlags.None, member.Name, member.GetMemberType(),
                                                     new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) });
     var callsite = CallSite<Func<CallSite, object, object>>.Create(binder);
     return callsite.Target(callsite, target);
 }
        protected virtual bool CanBeRouteParameter(MemberInfo info)
        {
            return (info.MemberType == MemberTypes.Field || info.MemberType == MemberTypes.Property)
                   && !info.HasCustomAttribute<ExcludeFromRouteAttribute>()
                   && IsValidForRoute(info.GetMemberType());

        }
Esempio n. 5
0
        public MemberMapping(MemberInfo memberInfo,  MemberAttribute memberAttribute, IEntityMapping entityMapping)
        {
            this.entity = entityMapping;

            this.memberInfo = memberInfo;

            this.memberAttribute = memberAttribute;

            this.memberType = memberInfo.GetMemberType();

            if (memberAttribute is ColumnAttribute)
            {
                this.InitializeColumnAttributeMapping((ColumnAttribute)memberAttribute);
            }
            else if (memberAttribute is AssociationAttribute)
            {
                var isEnumerableType = memberType != typeof(string) &&
                                       memberType != typeof(byte[]) &&
                                       typeof(IEnumerable).IsAssignableFrom(memberType);

                this.isRelationship = true;

                this.InitializeAssociationAttributeMapping((AssociationAttribute)memberAttribute, isEnumerableType);
            }
        }
Esempio n. 6
0
        internal MemberMapping(MemberInfo member, MemberAttribute attribute, EntityMapping entity)
        {
            this.member = member;
            this.entity = entity;

            memberType = member.GetMemberType();
            var isEnumerableType = memberType != Types.String
                && memberType != typeof(byte[])
                && Types.IEnumerable.IsAssignableFrom(memberType);

            if (attribute == null)
            {
                InitializeConversionMapping(isEnumerableType);
            }
            else
                InitializeAttributeMapping(attribute, isEnumerableType);

            getter = member.GetGetter();
            if (storageMember != null)
                setter = storageMember.GetSetter();
            else
                setter = member.GetSetter();
            if (columnName == null)
                columnName = member.Name;
        }
 public ColumnExpression(TableExpression table, string name, MemberInfo memberInfo)
     : base(ExpressionType, memberInfo.GetMemberType())
 {
     Table = table;
     Name = name;
     MemberInfo = memberInfo;
     RequestIndex = -1; // unused
 }
Esempio n. 8
0
    public MemberMap(MemberInfo member, Expression target = null, Expression self = null)
    {
      Self = self;
      Member = member;
      Target = target;
      Name = Member.Name;

      MemberType = member.GetMemberType();
    }
 public Maybe<object> ForMember(MemberInfo member, Func<object> instanceAccessor)
 {
     Func<object> propertyAccessor = () => member.Get(instanceAccessor());
     var fieldType = member.GetMemberType();
     foreach (var builder in Builders.Where(builder => builder.Key(fieldType)))
     {
         return builder.Value(member, propertyAccessor);
     }
     return new Nothing<object>();
 }
Esempio n. 10
0
		protected MetaMember (MetaType declaringType, MemberInfo member)
		{
			Precondition.Require(declaringType, () => Error.ArgumentNull("declaringType"));
			Precondition.Require(member, () => Error.ArgumentNull("member"));
			
			_declaringType = declaringType;
			_member = member;
			_type = member.GetMemberType();
			_accessor = new MetaAccessor(member);
		}
Esempio n. 11
0
        public MemberAccessor(MemberInfo memberInfo)
        {
            Require.NotNull(memberInfo, "memberInfo");

            Type = memberInfo is PropertyInfo ? MemberAccessorType.Property : MemberAccessorType.Field;
            MemberName = memberInfo.Name;
            DeclaringType = memberInfo.DeclaringType;
            MemberType = memberInfo.GetMemberType();
            Getter = memberInfo.CanRead() ? ReflectionHelpers.CreateWeakMemberGetter(memberInfo) : null;
            Setter = memberInfo.CanWrite() ? ReflectionHelpers.CreateWeakMemberSetter(memberInfo) : null;
        }
Esempio n. 12
0
		public MetaAccessor (MemberInfo member)
		{
			Precondition.Require(member, () => Error.ArgumentNull("member"));
			
			Type memberType = member.GetMemberType();
			Type deferredType = GetDeferredType(memberType);
			
			_accessor = CreateAccessor(member);
			_isDeferred = (deferredType != null);
			_type = deferredType ?? memberType;
		}
Esempio n. 13
0
 public string AssignmentBodyCode(MemberInfo idMember)
 {
     if (idMember.GetMemberType() == typeof (int))
     {
         return $"if (document.{idMember.Name} == 0) document.{idMember.Name} = _sequence.NextInt();";
     }
     else
     {
         return $"if (document.{idMember.Name} == 0) document.{idMember.Name} = _sequence.NextLong();";
     }
 }
Esempio n. 14
0
            private static string GetMemberName(System.Reflection.MemberInfo memberInfo)
            {
                var name = memberInfo.Name;

                if (memberInfo.GetMemberType() == MemberTypes.Method && name.Length > 4 && name.StartsWith("get_"))
                {
                    name = name.Substring(4, name.Length - 4);
                }

                return(name);
            }
Esempio n. 15
0
        internal static MemberInfo Create(System.Reflection.MemberInfo memberInfo, TypeInfoProvider typeInfoProvider)
        {
            switch (memberInfo.GetMemberType())
            {
            case MemberTypes.Field:
                return(new FieldInfo((System.Reflection.FieldInfo)memberInfo, typeInfoProvider));

            case MemberTypes.Constructor:
                return(new ConstructorInfo((System.Reflection.ConstructorInfo)memberInfo, typeInfoProvider));

            case MemberTypes.Property:
                return(new PropertyInfo((System.Reflection.PropertyInfo)memberInfo, typeInfoProvider));

            case MemberTypes.Method:
                return(new MethodInfo((System.Reflection.MethodInfo)memberInfo, typeInfoProvider));

            default:
                throw new Exception($"Not supported member type: {memberInfo.GetMemberType()}");
            }
        }
Esempio n. 16
0
        public string AssignmentBodyCode(MemberInfo idMember)
        {
            var member = idMember.GetMemberType() == typeof (int) ? "NextInt" : "NextLong";

            return $@"
BLOCK:if (document.{idMember.Name} == 0) 
document.{idMember.Name} = _sequence.{member}();
assigned = true;
END
BLOCK:else
assigned = false;
END
";
        }
Esempio n. 17
0
			public virtual ISqlExpression GetExpression(MemberInfo member, params ISqlExpression[] args)
			{
				return new SqlFunction(member.GetMemberType(), Name ?? member.Name, ConvertArgs(member, args)) { CanBeNull = CanBeNull };
			}
Esempio n. 18
0
        private void TryCreateCategoryAndInstanceFor(MemberInfo memberInfo)
        {
            if (ShouldCreateUiFor(memberInfo.GetMemberType(), memberInfo.Name))
            {
                
                string categoryName = GetCategoryFor(memberInfo);

                MemberCategory memberCategory = GetOrInstantiateAndAddMemberCategory(categoryName);

                InstanceMember newMember = new InstanceMember(memberInfo.Name, Instance);
                newMember.AfterSetByUi += HandleInstanceMemberSetByUi;
                newMember.BeforeSetByUi += HandleInstanceMemberBeforeSetByUi;
                newMember.Category = memberCategory;
                memberCategory.Members.Add(newMember);
            }
        }
Esempio n. 19
0
 public static object Map(this ResolutionContext context, MemberInfo member, object value)
 {
     var memberType = member.GetMemberType();
     return context.Map(value, null, value?.GetType() ?? memberType, memberType);
 }
 /// <summary>
 /// Determines if a property is different from its default value
 /// </summary>
 /// <param name="target"></param>
 /// <param name="memberInfo"></param>
 /// <returns></returns>
 protected virtual bool IsSpecified(object target, MemberInfo memberInfo)
 {
     object value = memberInfo.GetMemberValue(target);
     if (value == null)
         return false;
     if (Equals(value, TypeConvert.GetDefault(memberInfo.GetMemberType())))
         return false;
     return true;
 }
Esempio n. 21
0
            public ColumnModel(MemberInfo member)
            {
                MemberType = member.GetMemberType();
                var sourceType  = MemberType;
                AllowDBNull = sourceType.IsNullable();

                if (!AllowDBNull)
                {
                    IsEnum = sourceType.IsEnum;
                    if (IsEnum)
                        DataType = Enum.GetUnderlyingType(sourceType);
                    else
                        DataType = sourceType;
                }
                else
                {
                    sourceType =  Nullable.GetUnderlyingType(sourceType);
                    IsEnum = sourceType.IsEnum;
                    if (IsEnum)
                        DataType = Enum.GetUnderlyingType(sourceType);
                    else
                        DataType = sourceType;
                }
                ColumnName = member.Name;

                
                var getter = member.GetGetter();
                if (AllowDBNull)
                {
                    var p = MemberType.GetProperty("Value");

                    if (IsEnum)
                    {
                        SetColumnValue = (entity, row) =>
                        {
                            var v = getter(entity);
                            if (v == null)
                                row[ColumnName] = DBNull.Value;
                            else
                                row[ColumnName] = Converter.Convert(p.GetValue(v, null), DataType);
                        };
                    }
                    else
                    {
                        SetColumnValue = (entity, row) =>
                        {
                            var v = getter(entity);
                            if (v == null)
                                row[ColumnName] = DBNull.Value;
                            else
                                row[ColumnName] = p.GetValue(v, null);
                        };
                    }
                   
                }
                else
                {
                    if (DataType == Types.String)
                    {
                        AllowDBNull = true;
                        SetColumnValue = (entity, row) =>
                        {
                            var v = getter(entity);
                            row[ColumnName] = v == null ? DBNull.Value : v;
                        };
                    }
                    else
                    {
                        if(IsEnum)
                            SetColumnValue = (entity, row) => row[ColumnName] = Converter.Convert(getter(entity),DataType);
                        else
                            SetColumnValue = (entity, row) => row[ColumnName] = getter(entity);
                    }
                }
            }
Esempio n. 22
0
        public string AssignmentBodyCode(MemberInfo idMember)
        {
            var member = idMember.GetMemberType() == typeof (int) ? "NextInt" : "NextLong";

            return $"if (document.{idMember.Name} == 0) document.{idMember.Name} = _sequence.{member}();";
        }
Esempio n. 23
0
 public MappingMember(MemberInfo source, MemberInfo target)
 {
     Source = source;
     Target = target;
     TypePair = new TypePair(Source.GetMemberType(), Target.GetMemberType());
 }
Esempio n. 24
0
        public object ConvertbackValue(object value, MemberInfo member)
        {
            object convertedValue = value;
            var convertSupported = true;

            try
            {
            if (Binding.Converter != null)
            {
            //				try
                {
                    object parameter = Element;
                    if (Binding.ConverterParameter != null)
                        parameter = Binding.ConverterParameter;

                    convertedValue = Binding.Converter.ConvertBack(value, member.GetMemberType(), parameter, CultureInfo.CurrentUICulture);
                }
            //				catch (InvalidCastException) {}
            //				catch (NotSupportedException) { convertSupported = false; }
            //				catch (NotImplementedException) { convertSupported = false; }
            }

            if (convertSupported)
            {
                var typeCode = Convert.GetTypeCode(convertedValue);
                if (typeCode != TypeCode.Object && typeCode != TypeCode.Empty && typeCode != TypeCode.Int32)
                    convertedValue = Convert.ChangeType(convertedValue, member.GetMemberType());
            }
            }
            catch(FormatException)
            {
                var message = string.Format("{0} is a {1} but {2} is a {3}. Did you forget to specify an IValueConverter?", convertedValue, convertedValue.GetType(), member.Name, member.GetMemberType());
                throw new FormatException(message);
            }

            return convertedValue;
        }
Esempio n. 25
0
			public override ISqlExpression GetExpression(MemberInfo member, params ISqlExpression[] args)
			{
				return new SqlExpression(member.GetMemberType(), Name ?? member.Name, Precedence.Primary) { CanBeNull = CanBeNull };
			}
Esempio n. 26
0
 public static object Map(MemberInfo member, object value)
 {
     var memberType = member.GetMemberType();
     return Mapper.Map(value, value?.GetType() ?? memberType, memberType);
 }
Esempio n. 27
0
 public static object MapMember(this ResolutionContext context, MemberInfo member, object value, object destination)
 {
     var memberType = member.GetMemberType();
     var destValue = member.GetMemberValue(destination);
     return context.Mapper.Map(value, destValue, value?.GetType() ?? memberType, memberType, context);
 }
Esempio n. 28
0
 /// <summary>
 /// Determines whether the specified member type is introduction.
 /// </summary>
 /// <param name="memberInfo">The member information.</param>
 /// <returns></returns>
 private static Type GetIntroducedType(MemberInfo memberInfo)
 {
     var memberType = memberInfo.GetMemberType();
     if (!memberType.IsGenericType || memberType.GetGenericTypeDefinition() != typeof(IntroducedField<>))
         return null;
     return memberType.GetGenericArguments()[0];
 }
Esempio n. 29
0
 public static MemberDefinitionError Create(MemberInfo toMemberInfo, string reason)
 {
     return new MemberDefinitionError(toMemberInfo.DeclaringType, toMemberInfo.GetMemberType(), toMemberInfo.Name, reason);
 }
		public static PropertyReference New( MemberInfo member ) => new PropertyReference( member.DeclaringType, member.GetMemberType(), member.Name );
Esempio n. 31
0
 public override ISqlExpression GetExpression(MemberInfo member, params ISqlExpression[] args)
 {
     return new SqlExpression(member.GetMemberType(), Expression ?? member.Name, Precedence, ConvertArgs(member, args));
 }
Esempio n. 32
0
        private void UpdateSource(object obj, MemberInfo member, object targetValue)
        {
            bool canWrite = true;
            if (member is PropertyInfo) canWrite = ((PropertyInfo)member).CanWrite;

            if (member != null && canWrite && Binding.Mode == BindingMode.TwoWay)
            {
                try
                {
                    object convertedTargetValue = ConvertbackValue(targetValue, member);

                    convertedTargetValue = CheckAndCoerceToGenericEnumerable(member.GetMemberType(), convertedTargetValue);
                    SetValue(member, obj, convertedTargetValue);
                }
                catch (InvalidCastException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (NotImplementedException ex1)
                {
                    Console.WriteLine(ex1.Message);
                }
                catch (NotSupportedException ex2)
                {
                    Console.WriteLine(ex2.Message);
                }
            }
        }
Esempio n. 33
0
 public MappingMember(MemberInfo source, MemberInfo target)
     : this(source, target, new TypePair(source.GetMemberType(), target.GetMemberType()))
 {
 }