当前位置: 首页>>代码示例>>C#>>正文


C# MemberAccessor.GetAttribute方法代码示例

本文整理汇总了C#中MemberAccessor.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MemberAccessor.GetAttribute方法的具体用法?C# MemberAccessor.GetAttribute怎么用?C# MemberAccessor.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MemberAccessor的用法示例。


在下文中一共展示了MemberAccessor.GetAttribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetIgnore

		public override bool GetIgnore(ObjectMapper mapper, MemberAccessor member, out bool isSet)
		{
			if (IsLinqObject(mapper.TypeAccessor.Type))
			{
				isSet = true;
				return member.GetAttribute<ColumnAttribute>() == null;
			}

			return base.GetIgnore(mapper, member, out isSet);
		}
开发者ID:epdumitru,项目名称:mysqlib,代码行数:10,代码来源:LinqMetadataProvider.cs

示例2: GetAssociation

        public override Association GetAssociation(TypeExtension typeExtension, MemberAccessor member)
        {
            if (member.Type.IsClass && !member.Type.FullName.StartsWith("System"))
            {
                bool canBeNull = !member.IsDefined<RequiredAttribute>();
                Type otherType = member.Type;
                if(otherType.IsGenericType)
                    otherType = otherType.GetGenericArguments()[0];
                string[] otherKeys = null;
                string[] thisKeys = null;
                if (member.IsDefined<System.ComponentModel.DataAnnotations.AssociationAttribute>())
                {
                    var asAttr = member.GetAttribute<System.ComponentModel.DataAnnotations.AssociationAttribute>();
                    thisKeys = asAttr.ThisKeyMembers.ToArray();
                    otherKeys = asAttr.OtherKeyMembers.ToArray();
                }
                else if (member.IsDefined<ForeignKeyAttribute>())
                {
                    var fkAttr = member.GetAttribute<ForeignKeyAttribute>();
                    otherKeys = GetTypeKeyNames(otherType);
                    thisKeys = fkAttr.Name.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                }
                else
                {
                    otherKeys = GetTypeKeyNames(otherType);
                    thisKeys = otherKeys;
                }

                if (thisKeys != null && otherKeys != null && thisKeys.Length == otherKeys.Length && thisKeys.Length > 0)
                {
                    return new Association(
                        member,
                        thisKeys,
                        otherKeys,
                        string.Format("FK_{0}_{1}", member.TypeAccessor.Type, otherType),
                        canBeNull);
                }
            }
            return base.GetAssociation(typeExtension, member);
        }
开发者ID:cairabbit,项目名称:daf,代码行数:40,代码来源:DataAnnotationMetadataProvider.cs

示例3: GetNullable

		public override bool GetNullable(ObjectMapper mapper, MemberAccessor member, out bool isSet)
		{
			if (IsLinqObject(mapper.TypeAccessor.Type))
			{
				var attr = member.GetAttribute<ColumnAttribute>();

				if (attr != null)
				{
					isSet = true;
					return attr.CanBeNull;
				}
			}

			return base.GetNullable(mapper, member, out isSet);
		}
开发者ID:epdumitru,项目名称:mysqlib,代码行数:15,代码来源:LinqMetadataProvider.cs

示例4: GetFieldStorage

		public override string GetFieldStorage(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
		{
			if (IsLinqObject(member.TypeAccessor.Type))
			{
				var a = member.GetAttribute<ColumnAttribute>();

				if (a != null && !string.IsNullOrEmpty(a.Name))
				{
					isSet = true;
					return a.Storage;
				}
			}

			return base.GetFieldStorage(typeExtension, member, out isSet);
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:15,代码来源:LinqMetadataProvider.cs

示例5: GetFieldName

		public override string GetFieldName(ObjectMapper mapper, MemberAccessor member, out bool isSet)
		{
			if (IsLinqObject(mapper.TypeAccessor.Type))
			{
				ColumnAttribute a = member.GetAttribute<ColumnAttribute>();

				if (a != null && !string.IsNullOrEmpty(a.Name))
				{
					isSet = true;
					return a.Name;
				}
			}

			return base.GetFieldName(mapper, member, out isSet);
		}
开发者ID:epdumitru,项目名称:mysqlib,代码行数:15,代码来源:LinqMetadataProvider.cs

示例6: GetFieldStorage

		public override string GetFieldStorage(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
		{
			var a = member.GetAttribute<MapFieldAttribute>();

			if (a != null)
			{
				isSet = true;
				return a.Storage;
			}

			foreach (MapFieldAttribute attr in GetMapFieldAttributes(member.TypeAccessor))
			{
				if (string.Equals(attr.OrigName, member.Name, StringComparison.InvariantCultureIgnoreCase))
				{
					isSet = true;
					return attr.Storage;
				}
			}

			return base.GetFieldStorage(typeExtension, member, out isSet);
		}
开发者ID:ivanoffalex,项目名称:bltoolkit,代码行数:21,代码来源:AttributeMetadataProvider.cs

示例7: GetIgnore

		public override bool GetIgnore(ObjectMapper mapper, MemberAccessor member, out bool isSet)
		{
			MapIgnoreAttribute attr = member.GetAttribute<MapIgnoreAttribute>();

			if (attr == null)
				attr = (MapIgnoreAttribute)TypeHelper.GetFirstAttribute(member.Type, typeof(MapIgnoreAttribute));

			if (attr != null)
			{
				isSet = true;
				return attr.Ignore;
			}

			if (member.GetAttribute<MapImplicitAttribute>() != null ||
				TypeHelper.GetFirstAttribute(member.Type, typeof(MapImplicitAttribute)) != null)
			{
				isSet = true;
				return false;
			}

			return base.GetIgnore(mapper, member, out isSet);
		}
开发者ID:epdumitru,项目名称:mysqlib,代码行数:22,代码来源:AttributeMetadataProvider.cs

示例8: GetFieldName

		public override string GetFieldName(ObjectMapper mapper, MemberAccessor member, out bool isSet)
		{
			MapFieldAttribute a = member.GetAttribute<MapFieldAttribute>();

			if (a != null)
			{
				isSet = true;
				return a.MapName;
			}

			string name = member.Name.ToLower();

			foreach (MapFieldAttribute attr in GetMapFieldAttributes(mapper))
			{
				if (attr.OrigName.ToLower() == name)
				{
					isSet = true;
					return attr.MapName;
				}
			}

			return base.GetFieldName(mapper, member, out isSet);
		}
开发者ID:epdumitru,项目名称:mysqlib,代码行数:23,代码来源:AttributeMetadataProvider.cs

示例9: GetNullValue

		public override object GetNullValue(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
		{
			// Check member [NullValue(0)]
			//
			var attr = member.GetAttribute<NullValueAttribute>();

			if (attr != null)
			{
				isSet = true;
				return CheckNullValue(attr.Value, member);
			}

			// Check type [NullValues(typeof(int), 0)]
			//
			var attrs = member.GetTypeAttributes(typeof(NullValueAttribute));

			foreach (NullValueAttribute a in attrs)
			{
				if (a.Type == null && a.Value != null && a.Value.GetType() == member.Type ||
					a.Type != null && a.Type == member.Type)
				{
					isSet = true;
					return CheckNullValue(a.Value, member);
				}
			}

			if (member.Type.IsEnum)
			{
				var value = CheckNullValue(mappingSchema.GetNullValue(member.Type), member);

				if (value != null)
				{
					isSet = true;
					return value;
				}
			}

			isSet = false;
			return null;
		}
开发者ID:ivanoffalex,项目名称:bltoolkit,代码行数:40,代码来源:AttributeMetadataProvider.cs

示例10: GetNullable

		public override bool GetNullable(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
		{
			// Check member [Nullable(true | false)]
			//
			var attr1 = member.GetAttribute<NullableAttribute>();

			if (attr1 != null)
			{
				isSet = true;
				return attr1.IsNullable;
			}

			// Check member [NullValue(0)]
			//
			var attr2 = member.GetAttribute<NullValueAttribute>();

			if (attr2 != null)
				return isSet = true;

			// Check type [Nullable(true || false)]
			//
			attr1 = (NullableAttribute)TypeHelper.GetFirstAttribute(
				member.MemberInfo.DeclaringType, typeof(NullableAttribute));

			if (attr1 != null)
			{
				isSet = true;
				return attr1.IsNullable;
			}

			// Check type [NullValues(typeof(int), 0)]
			//
			var attrs = member.GetTypeAttributes(typeof(NullValueAttribute));

			foreach (NullValueAttribute a in attrs)
				if (a.Type == null && a.Value != null && a.Value.GetType() == member.Type ||
					a.Type != null && a.Type == member.Type)
					return isSet = true;

			if (member.Type.IsEnum)
				return isSet = mappingSchema.GetNullValue(member.Type) != null;

			if (member.Type.IsClass)
			{
				var pk = member.GetAttribute<PrimaryKeyAttribute>();

				if (pk != null)
				{
					isSet = false;
					return false;
				}
			}

			return base.GetNullable(mappingSchema, typeExtension, member, out isSet);
		}
开发者ID:ivanoffalex,项目名称:bltoolkit,代码行数:55,代码来源:AttributeMetadataProvider.cs

示例11: GetDefaultValue

		public override object GetDefaultValue(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
		{
			// Check member [DefaultValue(0)]
			//
			var attr = member.GetAttribute<DefaultValueAttribute>();

			if (attr != null)
			{
				isSet = true;
				return attr.Value;
			}

			// Check type [DefaultValues(typeof(int), 0)]
			//
			var attrs = member.GetTypeAttributes(typeof(DefaultValueAttribute));

			foreach (DefaultValueAttribute a in attrs)
				if (a.Type == null && a.Value != null && a.Value.GetType() == member.Type ||
					a.Type != null && a.Type == member.Type)
				{
					isSet = true;
					return a.Value;
				}

			return GetDefaultValue(mappingSchema, typeExtension, member.Type, out isSet);
		}
开发者ID:ivanoffalex,项目名称:bltoolkit,代码行数:26,代码来源:AttributeMetadataProvider.cs

示例12: GetSequenceName

		public override string GetSequenceName(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
		{
			var attr = member.GetAttribute<SequenceNameAttribute>();

			if (attr != null)
			{
				isSet = true;
				return attr.SequenceName;
			}

			return base.GetSequenceName(typeExtension, member, out isSet);
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:12,代码来源:AttributeMetadataProvider.cs

示例13: GetPrimaryKey

		public override PrimaryKeyAttribute GetPrimaryKey(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
		{
			var attr = member.GetAttribute<PrimaryKeyAttribute>() ?? (PrimaryKeyAttribute)TypeHelper.GetFirstAttribute(member.Type, typeof(PrimaryKeyAttribute));

			if (attr != null)
			{
				isSet = true;
				return attr;
			}

			return base.GetPrimaryKey(typeExtension, member, out isSet);
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:12,代码来源:AttributeMetadataProvider.cs

示例14: GetSqlIgnore

		public override bool GetSqlIgnore(TypeExtension typeExtension, MemberAccessor member, out bool isSet)
		{
			var attr = member.GetAttribute<SqlIgnoreAttribute>();

			if (attr == null)
				attr = (SqlIgnoreAttribute)TypeHelper.GetFirstAttribute(member.Type, typeof(SqlIgnoreAttribute));

			if (attr != null)
			{
				isSet = true;
				return attr.Ignore;
			}

			return base.GetSqlIgnore(typeExtension, member, out isSet);
		}
开发者ID:ivanoffalex,项目名称:bltoolkit,代码行数:15,代码来源:AttributeMetadataProvider.cs

示例15: GetAssociation

		public override Association GetAssociation(TypeExtension typeExtension, MemberAccessor member)
		{
			if (IsLinqObject(member.TypeAccessor.Type))
			{
				var a = member.GetAttribute<System.Data.Linq.Mapping.AssociationAttribute>();

				if (a != null)
					return new Association(member, Association.ParseKeys(a.ThisKey), Association.ParseKeys(a.OtherKey), a.Storage, true);
			}

			return base.GetAssociation(typeExtension, member);
		}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:12,代码来源:LinqMetadataProvider.cs


注:本文中的MemberAccessor.GetAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。