public static double GetInspectorOrder(MemberInfo memberInfo)
		{
			InspectorOrderAttribute attribute = memberInfo.GetAttribute<InspectorOrderAttribute>();
			if (attribute != null)
			{
				return attribute.Order;
			}
			return 1.7976931348623157E+308;
		}
 private static ConfigurationPropertyOptions GetOptions(MemberInfo mi)
 {
     var options = ConfigurationPropertyOptions.None;
     var requiredAttribute = mi.GetAttribute<RequiredAttribute>();
     if (requiredAttribute != null)
     {
         options = ConfigurationPropertyOptions.IsRequired;
     }
     return options;
 }
        public AttributedMetaAssociation(MemberInfo member, AssociationAttribute attribute, MetaDataMember metaDataMember)
        {
            _memberInfo = member;
            _associationAttribute = attribute;
            _thisMember = metaDataMember;
			// The bug described here:
			// https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=376669
			// says that under certain conditions, there's a bug where _otherMember == _thisMember
			// Not only is there no point in reproducing a MS bug, it's not as simple as simply setting _otherMember = metaDataMember
			Type otherType = _memberInfo.GetFirstInnerReturnType();
			string associationName = member.GetAttribute<AssociationAttribute>().Name;
			AttributedMetaType ownedMetaType = metaDataMember.DeclaringType.Model.GetMetaType(otherType) as AttributedMetaType;

			if ( ownedMetaType == null )
				throw new InvalidOperationException("Key in referenced table is of a different SQL MetaData provider");

			_otherMember = ownedMetaType.AssociationsLookup[otherType.GetMembers().Where(m => (AttributeNameNullCheck(m.GetAttribute<AssociationAttribute>()) == associationName) && (m != member)).Single()];
        }
		internal PrimitiveMemberInfoMetadata(MemberInfo memberInfo)
			: base(memberInfo)
		{
			Required = memberInfo.IsRequired();

			SupportLength = Type.IsOfType<string>();

			if (!SupportLength)
			{
				return;
			}

			var stringLengthAttribute = memberInfo.GetAttribute<StringLengthAttribute>();

			if (!stringLengthAttribute.IsNotNull())
			{
				return;
			}

			length = stringLengthAttribute.MaximumLength;
		}
		internal CollectionMemberInfoMetadata(MemberInfo memberInfo)
			: base(memberInfo)
		{
			Inverse = IsInverse();
			Lazy = memberInfo.GetAttribute<NotLazyAttribute>().IsNull();
		}
        static TreeNode CreateTreeNode(MemberInfo memberInfo, Func<object> getValue)
        {
            var attribute = memberInfo.GetAttribute<NodeAttribute>(true);
            if(attribute == null)
                return null;

            var value = CatchedEval(getValue);
            if(value == null)
                return null;

            var result = CreateNamedNode(value, memberInfo.Name, attribute.IconKey);

            if(memberInfo.GetAttribute<SmartNodeAttribute>(true) == null)
                return result;

            return SmartNodeAttribute.Process(result);
        }
 public EntityMemberMapping(MemberModel memberModel, ValidationAttribute attr)
 {
     Member = memberModel.Member;
     Name = memberModel.Name;
     Getter = memberModel.GetMember;
     ValidationAttribute = attr;
     var displayNameAttr = Member.GetAttribute<DisplayNameAttribute>(false);
     DisplayName = displayNameAttr != null ? displayNameAttr.DisplayName : Member.Name;
 }
Exemple #8
0
        private void RegisterMember(Type type, System.Reflection.MemberInfo m, Type mType, Func <object, object> get, Action <object, object> set)
        {
            // struct that holds access method for property/field
            MemberInfo accessor = new MemberInfo();

            accessor.Type = mType;
            accessor.Get  = get;
            accessor.Set  = set;

            if (set != null) // writeable ?
            {
                accessor.SerializeMethod = YamlSerializeMethod.Assign;
            }
            else
            {
                accessor.SerializeMethod = YamlSerializeMethod.Never;
                if (mType.IsClass)
                {
                    accessor.SerializeMethod = YamlSerializeMethod.Content;
                }
            }
            var attr1 = m.GetAttribute <YamlSerializeAttribute>();

            if (attr1 != null)     // specified
            {
                if (set == null)   // read only member
                {
                    if (attr1.SerializeMethod == YamlSerializeMethod.Assign ||
                        (mType.IsValueType && accessor.SerializeMethod == YamlSerializeMethod.Content))
                    {
                        throw new ArgumentException("{0} {1} is not writeable by {2}."
                                                    .DoFormat(mType.FullName, m.Name, attr1.SerializeMethod.ToString()));
                    }
                }
                accessor.SerializeMethod = attr1.SerializeMethod;
            }
            if (accessor.SerializeMethod == YamlSerializeMethod.Never)
            {
                return; // no need to register
            }
            if (accessor.SerializeMethod == YamlSerializeMethod.Binary)
            {
                if (!mType.IsArray)
                {
                    throw new InvalidOperationException("{0} {1} of {2} is not an array. Can not be serialized as binary."
                                                        .DoFormat(mType.FullName, m.Name, type.FullName));
                }
                if (!TypeUtils.IsPureValueType(mType.GetElementType()))
                {
                    throw new InvalidOperationException(
                              "{0} is not a pure ValueType. {1} {2} of {3} can not serialize as binary."
                              .DoFormat(mType.GetElementType(), mType.FullName, m.Name, type.FullName));
                }
            }

            // ShouldSerialize
            //      YamlSerializeAttribute(Never) => false
            //      ShouldSerializeSomeProperty => call it
            //      DefaultValueAttribute(default) => compare to it
            //      otherwise => true
            var shouldSerialize = type.GetMethod("ShouldSerialize" + m.Name,
                                                 BindingFlags.Instance | BindingFlags.NonPublic,
                                                 null, Type.EmptyTypes, new ParameterModifier[0]);

            if (shouldSerialize != null && shouldSerialize.ReturnType == typeof(bool) && accessor.ShouldSeriealize == null)
            {
                accessor.ShouldSeriealize = obj => (bool)shouldSerialize.Invoke(obj, EmptyObjectArray);
            }
            var attr2 = m.GetAttribute <DefaultValueAttribute>();

            if (attr2 != null && accessor.ShouldSeriealize == null)
            {
                var defaultValue = attr2.Value;
                if (TypeUtils.IsNumeric(defaultValue) && defaultValue.GetType() != mType)
                {
                    defaultValue = TypeUtils.CastToNumericType(defaultValue, mType);
                }
                accessor.ShouldSeriealize = obj => !TypeUtils.AreEqual(defaultValue, accessor.Get(obj));
            }
            if (accessor.ShouldSeriealize == null)
            {
                accessor.ShouldSeriealize = obj => true;
            }

            Accessors.Add(m.Name, accessor);
        }
 protected virtual ColumnAttribute GetColumnAttribute(MemberInfo memberInfo)
 {
     return memberInfo.GetAttribute<ColumnAttribute>();
 }
Exemple #10
0
        /// <summary>
        ///  获取成员元数据的 <see cref="DisplayNameAttribute"/> 特性描述信息
        /// </summary>
        /// <param name="member">成员元数据对象</param>
        /// <param name="inherit">是否搜索成员的继承链以查找描述特性</param>
        /// <returns>返回 <see cref="DisplayNameAttribute"/> 特性描述信息,如不存在则返回成员的名称</returns>
        public static string GetDisplayName(this MemberInfo member, bool inherit = false)
        {
            var desc = member.GetAttribute <DisplayNameAttribute>(inherit);

            return(desc?.DisplayName ?? member.GetDisplayAttribute()?.Name ?? member.Name);
        }
Exemple #11
0
 /// <summary>
 /// Checks if a custom attribute of the specified type applied to the specified member exists, and optionally inspects the ancestors of that member.
 /// </summary>
 /// <typeparam name="TAttribute">The type of attribute to search for.</typeparam>
 /// <param name="memberInfo"> The member to inspect.</param>
 /// <param name="inherit">true to inspect the ancestors of element; otherwise, false.</param>
 /// <returns>A custom attribute that matches attributeType, or null if no such attribute is found.</returns>
 public static bool AttributeExists <TAttribute>(this MemberInfo memberInfo, bool inherit = false) where TAttribute : System.Attribute
 {
     return(memberInfo.GetAttribute <TAttribute>(inherit) != null);
 }
Exemple #12
0
 /// <summary>
 /// Retrieves a <see cref="DisplayAttribute"/> of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member.
 /// </summary>
 /// <param name="member"> The member to inspect.</param>
 /// <param name="inherit">true to inspect the ancestors of element; otherwise, false.</param>
 /// <returns>A <see cref="DisplayAttribute"/> that matches attributeType, or null if no such attribute is found.</returns>
 private static DisplayAttribute GetDisplayAttribute(this MemberInfo member, bool inherit = false)
 {
     return(member.GetAttribute <DisplayAttribute>(inherit));
 }
Exemple #13
0
        static bool CheckDumpDataAttribute(MemberInfo m)
        {
            var dda = m.GetAttribute<DumpEnabledAttribute>(true);
            if(dda != null)
                return dda.IsEnabled;

            return !IsPrivateOrDump(m);
        }
Exemple #14
0
 /// <summary>
 /// Checks if a custom attribute of the specified type applied to the specified member exists, and optionally inspects the ancestors of that member.
 /// </summary>
 /// <typeparam name="TAttribute">The type of attribute to search for.</typeparam>
 /// <param name="memberInfo"> The member to inspect.</param>
 /// <param name="inherit">true to inspect the ancestors of element; otherwise, false.</param>
 /// <returns>A custom attribute that matches attributeType, or null if no such attribute is found.</returns>
 public static bool AttributeExists <TAttribute>(this MemberInfo memberInfo, bool inherit = false) => memberInfo.GetAttribute <TAttribute>(inherit: inherit) != null;
Exemple #15
0
        /// <summary>
        ///  获取成员元数据的Description特性描述信息
        /// </summary>
        /// <param name="member">成员元数据对象</param>
        /// <param name="inherit">是否搜索成员的继承链以查找描述特性</param>
        /// <returns>返回 <see cref="DescriptionAttribute"/> 特性描述信息,如不存在则返回 null</returns>
        public static string GetDescription(this MemberInfo member, bool inherit = false)
        {
            var desc = member.GetAttribute <DescriptionAttribute>(inherit: inherit);

            return(desc?.Description ?? member.GetDisplayAttribute()?.Description ?? member.Name);
        }
Exemple #16
0
 /// <summary>
 /// Retrieves a <see cref="DisplayAttribute"/> of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member.
 /// </summary>
 /// <param name="member"> The member to inspect.</param>
 /// <param name="inherit">true to inspect the ancestors of element; otherwise, false.</param>
 /// <returns>A <see cref="DisplayAttribute"/> that matches attributeType, or null if no such attribute is found.</returns>
 private static DisplayAttribute GetDisplayAttribute(this MemberInfo member, bool inherit = false)
 => member.GetAttribute <DisplayAttribute>(inherit: inherit);