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


C# PropertyInfo.CanWriteExtended方法代码示例

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


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

示例1: AddScalarMember

        private static void AddScalarMember(
            Type type, PropertyInfo clrProperty, StructuralType ospaceType, EdmProperty cspaceProperty, EdmType propertyType)
        {
            DebugCheck.NotNull(type);
            DebugCheck.NotNull(clrProperty);
            Debug.Assert(clrProperty.CanRead && clrProperty.CanWriteExtended(), "The clr property has to have a setter and a getter.");
            DebugCheck.NotNull(ospaceType);
            DebugCheck.NotNull(cspaceProperty);
            DebugCheck.NotNull(propertyType);
            Debug.Assert(Helper.IsScalarType(propertyType), "Property has to be primitive or enum.");

            var cspaceType = cspaceProperty.DeclaringType;

            var isKeyMember = Helper.IsEntityType(cspaceType) && ((EntityType)cspaceType).KeyMemberNames.Contains(clrProperty.Name);

            // the property is nullable only if it is not a key and can actually be set to null (i.e. is not a value type or is a nullable value type)
            var nullableFacetValue = !isKeyMember
                                     &&
                                     (!clrProperty.PropertyType.IsValueType() || Nullable.GetUnderlyingType(clrProperty.PropertyType) != null);

            var ospaceProperty =
                new EdmProperty(
                    cspaceProperty.Name,
                    TypeUsage.Create(
                        propertyType, new FacetValues
                            {
                                Nullable = nullableFacetValue
                            }),
                    clrProperty,
                    type);

            if (isKeyMember)
            {
                ((EntityType)ospaceType).AddKeyMember(ospaceProperty);
            }
            else
            {
                ospaceType.AddMember(ospaceProperty);
            }
        }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:40,代码来源:OSpaceTypeFactory.cs

示例2: CreateAndAddEnumProperty

 // <summary>
 // Creates an Enum property based on <paramref name="clrProperty" /> and adds it to the parent structural type.
 // </summary>
 // <param name="type">
 // CLR type owning <paramref name="clrProperty" /> .
 // </param>
 // <param name="ospaceType"> OSpace type the created property will be added to. </param>
 // <param name="cspaceProperty"> Corresponding property from CSpace. </param>
 // <param name="clrProperty"> CLR property used to build an Enum property. </param>
 private void CreateAndAddEnumProperty(Type type, StructuralType ospaceType, EdmProperty cspaceProperty, PropertyInfo clrProperty)
 {
     EdmType propertyType;
     if (CspaceToOspace.TryGetValue(cspaceProperty.TypeUsage.EdmType, out propertyType))
     {
         if (clrProperty.CanRead
             && clrProperty.CanWriteExtended())
         {
             AddScalarMember(type, clrProperty, ospaceType, cspaceProperty, propertyType);
         }
         else
         {
             LogError(
                 Strings.Validator_OSpace_Convention_ScalarPropertyMissginGetterOrSetter(
                     clrProperty.Name, type.FullName, type.Assembly().FullName),
                 cspaceProperty.TypeUsage.EdmType);
         }
     }
     else
     {
         LogError(
             Strings.Validator_OSpace_Convention_MissingOSpaceType(cspaceProperty.TypeUsage.EdmType.FullName),
             cspaceProperty.TypeUsage.EdmType);
     }
 }
开发者ID:Cireson,项目名称:EntityFramework6,代码行数:34,代码来源:OSpaceTypeFactory.cs


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