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


C# MappingSchema.GetAttribute方法代码示例

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


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

示例1: ColumnDescriptor

		public ColumnDescriptor(MappingSchema mappingSchema, ColumnAttribute columnAttribute, MemberAccessor memberAccessor)
		{
			MappingSchema  = mappingSchema;
			MemberAccessor = memberAccessor;
			MemberInfo     = memberAccessor.MemberInfo;

			if (MemberInfo.IsFieldEx())
			{
				var fieldInfo = (FieldInfo)MemberInfo;
				MemberType = fieldInfo.FieldType;
			}
			else if (MemberInfo.IsPropertyEx())
			{
				var propertyInfo = (PropertyInfo)MemberInfo;
				MemberType = propertyInfo.PropertyType;
			}

			MemberName      = columnAttribute.MemberName ?? MemberInfo.Name;
			ColumnName      = columnAttribute.Name       ?? MemberInfo.Name;
			Storage         = columnAttribute.Storage;
			PrimaryKeyOrder = columnAttribute.PrimaryKeyOrder;
			IsDiscriminator = columnAttribute.IsDiscriminator;
			DataType        = columnAttribute.DataType;
			DbType          = columnAttribute.DbType;
			CreateFormat    = columnAttribute.CreateFormat;

			if (columnAttribute.HasLength   ()) Length    = columnAttribute.Length;
			if (columnAttribute.HasPrecision()) Precision = columnAttribute.Precision;
			if (columnAttribute.HasScale    ()) Scale     = columnAttribute.Scale;

			if (Storage == null)
			{
				StorageType = MemberType;
				StorageInfo = MemberInfo;
			}
			else
			{
				var expr = Expression.PropertyOrField(Expression.Constant(null, MemberInfo.DeclaringType), Storage);
				StorageType = expr.Type;
				StorageInfo = expr.Member;
			}

			var defaultCanBeNull = false;

			if (columnAttribute.HasCanBeNull())
				CanBeNull = columnAttribute.CanBeNull;
			else
			{
				var na = mappingSchema.GetAttribute<NullableAttribute>(MemberInfo, attr => attr.Configuration);

				if (na != null)
				{
					CanBeNull = na.CanBeNull;
				}
				else
				{
					CanBeNull        = mappingSchema.GetCanBeNull(MemberType);
					defaultCanBeNull = true;
				}
			}

			if (columnAttribute.HasIsIdentity())
				IsIdentity = columnAttribute.IsIdentity;
			else
			{
				var a = mappingSchema.GetAttribute<IdentityAttribute>(MemberInfo, attr => attr.Configuration);
				if (a != null)
					IsIdentity = true;
			}

			SkipOnInsert = columnAttribute.HasSkipOnInsert() ? columnAttribute.SkipOnInsert : IsIdentity;
			SkipOnUpdate = columnAttribute.HasSkipOnUpdate() ? columnAttribute.SkipOnUpdate : IsIdentity;

			if (defaultCanBeNull && IsIdentity)
				CanBeNull = false;

			if (columnAttribute.HasIsPrimaryKey())
				IsPrimaryKey = columnAttribute.IsPrimaryKey;
			else
			{
				var a = mappingSchema.GetAttribute<PrimaryKeyAttribute>(MemberInfo, attr => attr.Configuration);

				if (a != null)
				{
					IsPrimaryKey    = true;
					PrimaryKeyOrder = a.Order;
				}
			}

			if (DbType == null || DataType == DataType.Undefined)
			{
				var a = mappingSchema.GetAttribute<DataTypeAttribute>(MemberInfo, attr => attr.Configuration);

				if (a != null)
				{
					if (DbType == null)
						DbType = a.DbType;

					if (DataType == DataType.Undefined && a.DataType.HasValue)
						DataType = a.DataType.Value;
//.........这里部分代码省略.........
开发者ID:ronnyek,项目名称:linq2db,代码行数:101,代码来源:ColumnDescriptor.cs

示例2: ColumnDescriptor

        public ColumnDescriptor(MappingSchema mappingSchema, ColumnAttribute columnAttribute, MemberAccessor memberAccessor)
        {
            MappingSchema  = mappingSchema;
            MemberAccessor = memberAccessor;
            MemberInfo     = memberAccessor.MemberInfo;

            if (MemberInfo.IsFieldEx())
            {
                var fieldInfo = (FieldInfo)MemberInfo;
                MemberType = fieldInfo.FieldType;
            }
            else if (MemberInfo.IsPropertyEx())
            {
                var propertyInfo = (PropertyInfo)MemberInfo;
                MemberType = propertyInfo.PropertyType;
            }

            MemberName      = columnAttribute.MemberName ?? MemberInfo.Name;
            ColumnName      = columnAttribute.Name       ?? MemberInfo.Name;
            Storage         = columnAttribute.Storage;
            PrimaryKeyOrder = columnAttribute.PrimaryKeyOrder;
            IsDiscriminator = columnAttribute.IsDiscriminator;
            DataType        = columnAttribute.DataType;
            DbType          = columnAttribute.DbType;
            Length          = columnAttribute.Length;
            Precision       = columnAttribute.Precision;
            Scale           = columnAttribute.Scale;

            var defaultCanBeNull = false;

            if (columnAttribute.HasCanBeNull())
                CanBeNull = columnAttribute.CanBeNull;
            else
            {
                var na = mappingSchema.GetAttribute<NullableAttribute>(MemberInfo, attr => attr.Configuration);

                if (na != null)
                {
                    CanBeNull = na.CanBeNull;
                }
                else
                {
                    CanBeNull        = mappingSchema.GetCanBeNull(MemberType);
                    defaultCanBeNull = true;
                }
            }

            if (columnAttribute.HasIsIdentity())
                IsIdentity = columnAttribute.IsIdentity;
            else
            {
                var a = mappingSchema.GetAttribute<IdentityAttribute>(MemberInfo, attr => attr.Configuration);
                if (a != null)
                    IsIdentity = true;
            }

            SkipOnInsert = columnAttribute.HasSkipOnInsert() ? columnAttribute.SkipOnInsert : IsIdentity;
            SkipOnUpdate = columnAttribute.HasSkipOnUpdate() ? columnAttribute.SkipOnUpdate : IsIdentity;

            if (defaultCanBeNull && IsIdentity)
                CanBeNull = false;

            if (columnAttribute.HasIsPrimaryKey())
                IsPrimaryKey = columnAttribute.IsPrimaryKey;
            else
            {
                var a = mappingSchema.GetAttribute<PrimaryKeyAttribute>(MemberInfo, attr => attr.Configuration);

                if (a != null)
                {
                    IsPrimaryKey    = true;
                    PrimaryKeyOrder = a.Order;
                }
            }
        }
开发者ID:jack128,项目名称:linq2db,代码行数:75,代码来源:ColumnDescriptor.cs


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