private void CreateEdmTypeHeader(IStructuralTypeConfiguration config) { if (!_types.ContainsKey(config.ClrType)) { if (config.Kind == EdmTypeKind.Complex) { _types.Add(config.ClrType, new EdmComplexType(config.Namespace, config.Name)); } else { IEntityTypeConfiguration entity = config as IEntityTypeConfiguration; Contract.Assert(entity != null); IEdmEntityType baseType = null; if (entity.BaseType != null) { CreateEdmTypeHeader(entity.BaseType); baseType = _types[entity.BaseType.ClrType] as IEdmEntityType; Contract.Assert(baseType != null); } _types.Add(config.ClrType, new EdmEntityType(config.Namespace, config.Name, baseType, entity.IsAbstract, isOpen: false)); } } }
private void CreateEdmTypeHeader(IStructuralTypeConfiguration config) { if (!_types.ContainsKey(config.ClrType)) { if (config.Kind == EdmTypeKind.Complex) { _types.Add(config.ClrType, new EdmComplexType(config.Namespace, config.Name)); } else { IEntityTypeConfiguration entity = config as IEntityTypeConfiguration; Contract.Assert(entity != null); IEdmEntityType baseType = null; if (entity.BaseType != null) { CreateEdmTypeHeader(entity.BaseType); baseType = _types[entity.BaseType.ClrType] as IEdmEntityType; Contract.Assert(baseType != null); } _types.Add(config.ClrType, new EdmEntityType(config.Namespace, config.Name, baseType, entity.IsAbstract ?? false, isOpen: false)); } } }
private void MapEntityType(IEntityTypeConfiguration entity) { PropertyInfo[] properties = ConventionsHelpers.GetProperties(entity.ClrType); foreach (PropertyInfo property in properties) { if (EdmLibHelpers.GetEdmPrimitiveTypeOrNull(property.PropertyType) != null) { PrimitivePropertyConfiguration primitiveProperty = entity.AddProperty(property); primitiveProperty.OptionalProperty = IsNullable(property.PropertyType); } else { IStructuralTypeConfiguration mappedType = GetStructuralTypeOrNull(property.PropertyType); if (mappedType != null) { if (mappedType is IComplexTypeConfiguration) { entity.AddComplexProperty(property); } else { entity.AddNavigationProperty(property, property.PropertyType.IsCollection() ? EdmMultiplicity.Many : EdmMultiplicity.ZeroOrOne); } } else { // we are not really sure if this should be a complex property or an navigation property. // Assume that it is a navigation property and patch later in RediscoverComplexTypes(). entity.AddNavigationProperty(property, property.PropertyType.IsCollection() ? EdmMultiplicity.Many : EdmMultiplicity.ZeroOrOne); } } } }
private static void ApplyPropertyConventions(PropertyConfiguration property, IStructuralTypeConfiguration edmTypeConfiguration) { foreach (IConvention convention in _conventions) { PrimitivePropertyConfiguration primitivePropertyConfiguration; ComplexPropertyConfiguration complexPropertyConfiguration; NavigationPropertyConfiguration navigationPropertyConfiguration; if ((primitivePropertyConfiguration = property as PrimitivePropertyConfiguration) != null) { IEdmPropertyConvention <PrimitivePropertyConfiguration> propertyConfigurationConvention = convention as IEdmPropertyConvention <PrimitivePropertyConfiguration>; if (propertyConfigurationConvention != null) { ApplyPropertyConvention(primitivePropertyConfiguration, edmTypeConfiguration, propertyConfigurationConvention); } } else if ((complexPropertyConfiguration = property as ComplexPropertyConfiguration) != null) { IEdmPropertyConvention <ComplexPropertyConfiguration> propertyConfigurationConvention = convention as IEdmPropertyConvention <ComplexPropertyConfiguration>; if (propertyConfigurationConvention != null) { ApplyPropertyConvention(complexPropertyConfiguration, edmTypeConfiguration, propertyConfigurationConvention); } } else if ((navigationPropertyConfiguration = property as NavigationPropertyConfiguration) != null) { IEdmPropertyConvention <NavigationPropertyConfiguration> propertyConfigurationConvention = convention as IEdmPropertyConvention <NavigationPropertyConfiguration>; if (propertyConfigurationConvention != null) { ApplyPropertyConvention(navigationPropertyConfiguration, edmTypeConfiguration, propertyConfigurationConvention); } } } }
/// <summary> /// Removes the property from the edm type. /// </summary> /// <param name="edmProperty">The property being removed.</param> /// <param name="structuralTypeConfiguration">The edm type from which the property is being removed.</param> /// <param name="attribute">The <see cref="Attribute"/> found on this type.</param> public override void Apply(PropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute) { if (structuralTypeConfiguration == null) { throw Error.ArgumentNull("structuralTypeConfiguration"); } if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } bool isTypeDataContract = structuralTypeConfiguration.ClrType.GetCustomAttributes(typeof(DataContractAttribute), inherit: true).Any(); bool isPropertyDataMember = edmProperty.PropertyInfo.GetCustomAttributes(typeof(DataMemberAttribute), inherit: true).Any(); if (isTypeDataContract && isPropertyDataMember) { // both Datamember and IgnoreDataMember. DataMember wins as this a DataContract return; } else { structuralTypeConfiguration.RemoveProperty(edmProperty.PropertyInfo); } }
private void MapStructuralProperty(IStructuralTypeConfiguration type, PropertyInfo property, PropertyKind propertyKind, bool isCollection) { Contract.Assert(type != null); Contract.Assert(property != null); Contract.Assert(propertyKind == PropertyKind.Complex || propertyKind == PropertyKind.Primitive); if (!isCollection) { if (propertyKind == PropertyKind.Primitive) { type.AddProperty(property); } else { type.AddComplexProperty(property); } } else { if (_isQueryCompositionMode) { Contract.Assert(propertyKind != PropertyKind.Complex, "we don't create complex types in query composition mode."); } type.AddCollectionProperty(property); } }
private static void ApplyPropertyConvention <TPropertyConfiguration>( TPropertyConfiguration property, IStructuralTypeConfiguration structuralTypeConfiguration, IEdmPropertyConvention <TPropertyConfiguration> convention) where TPropertyConfiguration : PropertyConfiguration { convention.Apply(property, structuralTypeConfiguration); }
/// <summary> /// Constructs a CollectionPropertyConfiguration using the <paramref name="property">property</paramref> provided. /// </summary> public CollectionPropertyConfiguration(PropertyInfo property, IStructuralTypeConfiguration declaringType) : base(property, declaringType) { if (!property.PropertyType.IsCollection(out _elementType)) { throw Error.Argument("property", SRResources.CollectionPropertiesMustReturnIEnumerable, property.Name, property.DeclaringType.FullName); } }
protected StructuralTypeConfiguration(IStructuralTypeConfiguration configuration) { if (configuration == null) { throw Error.ArgumentNull("configuration"); } _configuration = configuration; }
/// <summary> /// Marks the property non-optional on the edm type. /// </summary> /// <param name="edmProperty">The edm property.</param> /// <param name="structuralTypeConfiguration">The edm type being configured.</param> /// <param name="attribute">The <see cref="RequiredAttribute"/> found.</param> public override void Apply(StructuralPropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration, RequiredAttribute attribute) { if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } edmProperty.OptionalProperty = false; }
public void Apply(TPropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration) { PropertyInfo clrProperty = edmProperty.PropertyInfo; foreach (TAttribute attribute in clrProperty.GetCustomAttributes(typeof(TAttribute), inherit: false)) { Apply(edmProperty, structuralTypeConfiguration, attribute); } }
private static PropertyConfiguration MockProperty(string name, IStructuralTypeConfiguration declaringType) { Mock <PropertyInfo> propertyInfo = new Mock <PropertyInfo>(); propertyInfo.Setup(p => p.Name).Returns(name); Mock <PropertyConfiguration> property = new Mock <PropertyConfiguration>(propertyInfo.Object, declaringType); return(property.Object); }
private static void ApplyPropertyConventions(IStructuralTypeConfiguration edmTypeConfiguration) { foreach (PropertyConfiguration property in edmTypeConfiguration.Properties.ToArray()) { foreach (IEdmPropertyConvention propertyConvention in _conventions.OfType <IEdmPropertyConvention>()) { propertyConvention.Apply(property, edmTypeConfiguration); } } }
private static IEdmType CreateEdmTypeHeader(IStructuralTypeConfiguration config) { if (config.Kind == StructuralTypeKind.ComplexType) { return new EdmComplexType(config.Namespace, config.Name); } else { return new EdmEntityType(config.Namespace, config.Name); } }
private static IEdmType CreateEdmTypeHeader(IStructuralTypeConfiguration config) { if (config.Kind == StructuralTypeKind.ComplexType) { return(new EdmComplexType(config.Namespace, config.Name)); } else { return(new EdmEntityType(config.Namespace, config.Name)); } }
/// <summary> /// Marks the property non-optional on the edm type. /// </summary> /// <param name="edmProperty">The edm property.</param> /// <param name="structuralTypeConfiguration">The edm type being configured.</param> /// <param name="attribute">The <see cref="Attribute"/> found.</param> public override void Apply(StructuralPropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute) { if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } if (!edmProperty.IsOptionalPropertyExplicitlySet) { edmProperty.OptionalProperty = false; } }
public static PropertyInfo[] GetProperties(IStructuralTypeConfiguration type) { if (type == null) { throw Error.ArgumentNull("type"); } return type .ClrType .GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where(p => p.IsValidStructuralProperty() && !type.IgnoredProperties.Contains(p)) .ToArray(); }
public static PropertyInfo[] GetProperties(IStructuralTypeConfiguration type) { if (type == null) { throw Error.ArgumentNull("type"); } return(type .ClrType .GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where(p => p.IsValidStructuralProperty() && !type.IgnoredProperties.Contains(p)) .ToArray()); }
public override void Apply(PrimitivePropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration, KeyAttribute attribute) { if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } EntityTypeConfiguration entity = structuralTypeConfiguration as EntityTypeConfiguration; if (entity != null) { entity.HasKey(edmProperty.PropertyInfo); } }
public override void Apply(PropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute) { if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } if (structuralTypeConfiguration == null) { throw Error.ArgumentNull("structuralTypeConfiguration"); } structuralTypeConfiguration.RemoveProperty(edmProperty.PropertyInfo); }
protected PropertyConfiguration(PropertyInfo property, IStructuralTypeConfiguration declaringType) { if (property == null) { throw Error.ArgumentNull("property"); } if (declaringType == null) { throw Error.ArgumentNull("declaringType"); } PropertyInfo = property; DeclaringType = declaringType; }
private void ApplyTypeConventions(IStructuralTypeConfiguration edmTypeConfiguration) { if (!_configuredTypes.Contains(edmTypeConfiguration)) { _configuredTypes.Add(edmTypeConfiguration); foreach (IEdmTypeConvention convention in _conventions.OfType <IEdmTypeConvention>()) { if (convention != null) { convention.Apply(edmTypeConfiguration, this); } } } }
private void CreateEdmTypeBody(IStructuralTypeConfiguration config) { IEdmType edmType = _types[config.ClrType]; if (edmType.TypeKind == EdmTypeKind.Complex) { CreateComplexTypeBody(edmType as EdmComplexType, config as IComplexTypeConfiguration); } else { if (edmType.TypeKind == EdmTypeKind.Entity) { CreateEntityTypeBody(edmType as EdmEntityType, config as IEntityTypeConfiguration); } } }
private void CreateEdmTypeBody(IStructuralTypeConfiguration config) { IEdmType edmType = _types[config.FullName]; if (edmType.TypeKind == EdmTypeKind.Complex) { CreateComplexTypeBody(edmType as EdmComplexType, config as IComplexTypeConfiguration); } else { if (edmType.TypeKind == EdmTypeKind.Entity) { CreateEntityTypeBody(edmType as EdmEntityType, config as IEntityTypeConfiguration); } } }
private void CreateStructuralTypeBody(EdmStructuredType type, IStructuralTypeConfiguration config) { foreach (PropertyConfiguration property in config.Properties) { switch (property.Kind) { case PropertyKind.Primitive: PrimitivePropertyConfiguration primitiveProperty = property as PrimitivePropertyConfiguration; type.AddStructuralProperty( primitiveProperty.PropertyInfo.Name, GetTypeKind(primitiveProperty.PropertyInfo.PropertyType), primitiveProperty.OptionalProperty); break; case PropertyKind.Complex: ComplexPropertyConfiguration complexProperty = property as ComplexPropertyConfiguration; IEdmComplexType complexType = _types[complexProperty.RelatedClrType] as IEdmComplexType; type.AddStructuralProperty( complexProperty.PropertyInfo.Name, new EdmComplexTypeReference(complexType, complexProperty.OptionalProperty)); break; case PropertyKind.Collection: CollectionPropertyConfiguration collectionProperty = property as CollectionPropertyConfiguration; IEdmTypeReference elementTypeReference = null; if (_types.ContainsKey(collectionProperty.ElementType)) { IEdmComplexType elementType = _types[collectionProperty.ElementType] as IEdmComplexType; elementTypeReference = new EdmComplexTypeReference(elementType, false); } else { elementTypeReference = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(collectionProperty.ElementType); } type.AddStructuralProperty( collectionProperty.PropertyInfo.Name, new EdmCollectionTypeReference( new EdmCollectionType(elementTypeReference), collectionProperty.OptionalProperty)); break; default: break; } } }
// the convention model builder MapTypes() method might have went through deep object graphs and added a bunch of types // only to realise after applying the conventions that the user has ignored some of the properties. So, prune the unreachable stuff. private void PruneUnreachableTypes() { Contract.Assert(_explicitlyAddedTypes != null); // Do a BFS starting with the types the user has explicitly added to find out the unreachable nodes. Queue <IStructuralTypeConfiguration> reachableTypes = new Queue <IStructuralTypeConfiguration>(_explicitlyAddedTypes); HashSet <IStructuralTypeConfiguration> visitedTypes = new HashSet <IStructuralTypeConfiguration>(); while (reachableTypes.Count != 0) { IStructuralTypeConfiguration currentType = reachableTypes.Dequeue(); // go visit other end of each of this node's edges. foreach (PropertyConfiguration property in currentType.Properties.Where(property => property.Kind != PropertyKind.Primitive)) { if (property.Kind == PropertyKind.Collection) { // if the elementType is primitive we don't need to do anything. CollectionPropertyConfiguration colProperty = property as CollectionPropertyConfiguration; if (EdmLibHelpers.GetEdmPrimitiveTypeOrNull(colProperty.ElementType) != null) { continue; } } IStructuralTypeConfiguration propertyType = GetStructuralTypeOrNull(property.RelatedClrType); Contract.Assert(propertyType != null, "we should already have seen this type"); if (!visitedTypes.Contains(propertyType)) { reachableTypes.Enqueue(propertyType); } } visitedTypes.Add(currentType); } IStructuralTypeConfiguration[] allConfiguredTypes = StructuralTypes.ToArray(); foreach (IStructuralTypeConfiguration type in allConfiguredTypes) { if (!visitedTypes.Contains(type)) { // we don't have to fix up any properties because this type is unreachable and cannot be a property of any reachable type. RemoveStructuralType(type.ClrType); } } }
/// <summary> /// Applies the convention. /// </summary> /// <param name="edmProperty">The property being configured.</param> /// <param name="structuralTypeConfiguration">The type being configured.</param> public void Apply(TPropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration) { if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } if (structuralTypeConfiguration == null) { throw Error.ArgumentNull("structuralTypeConfiguration"); } foreach (Attribute attribute in GetAttributes(edmProperty.PropertyInfo)) { Apply(edmProperty, structuralTypeConfiguration, attribute); } }
private void ApplyTypeAndPropertyConventions(IStructuralTypeConfiguration edmTypeConfiguration) { foreach (IConvention convention in _conventions) { IEdmTypeConvention typeConvention = convention as IEdmTypeConvention; if (typeConvention != null) { typeConvention.Apply(edmTypeConfiguration, this); } IEdmPropertyConvention propertyConvention = convention as IEdmPropertyConvention; if (propertyConvention != null) { ApplyPropertyConvention(propertyConvention, edmTypeConfiguration); } } }
private void CreateStructuralTypeBody(EdmStructuredType type, IStructuralTypeConfiguration config) { foreach (PrimitivePropertyConfiguration prop in config.Properties.OfType <PrimitivePropertyConfiguration>()) { type.AddStructuralProperty( prop.PropertyInfo.Name, GetTypeKind(prop.PropertyInfo.PropertyType), prop.OptionalProperty); } foreach (ComplexPropertyConfiguration prop in config.Properties.OfType <ComplexPropertyConfiguration>()) { IEdmComplexType complexType = _types[prop.RelatedClrType.FullName] as IEdmComplexType; type.AddStructuralProperty( prop.PropertyInfo.Name, new EdmComplexTypeReference(complexType, prop.OptionalProperty)); } }
private void CreateStructuralTypeBody(EdmStructuredType type, IStructuralTypeConfiguration config) { foreach (PrimitivePropertyConfiguration prop in config.Properties.OfType<PrimitivePropertyConfiguration>()) { type.AddStructuralProperty( prop.PropertyInfo.Name, GetTypeKind(prop.PropertyInfo.PropertyType), prop.OptionalProperty); } foreach (ComplexPropertyConfiguration prop in config.Properties.OfType<ComplexPropertyConfiguration>()) { IEdmComplexType complexType = _types[prop.RelatedClrType.FullName] as IEdmComplexType; type.AddStructuralProperty( prop.PropertyInfo.Name, new EdmComplexTypeReference(complexType, prop.OptionalProperty)); } }
private void MapType(IStructuralTypeConfiguration edmType) { if (!_mappedTypes.Contains(edmType)) { _mappedTypes.Add(edmType); IEntityTypeConfiguration entity = edmType as IEntityTypeConfiguration; if (entity != null) { MapEntityType(entity); } else { MapComplexType(edmType as IComplexTypeConfiguration); } ApplyTypeAndPropertyConventions(edmType); } }
/// <summary> /// Applies the convention. /// </summary> /// <param name="edmProperty">The property being configured.</param> /// <param name="structuralTypeConfiguration">The type being configured.</param> /// <param name="attribute">The attribute to be used during configuration.</param> public override void Apply(TPropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute) { if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } if (structuralTypeConfiguration == null) { throw Error.ArgumentNull("structuralTypeConfiguration"); } if (attribute == null) { throw Error.ArgumentNull("attribute"); } Apply(edmProperty, structuralTypeConfiguration, attribute as TAttribute); }
/// <summary> /// Applies the convention. /// </summary> /// <param name="edmProperty">The property being configured.</param> /// <param name="structuralTypeConfiguration">The type being configured.</param> public void Apply(PropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration) { if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } if (structuralTypeConfiguration == null) { throw Error.ArgumentNull("structuralTypeConfiguration"); } TPropertyConfiguration property = edmProperty as TPropertyConfiguration; if (property != null) { Apply(property, structuralTypeConfiguration); } }
public override void Apply(StructuralPropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute) { if (structuralTypeConfiguration == null) { throw Error.ArgumentNull("structuralTypeConfiguration"); } if (edmProperty == null) { throw Error.ArgumentNull("edmProperty"); } bool isTypeDataContract = structuralTypeConfiguration.ClrType.GetCustomAttributes(typeof(DataContractAttribute), inherit: true).Any(); DataMemberAttribute dataMember = attribute as DataMemberAttribute; if (isTypeDataContract && dataMember != null && !edmProperty.IsOptionalPropertyExplicitlySet) { edmProperty.OptionalProperty = !dataMember.IsRequired; } }
private void MapStructuralProperty(IStructuralTypeConfiguration type, PropertyInfo property, PropertyKind propertyKind, bool isCollection) { Contract.Assert(type != null); Contract.Assert(property != null); Contract.Assert(propertyKind == PropertyKind.Complex || propertyKind == PropertyKind.Primitive || propertyKind == PropertyKind.Collection); if (!isCollection) { if (propertyKind == PropertyKind.Primitive) { type.AddProperty(property); } else { type.AddComplexProperty(property); } } else { if (_isQueryCompositionMode) { Contract.Assert(propertyKind != PropertyKind.Complex, "we don't create complex types in query composition mode."); } type.AddCollectionProperty(property); } }
// figures out the type of the property (primitive, complex, navigation, collecion) and the corresponding edm type if we have seen this type // earlier or the user told us about it. private PropertyKind GetPropertyType(PropertyInfo property, out bool isCollection, out IStructuralTypeConfiguration mappedType) { Contract.Assert(property != null); if (EdmLibHelpers.GetEdmPrimitiveTypeOrNull(property.PropertyType) != null) { isCollection = false; mappedType = null; return PropertyKind.Primitive; } else { mappedType = GetStructuralTypeOrNull(property.PropertyType); if (mappedType != null) { isCollection = false; if (mappedType is IComplexTypeConfiguration) { return PropertyKind.Complex; } else { return PropertyKind.Navigation; } } else { Type elementType; if (property.PropertyType.IsCollection(out elementType)) { isCollection = true; // Collection properties - can be a collection of primitives, complex or entities. if (EdmLibHelpers.GetEdmPrimitiveTypeOrNull(elementType) != null) { return PropertyKind.Primitive; } else { mappedType = GetStructuralTypeOrNull(elementType); if (mappedType != null && mappedType is IComplexTypeConfiguration) { return PropertyKind.Complex; } else { return PropertyKind.Navigation; } } } else { isCollection = false; return PropertyKind.Navigation; } } } }
private void ApplyTypeConventions(IStructuralTypeConfiguration edmTypeConfiguration) { if (!_configuredTypes.Contains(edmTypeConfiguration)) { _configuredTypes.Add(edmTypeConfiguration); foreach (IEdmTypeConvention convention in _conventions.OfType<IEdmTypeConvention>()) { if (convention != null) { convention.Apply(edmTypeConfiguration, this); } } } }
private static void ApplyPropertyConventions(IStructuralTypeConfiguration edmTypeConfiguration) { foreach (PropertyConfiguration property in edmTypeConfiguration.Properties.ToArray()) { foreach (IEdmPropertyConvention propertyConvention in _conventions.OfType<IEdmPropertyConvention>()) { propertyConvention.Apply(property, edmTypeConfiguration); } } }
/// <summary> /// Applies the convention. /// </summary> /// <param name="edmProperty">The property being configured.</param> /// <param name="structuralTypeConfiguration">The type being configured.</param> /// <param name="attribute">The attribute to be used during configuration.</param> public abstract void Apply(TPropertyConfiguration edmProperty, IStructuralTypeConfiguration structuralTypeConfiguration, TAttribute attribute);
public PrimitivePropertyConfiguration(PropertyInfo property, IStructuralTypeConfiguration declaringType) : base(property, declaringType) { }
public ComplexPropertyConfiguration(PropertyInfo property, IStructuralTypeConfiguration declaringType) : base(property, declaringType) { }
protected StructuralPropertyConfiguration(PropertyInfo property, IStructuralTypeConfiguration declaringType) : base(property, declaringType) { _optionalProperty = EdmLibHelpers.IsNullable(property.PropertyType); }
private static PropertyConfiguration MockProperty(string name, IStructuralTypeConfiguration declaringType) { Mock<PropertyInfo> propertyInfo = new Mock<PropertyInfo>(); propertyInfo.Setup(p => p.Name).Returns(name); Mock<PropertyConfiguration> property = new Mock<PropertyConfiguration>(propertyInfo.Object, declaringType); return property.Object; }