private static void CheckResourcePropertyKind(ResourcePropertyKind kind, string parameterName) { if ((((kind != ResourcePropertyKind.ResourceReference) && (kind != ResourcePropertyKind.ResourceSetReference)) && ((kind != ResourcePropertyKind.ComplexType) && (kind != ResourcePropertyKind.Primitive))) && (((kind != ResourcePropertyKind.Collection) && (kind != ResourcePropertyKind.Stream)) && ((kind != (ResourcePropertyKind.Key | ResourcePropertyKind.Primitive)) && (kind != (ResourcePropertyKind.ETag | ResourcePropertyKind.Primitive))))) { throw new ArgumentException(Strings.InvalidEnumValue(kind.GetType().Name), parameterName); } }
/// <summary> /// Validate the parameters of the resource property constructor. /// </summary> /// <param name="kind">kind of the resource property.</param> /// <param name="propertyResourceType">resource type that this property refers to.</param> private static void ValidatePropertyParameters(ResourcePropertyKind kind, ResourceType propertyResourceType) { CheckResourcePropertyKind(kind, "kind"); if (IsOfKind(kind, ResourcePropertyKind.ResourceReference) || IsOfKind(kind, ResourcePropertyKind.ResourceSetReference)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.EntityType) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.Primitive)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.Primitive) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.ComplexType)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.ComplexType) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.Key) && Nullable.GetUnderlyingType(propertyResourceType.InstanceType) != null) { throw new ArgumentException(Strings.ResourceProperty_KeyPropertiesCannotBeNullable); } }
/// <summary> /// Validate the parameters of the resource property constructor. /// </summary> /// <param name="kind">kind of the resource property.</param> /// <param name="propertyResourceType">resource type that this property refers to.</param> private static void ValidatePropertyParameters(ResourcePropertyKind kind, ResourceType propertyResourceType) { CheckResourcePropertyKind(kind, "kind"); if (IsOfKind(kind, ResourcePropertyKind.ResourceReference) || IsOfKind(kind, ResourcePropertyKind.ResourceSetReference)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.EntityType) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.Primitive)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.Primitive) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.ComplexType)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.ComplexType) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.MultiValue)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.MultiValue) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.Stream)) { if (kind != ResourcePropertyKind.Stream) { throw new ArgumentException(Strings.ResourceProperty_NamedStreamKindMustBeUsedAlone); } // Stream property should be declared on the Primitive Type Edm.Stream if (propertyResourceType != ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream))) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } else if (propertyResourceType == ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream))) { // all other property kinds: throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } if (IsOfKind(kind, ResourcePropertyKind.Key) && Nullable.GetUnderlyingType(propertyResourceType.InstanceType) != null) { throw new ArgumentException(Strings.ResourceProperty_KeyPropertiesCannotBeNullable); } }
/// <summary>Adds a new resource property.</summary> /// <param name="resourceType">The resource type to add the property to.</param> /// <param name="name">The name of the property to add.</param> /// <param name="kind">The kind of the property to add.</param> /// <param name="propertyType">The type of the property to add.</param> /// <param name="propertyInfo">If this is a CLR property, the <see cref="PropertyInfo"/> for the property, or null otherwise.</param> /// <returns>The newly created and added property.</returns> private static ResourceProperty AddResourceProperty( ResourceType resourceType, string name, ResourcePropertyKind kind, ResourceType propertyType, PropertyInfo propertyInfo) { ResourceProperty property = new ResourceProperty(name, kind, propertyType); if (propertyInfo != null) { property.CanReflectOnInstanceTypeProperty = true; property.CustomState = new ResourcePropertyAnnotation() { PropertyInfo = propertyInfo }; } else if (kind != ResourcePropertyKind.Stream) { property.CanReflectOnInstanceTypeProperty = false; property.CustomState = new ResourcePropertyAnnotation() { }; } resourceType.AddProperty(property); return(property); }
private void ApplyNavigationProperties(ODataEntryAnnotation entryAnnotation, ResourceSetWrapper entityResourceSet, ResourceType entityResourceType, object entityResource) { foreach (ODataNavigationLink link in entryAnnotation) { ResourcePropertyKind stream = ResourcePropertyKind.Stream; ResourceProperty navigationProperty = entityResourceType.TryResolvePropertyName(link.Name, stream); this.ApplyNavigationProperty(link, entityResourceSet, entityResourceType, navigationProperty, entityResource); } }
public ResourceProperty(string name, ResourcePropertyKind kind, System.Data.Services.Providers.ResourceType propertyResourceType) { WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckArgumentNull <System.Data.Services.Providers.ResourceType>(propertyResourceType, "propertyResourceType"); ValidatePropertyParameters(kind, propertyResourceType); this.kind = kind; this.name = name; this.propertyResourceType = propertyResourceType; this.canReflectOnInstanceTypeProperty = !kind.HasFlag(ResourcePropertyKind.Stream); }
internal void AddPrimitiveProperty(ResourceType resourceType, string name, Type propertyType, bool isEtag, object defaultValue) { ResourcePropertyKind resourcePropertyKind = ResourcePropertyKind.Primitive; if (isEtag) { resourcePropertyKind = resourcePropertyKind | ResourcePropertyKind.ETag; } this.AddPrimitiveProperty(resourceType, name, propertyType, resourcePropertyKind, defaultValue); }
public ResourceProperty(string name, ResourcePropertyKind kind, System.Data.Services.Providers.ResourceType propertyResourceType) { WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckArgumentNull<System.Data.Services.Providers.ResourceType>(propertyResourceType, "propertyResourceType"); ValidatePropertyParameters(kind, propertyResourceType); this.kind = kind; this.name = name; this.propertyResourceType = propertyResourceType; this.canReflectOnInstanceTypeProperty = !kind.HasFlag(ResourcePropertyKind.Stream); }
/// <summary> /// Validates that the given property kind is valid /// </summary> /// <param name="kind">property kind to check</param> /// <param name="parameterName">name of the parameter</param> private static void CheckResourcePropertyKind(ResourcePropertyKind kind, string parameterName) { // For open properties, resource property instance is created only for nav properties. if (kind != ResourcePropertyKind.ResourceReference && kind != ResourcePropertyKind.ResourceSetReference && kind != ResourcePropertyKind.ComplexType && kind != ResourcePropertyKind.Primitive && kind != (ResourcePropertyKind.Primitive | ResourcePropertyKind.Key) && kind != (ResourcePropertyKind.Primitive | ResourcePropertyKind.ETag)) { throw new ArgumentException(Strings.InvalidEnumValue(kind.GetType().Name), parameterName); } }
internal override Expression VisitMemberAccess(MemberExpression m) { if ((m.Member.MemberType != MemberTypes.Property) || (m.Expression.NodeType != ExpressionType.Parameter)) { this.NeedSkipToken = true; return(m); } if (this.rt != null) { ResourcePropertyKind stream = ResourcePropertyKind.Stream; this.property = this.rt.TryResolvePropertyName(m.Member.Name, stream); } return(base.VisitMemberAccess(m)); }
/// <summary> /// Validates that the given property kind is valid. /// </summary> /// <param name="kind">Property kind to check.</param> /// <param name="parameterName">Name of the parameter.</param> private static void CheckResourcePropertyKind(ResourcePropertyKind kind, string parameterName) { if (kind != ResourcePropertyKind.ResourceReference && kind != ResourcePropertyKind.ResourceSetReference && kind != ResourcePropertyKind.ComplexType && kind != ResourcePropertyKind.Primitive && kind != ResourcePropertyKind.MultiValue && kind != ResourcePropertyKind.Stream && kind != (ResourcePropertyKind.Primitive | ResourcePropertyKind.Key) && kind != (ResourcePropertyKind.Primitive | ResourcePropertyKind.ETag)) { throw new ArgumentException(Strings.General_InvalidEnumValue(kind.GetType().Name), parameterName); } }
private static void VerifyResourceProperty(string expectedPropertyName, Type expectedPropertyType, ResourceProperty actualResourceProperty) { ResourcePropertyKind expectedPropertyKind = ResourcePropertyKind.Primitive; if (expectedPropertyName == ProviderMemberSimulator.KeyPropertyName) { expectedPropertyKind |= ResourcePropertyKind.Key; } string expectedMimeType = ProviderMemberSimulator.IsMimeType(expectedPropertyName) ? ProviderMemberSimulator.SimulatedMimeType : null; Assert.AreEqual(expectedPropertyKind, actualResourceProperty.Kind, "Expected ResourceProperty {0} to be a primitive.", expectedPropertyName); Assert.AreEqual(expectedPropertyType, actualResourceProperty.Type, "ResourceProperty.Type is not the expected type."); Assert.AreEqual(expectedMimeType, actualResourceProperty.MimeType, "Expected ResourceProperty {0} to have the simulated MimeType.", expectedPropertyName); }
/// <summary>Adds a key property to the specified <paramref name="resourceType"/>.</summary> /// <param name="resourceType">The resource type to add the property to.</param> /// <param name="name">The name of the property to add.</param> /// <param name="propertyType">The CLR type of the property to add. This can be only a primitive type.</param> /// <param name="isKey">true if the property should be a key property.</param> private void AddPrimitiveProperty(ResourceType resourceType, string name, Type propertyType, bool isKey) { ResourceType type = ResourceType.GetPrimitiveResourceType(propertyType); ResourcePropertyKind kind = ResourcePropertyKind.Primitive; if (isKey) { kind |= ResourcePropertyKind.Key; } ResourceProperty property = new ResourceProperty(name, kind, type); property.CanReflectOnInstanceTypeProperty = false; resourceType.AddProperty(property); }
/// <summary> /// Initializes a new ResourceProperty instance for an open property. /// </summary> /// <param name="name">Property name for the property.</param> /// <param name="kind">Property kind.</param> /// <param name="propertyResourceType">The type of the resource that this property refers to</param> public ResourceProperty( string name, ResourcePropertyKind kind, ResourceType propertyResourceType) { WebUtil.CheckStringArgumentNull(name, "name"); WebUtil.CheckArgumentNull(propertyResourceType, "propertyResourceType"); ValidatePropertyParameters(kind, propertyResourceType); this.kind = kind; this.name = name; this.propertyResourceType = propertyResourceType; this.canReflectOnInstanceTypeProperty = true; }
/// <summary> /// Initializes a new ResourceProperty instance for an open property. /// </summary> /// <param name="name">Property name for the property.</param> /// <param name="kind">Property kind.</param> /// <param name="propertyResourceType">The type of the resource that this property refers to</param> public ResourceProperty( string name, ResourcePropertyKind kind, ResourceType propertyResourceType) { ExceptionUtils.CheckArgumentStringNotNullOrEmpty(name, "name"); ExceptionUtils.CheckArgumentNotNull(propertyResourceType, "propertyResourceType"); ValidatePropertyParameters(kind, propertyResourceType); this.kind = kind; this.name = name; this.propertyResourceType = propertyResourceType; this.canReflectOnInstanceTypeProperty = kind.HasFlag(ResourcePropertyKind.Stream) ? false : true; }
/// <summary>Initializes a new <see cref="T:Microsoft.OData.Service.Providers.ResourceProperty" /> for an open property.</summary> /// <param name="name">Property name for the property as string.</param> /// <param name="kind"> /// <see cref="T:Microsoft.OData.Service.Providers.ResourcePropertyKind" />.</param> /// <param name="propertyResourceType">The <see cref="T:Microsoft.OData.Service.Providers.ResourceType" /> of the resource to which the property refers.</param> public ResourceProperty( string name, ResourcePropertyKind kind, ResourceType propertyResourceType) { WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); WebUtil.CheckArgumentNull(propertyResourceType, "propertyResourceType"); ValidatePropertyParameters(kind, propertyResourceType); this.kind = kind; this.name = name; this.propertyResourceType = propertyResourceType; this.canReflectOnInstanceTypeProperty = kind.HasFlag(ResourcePropertyKind.Stream) ? false : true; }
/// <summary> /// Creates a property segment /// </summary> /// <param name="previous">previous segment info.</param> /// <param name="property">property to create the segment for.</param> /// <returns>new segment for the given property.</returns> private SegmentInfo CreatePropertySegment(SegmentInfo previous, ResourceProperty property) { // Handle a strongly-typed property. SegmentInfo segment = new SegmentInfo() { Identifier = property.Name, ProjectedProperty = property }; segment.TargetResourceType = property.ResourceType; ResourcePropertyKind propertyKind = property.Kind; segment.SingleResult = (propertyKind != ResourcePropertyKind.ResourceSetReference); segment.TargetSource = RequestTargetSource.Property; if (previous.TargetKind == RequestTargetKind.Link && property.TypeKind != ResourceTypeKind.EntityType) { throw DataServiceException.CreateBadRequestError(Strings.RequestUriProcessor_LinkSegmentMustBeFollowedByEntitySegment(segment.Identifier, XmlConstants.UriLinkSegment)); } switch (propertyKind) { case ResourcePropertyKind.ComplexType: segment.TargetKind = RequestTargetKind.ComplexObject; break; case ResourcePropertyKind.Collection: segment.TargetKind = RequestTargetKind.Collection; break; case ResourcePropertyKind.ResourceReference: case ResourcePropertyKind.ResourceSetReference: segment.TargetKind = RequestTargetKind.Resource; segment.TargetResourceSet = this.providerWrapper.GetResourceSet(previous.TargetResourceSet, previous.TargetResourceType, property); if (segment.TargetResourceSet == null) { throw DataServiceException.CreateResourceNotFound(property.Name); } break; default: Debug.Assert(property.IsOfKind(ResourcePropertyKind.Primitive), "must be primitive type property"); segment.TargetKind = RequestTargetKind.Primitive; break; } return(segment); }
private IEnumerable <ODataProperty> GetProjectedEntityProperties(object customObject, ResourceType currentResourceType, Uri relativeUri, IEnumerable <ProjectionNode> projectionNodesForCurrentResourceType) { List <ODataProperty> source = new List <ODataProperty>(currentResourceType.Properties.Count); foreach (ProjectionNode node in projectionNodesForCurrentResourceType) { string str = node.PropertyName; ResourceProperty property = node.TargetResourceType.TryResolvePropertyName(str); if (property != null) { if (property.TypeKind != ResourceTypeKind.EntityType) { source.Add(this.GetODataPropertyForEntityProperty(customObject, currentResourceType, relativeUri, property)); } } else { object propertyValue = WebUtil.GetPropertyValue(base.Provider, customObject, currentResourceType, null, str); source.Add(this.GetODataPropertyForOpenProperty(str, propertyValue)); } } if (currentResourceType.HasEntityPropertyMappings) { foreach (EpmSourcePathSegment segment in currentResourceType.EpmSourceTree.Root.SubProperties) { string propertyName = segment.PropertyName; if (source.FirstOrDefault <ODataProperty>(p => (p.Name == propertyName)) == null) { ResourcePropertyKind stream = ResourcePropertyKind.Stream; ResourceProperty resourceProperty = currentResourceType.TryResolvePropertyName(propertyName, stream); object obj3 = WebUtil.GetPropertyValue(base.Provider, customObject, currentResourceType, resourceProperty, (resourceProperty == null) ? propertyName : null); if (resourceProperty != null) { ODataProperty item = new ODataProperty { Name = propertyName, Value = base.GetPropertyValue(propertyName, resourceProperty.ResourceType, obj3, resourceProperty == null) }; source.Add(item); } else { source.Add(this.GetODataPropertyForOpenProperty(propertyName, obj3)); } } } } return(source); }
/// <summary> /// Determines if the specified property kind is valid. /// </summary> /// <param name="kind">The property kind to inspect.</param> /// <returns>true if the property kind is valid; false otherwise.</returns> private static bool IsValidValue(ResourcePropertyKind kind) { if (kind != ResourcePropertyKind.ResourceReference && kind != ResourcePropertyKind.ResourceSetReference && kind != ResourcePropertyKind.ComplexType && kind != ResourcePropertyKind.Primitive && kind != ResourcePropertyKind.Collection && kind != ResourcePropertyKind.Stream && kind != (ResourcePropertyKind.Primitive | ResourcePropertyKind.Key) && kind != (ResourcePropertyKind.Primitive | ResourcePropertyKind.ETag)) { return(false); } return(true); }
/// <summary> /// Enumerates all interesting combinations of property kind flags. /// </summary> /// <returns>Enumeration of property kind flags.</returns> private IEnumerable <ResourcePropertyKind> GetPropertyKindValues() { ResourcePropertyKind[] kinds = (ResourcePropertyKind[])Enum.GetValues(typeof(ResourcePropertyKind)); foreach (ResourcePropertyKind k in kinds) { yield return(k); } for (int i = 0; i < kinds.Length; i++) { ResourcePropertyKind k = kinds[i]; for (int j = i + 1; j < kinds.Length; j++) { k |= kinds[j]; yield return(k); } } }
private ResourceType GenerateComplexTypeSchema(Type clrType, ResourceTypeKind resourceTypeKind) { if (this.complexTypeResourceTypes.ContainsKey(clrType.FullName)) { return(this.complexTypeResourceTypes[clrType.FullName]); } ResourceType resourceType = new ResourceType(clrType, resourceTypeKind, null, "TenantReporting", clrType.Name, false); foreach (PropertyInfo propertyInfo in clrType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)) { Type type = propertyInfo.PropertyType; Type type2; if (ReportingSchema.IsNullableType(type, out type2)) { type = type2; } ResourcePropertyKind resourcePropertyKind = 1; ResourceType resourceType2 = ResourceType.GetPrimitiveResourceType(type); if (resourceType2 == null) { if (type.IsEnum || type.IsValueType) { throw new NotSupportedException("struct and enum are not supported. For struct, try to change it to class. For enum, try to change it to integer or string."); } if (type.Equals(clrType)) { resourceType2 = resourceType; } else { resourceType2 = this.GenerateComplexTypeSchema(type, 1); } resourcePropertyKind = 4; } resourceType.AddProperty(new ResourceProperty(propertyInfo.Name, resourcePropertyKind, resourceType2)); } if (resourceTypeKind == 1) { this.complexTypeResourceTypes.Add(clrType.FullName, resourceType); } return(resourceType); }
internal void AddPrimitiveProperty(ResourceType resourceType, string name, Type propertyType, ResourcePropertyKind flags, object defaultValue) { if (flags == ResourcePropertyKind.Primitive || flags == (ResourcePropertyKind.Primitive | ResourcePropertyKind.ETag) || flags == (ResourcePropertyKind.Primitive | ResourcePropertyKind.Key)) { ResourceType primitiveResourceType = ResourceType.GetPrimitiveResourceType(propertyType); ResourcePropertyKind resourcePropertyKind = ResourcePropertyKind.Primitive; resourcePropertyKind = resourcePropertyKind | flags; ResourceProperty resourcePropertyWithDescription = new ResourcePropertyWithDescription(name, resourcePropertyKind, primitiveResourceType); resourcePropertyWithDescription.CanReflectOnInstanceTypeProperty = false; PropertyCustomState propertyCustomState = new PropertyCustomState(); propertyCustomState.DefaultValue = defaultValue; resourcePropertyWithDescription.CustomState = propertyCustomState; resourceType.AddProperty(resourcePropertyWithDescription); return; } else { throw new ArgumentException(ExceptionHelpers.GetExceptionMessage(Resources.SchemaInvalidKeyOrEtagDiscrepancy, new object[0]), "flags"); } }
private static void ValidatePropertyParameters(ResourcePropertyKind kind, System.Data.Services.Providers.ResourceType propertyResourceType) { CheckResourcePropertyKind(kind, "kind"); if ((IsOfKind(kind, ResourcePropertyKind.ResourceReference) || IsOfKind(kind, ResourcePropertyKind.ResourceSetReference)) && (propertyResourceType.ResourceTypeKind != ResourceTypeKind.EntityType)) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } if (IsOfKind(kind, ResourcePropertyKind.Primitive) && (propertyResourceType.ResourceTypeKind != ResourceTypeKind.Primitive)) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } if (IsOfKind(kind, ResourcePropertyKind.ComplexType) && (propertyResourceType.ResourceTypeKind != ResourceTypeKind.ComplexType)) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } if (IsOfKind(kind, ResourcePropertyKind.Collection) && (propertyResourceType.ResourceTypeKind != ResourceTypeKind.Collection)) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } if (IsOfKind(kind, ResourcePropertyKind.Stream)) { if (kind != ResourcePropertyKind.Stream) { throw new ArgumentException(Strings.ResourceProperty_NamedStreamKindMustBeUsedAlone); } if (propertyResourceType != System.Data.Services.Providers.ResourceType.PrimitiveResourceTypeMap.GetPrimitive(typeof(Stream))) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } else if (propertyResourceType == System.Data.Services.Providers.ResourceType.PrimitiveResourceTypeMap.GetPrimitive(typeof(Stream))) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } if (IsOfKind(kind, ResourcePropertyKind.Key) && (Nullable.GetUnderlyingType(propertyResourceType.InstanceType) != null)) { throw new ArgumentException(Strings.ResourceProperty_KeyPropertiesCannotBeNullable); } }
public ResourceAssociationSet GetResourceAssociationSet(ResourceSetWrapper resourceSet, ResourceType resourceType, ResourceProperty resourceProperty) { ResourceAssociationSet set; resourceType = GetDeclaringTypeForProperty(resourceType, resourceProperty, null); string key = string.Concat(new object[] { resourceSet.Name, '_', resourceType.FullName, '_', resourceProperty.Name }); if (!this.ResourceAssociationSetCache.TryGetValue(key, out set)) { set = this.metadataProvider.GetResourceAssociationSet(resourceSet.ResourceSet, resourceType, resourceProperty); if (set != null) { ResourceAssociationSetEnd end = set.GetResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty); ResourceAssociationSetEnd end2 = set.GetRelatedResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty); ResourceSetWrapper wrapper = this.ValidateResourceSet(end2.ResourceSet); if (wrapper == null) { set = null; } else { ResourceType type = this.ValidateResourceType(end2.ResourceType); ResourceProperty property = null; if (end2.ResourceProperty != null) { ResourcePropertyKind stream = ResourcePropertyKind.Stream; property = type.TryResolvePropertyName(end2.ResourceProperty.Name, stream); } resourceType = this.ValidateResourceType(end.ResourceType); if ((((end.ResourceSet != resourceSet.ResourceSet) || (end.ResourceType != resourceType)) || ((end.ResourceProperty != resourceProperty) || (end2.ResourceSet != wrapper.ResourceSet))) || ((end2.ResourceType != type) || (end2.ResourceProperty != property))) { set = new ResourceAssociationSet(set.Name, new ResourceAssociationSetEnd(resourceSet.ResourceSet, resourceType, resourceProperty), new ResourceAssociationSetEnd(wrapper.ResourceSet, type, property)); } } } this.ResourceAssociationSetCache.Add(key, set); } return(set); }
private void BuildResourceType(IEntity entity, ResourceType resourceType, Dictionary <string, ResourceType> complexTypeResourceTypes) { if (ResourceType.GetPrimitiveResourceType(entity.ClrType) == null) { foreach (PropertyInfo propertyInfo in entity.ClrType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)) { if (entity.ReportPropertyCmdletParamsMap == null || !entity.ReportPropertyCmdletParamsMap.ContainsKey(propertyInfo.Name) || this.IsEntityPropertyVisibleForCurrentUser(entity, propertyInfo.Name)) { Type type = propertyInfo.PropertyType; Type type2; if (ReportingSchema.IsNullableType(type, out type2)) { type = type2; } ResourcePropertyKind resourcePropertyKind = 1; ResourceType resourceType2 = ResourceType.GetPrimitiveResourceType(type); if (resourceType2 == null) { if (type.IsEnum || type.IsValueType) { throw new NotSupportedException("struct and enum are not supported. For struct, try to change it to class. For enum, try to change it to integer or string."); } if (type.Equals(entity.ClrType)) { resourceType2 = resourceType; } else { resourceType2 = complexTypeResourceTypes[type.FullName]; } resourcePropertyKind = 4; } resourceType.AddProperty(new ResourceProperty(propertyInfo.Name, resourcePropertyKind | (entity.KeyMembers.Contains(propertyInfo.Name) ? 2 : 0), resourceType2)); } } } resourceType.SetReadOnly(); }
public ResourceProperty AddResourceProperty(string propertyName, ResourceType resourceType, ResourcePropertyKind resourcePropertyKind, NodeType propertyType, string containerName, bool IsClrProperty) { ResourceProperty newProperty = null; string propertyTypeName = null; if (resourcePropertyKind == ResourcePropertyKind.ComplexType) { newProperty = Resource.Property(propertyName, propertyType); propertyTypeName = propertyType.Name; } else if (resourcePropertyKind == ResourcePropertyKind.Primitive) { newProperty = Resource.Property(propertyName, propertyType); propertyTypeName = propertyType.ClrType.FullName; } else if (resourcePropertyKind == ResourcePropertyKind.Key) { newProperty = Resource.Property(propertyName, propertyType, Resource.Key()); resourceType.Key = new PrimaryKey(propertyName, newProperty); propertyTypeName = propertyType.ClrType.FullName; } else if (resourcePropertyKind == ResourcePropertyKind.ResourceReference) { // TODO: does this work? ResourceAssociationEnd zeroRole = Resource.End(propertyType.Name, (ResourceType)propertyType, Multiplicity.Zero); ResourceAssociationEnd manyRole = Resource.End(resourceType.Name, resourceType, Multiplicity.Many); ResourceAssociation fk = Resource.Association("FK_" + propertyType.Name + "_" + resourceType.Name, zeroRole, manyRole); newProperty = Resource.Property(propertyName, propertyType, fk, manyRole, zeroRole); propertyTypeName = propertyType.Name; } else if (resourcePropertyKind == ResourcePropertyKind.ResourceSetReference) { // TODO: does this work? ResourceAssociationEnd zeroRole = Resource.End(resourceType.Name, resourceType, Multiplicity.Zero); ResourceAssociationEnd manyRole = Resource.End(propertyType.Name, (ResourceType)propertyType, Multiplicity.Many); ResourceAssociation fk = Resource.Association("FK_" + resourceType.Name + "_" + propertyType.Name, zeroRole, manyRole); newProperty = Resource.Property(propertyName, Resource.Collection(propertyType), fk, zeroRole, manyRole); propertyTypeName = propertyType.Name; } resourceType.Properties.Add(newProperty); // call service op to add to metadata string url = this.ServiceUri + String.Format("/AddResourceProperty?propertyName='{0}'&addToResourceType='{1}'&resourcePropertyKind='{2}'" + "&propertyType='{3}'{4}&isClrProperty={5}", propertyName, resourceType.Name, resourcePropertyKind.ToString(), propertyTypeName, containerName == null ? "" : "&containerName='" + containerName + "'", IsClrProperty.ToString().ToLowerInvariant()); this.ExecuteServiceOp(url); return newProperty; }
/// <summary> /// Return true if the given property kind is of the given kind. /// </summary> /// <param name="propertyKind">Kind of the property.</param> /// <param name="kind">Flag which needs to be checked on property kind.</param> /// <returns>true if the kind flag is set on the given property kind.</returns> public static bool IsOfKind(ResourcePropertyKind propertyKind, ResourcePropertyKind kind) { return((propertyKind & kind) == kind); }
public UtilityRowResourceProperty(string name, ResourcePropertyKind kind, System.Data.Services.Providers.ResourceType propertyResourceType) : this(name, kind, propertyResourceType, null) { }
/// <summary>Adds a new resource property.</summary> /// <param name="resourceType">The resource type to add the property to.</param> /// <param name="name">The name of the property to add.</param> /// <param name="kind">The kind of the property to add.</param> /// <param name="propertyType">The type of the property to add.</param> /// <param name="propertyInfo">If this is a CLR property, the <see cref="PropertyInfo"/> for the property, or null otherwise.</param> /// <returns>The newly created and added property.</returns> private static ResourceProperty AddResourceProperty( ResourceType resourceType, string name, ResourcePropertyKind kind, ResourceType propertyType, PropertyInfo propertyInfo) { ResourceProperty property = new ResourceProperty(name, kind, propertyType); if (propertyInfo != null) { property.CanReflectOnInstanceTypeProperty = true; property.CustomState = new ResourcePropertyAnnotation() { PropertyInfo = propertyInfo }; } else if (kind != ResourcePropertyKind.Stream) { property.CanReflectOnInstanceTypeProperty = false; property.CustomState = new ResourcePropertyAnnotation() { }; } resourceType.AddProperty(property); return property; }
public ResourceProperty(string name, ResourcePropertyKind kind, ResourceType propertyResourceType) { Contract.Requires(!string.IsNullOrEmpty(name)); Contract.Requires(propertyResourceType != null); }
internal ResourceProperty TryResolvePropertyName(string propertyName, ResourcePropertyKind exceptKind) { return this.Properties.FirstOrDefault<ResourceProperty>(p => ((p.Name == propertyName) && ((p.Kind & exceptKind) == 0))); }
/// <summary>Tries to find the property declared on this type for the specified name.</summary> /// <param name="propertyName">Name of property to resolve.</param> /// <param name="exceptKind">The property kind to filter out.</param> /// <returns>Resolved property; possibly null.</returns> internal ResourceProperty TryResolvePropertiesDeclaredOnThisTypeByName(string propertyName, ResourcePropertyKind exceptKind) { // In case of empty property name this will return null, which means propery is not found return this.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == propertyName && (p.Kind & exceptKind) == 0); }
private static bool IsPropertyKind(ResourceProperty property, ResourcePropertyKind propertyKind) { return (property.Kind & propertyKind) == propertyKind; }
/// <summary> /// Determines if the specified property kind is valid. /// </summary> /// <param name="kind">The property kind to inspect.</param> /// <returns>true if the property kind is valid; false otherwise.</returns> private static bool IsValidValue(ResourcePropertyKind kind) { if (kind != ResourcePropertyKind.ResourceReference && kind != ResourcePropertyKind.ResourceSetReference && kind != ResourcePropertyKind.ComplexType && kind != ResourcePropertyKind.Primitive && kind != ResourcePropertyKind.Collection && kind != ResourcePropertyKind.Stream && kind != (ResourcePropertyKind.Primitive | ResourcePropertyKind.Key) && kind != (ResourcePropertyKind.Primitive | ResourcePropertyKind.ETag)) { return false; } return true; }
/// <summary>Adds a key property to the specified <paramref name="resourceType"/>.</summary> /// <param name="resourceType">The resource type to add the property to.</param> /// <param name="name">The name of the property to add.</param> /// <param name="propertyType">The CLR type of the property to add. This can be only a primitive type.</param> /// <param name="kind">Kind of the property to add.</param> /// <returns>The newly created property.</returns> private ResourceProperty AddPrimitiveProperty(ResourceType resourceType, string name, Type propertyType, ResourcePropertyKind kind) { Debug.Assert(((kind & ResourcePropertyKind.Primitive) == 0) && ((kind & ResourcePropertyKind.ComplexType) == 0) && ((kind & ResourcePropertyKind.Collection) == 0) && ((kind & ResourcePropertyKind.ResourceReference) == 0) && ((kind & ResourcePropertyKind.ResourceSetReference) == 0), "Only Key and ETag can be specified in the kind"); PropertyInfo propertyInfo = resourceType.InstanceType.GetProperty(name); propertyType = propertyType ?? (propertyInfo != null ? propertyInfo.PropertyType : null); ResourceType type = ResourceType.GetPrimitiveResourceType(propertyType); kind |= ResourcePropertyKind.Primitive; return AddResourceProperty(resourceType, name, kind, type, propertyInfo); }
/// <summary> /// Returns true if the specified kind enum has the specified flags set. /// </summary> /// <param name="kind">The kind enum to test.</param> /// <param name="flag">The flag to look for.</param> /// <returns>true if the flag is set; false otherwise.</returns> internal static bool HasFlag(this ResourcePropertyKind kind, ResourcePropertyKind flag) { DebugUtils.CheckNoExternalCallers(); return (kind & flag) == flag; }
public UtilityRowResourceProperty(string name, ResourcePropertyKind kind, System.Data.Services.Providers.ResourceType propertyResourceType, ResourceSet targetContainer) : base(name, kind, propertyResourceType) { }
/// <summary> /// return true if this property is of the given kind /// </summary> /// <param name="checkKind">flag which needs to be checked on the current property kind</param> /// <returns>true if the current property is of the given kind</returns> internal bool IsOfKind(ResourcePropertyKind checkKind) { return ResourceProperty.IsOfKind(this.kind, checkKind); }
/// <summary> /// return true if this property is of the given kind /// </summary> /// <param name="checkKind">flag which needs to be checked on the current property kind</param> /// <returns>true if the current property is of the given kind</returns> internal bool IsOfKind(ResourcePropertyKind checkKind) { return(ResourceProperty.IsOfKind(this.kind, checkKind)); }
/// <summary> /// return true if the given property kind is of the given kind /// </summary> /// <param name="propertyKind">kind of the property</param> /// <param name="kind">flag which needs to be checked on property kind</param> /// <returns>true if the kind flag is set on the given property kind</returns> private static bool IsOfKind(ResourcePropertyKind propertyKind, ResourcePropertyKind kind) { return ((propertyKind & kind) == kind); }
/// <summary> /// Return true if this property is of the given kind. /// </summary> /// <param name="checkKind">Flag which needs to be checked on the current property kind.</param> /// <returns>true if the current property is of the given kind.</returns> public bool IsOfKind(ResourcePropertyKind checkKind) { DebugUtils.CheckNoExternalCallers(); return ResourceProperty.IsOfKind(this.kind, checkKind); }
/// <summary> /// Validate the parameters of the resource property constructor. /// </summary> /// <param name="kind">kind of the resource property.</param> /// <param name="propertyResourceType">resource type that this property refers to.</param> private static void ValidatePropertyParameters(ResourcePropertyKind kind, ResourceType propertyResourceType) { CheckResourcePropertyKind(kind, "kind"); if (IsOfKind(kind, ResourcePropertyKind.ResourceReference) || IsOfKind(kind, ResourcePropertyKind.ResourceSetReference)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.EntityType) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.Primitive)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.Primitive) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.ComplexType)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.ComplexType) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.Collection)) { if (propertyResourceType.ResourceTypeKind != ResourceTypeKind.Collection) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } if (IsOfKind(kind, ResourcePropertyKind.Stream)) { if (kind != ResourcePropertyKind.Stream) { throw new ArgumentException(Strings.ResourceProperty_NamedStreamKindMustBeUsedAlone); } // Stream property should be declared on the Primitive Type Edm.Stream if (propertyResourceType != PrimitiveResourceTypeMap.TypeMap.GetPrimitive(typeof(System.IO.Stream))) { throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } } else if (propertyResourceType == PrimitiveResourceTypeMap.TypeMap.GetPrimitive(typeof(System.IO.Stream))) { // all other property kinds: throw new ArgumentException(Strings.ResourceProperty_PropertyKindAndResourceTypeKindMismatch("kind", "propertyResourceType")); } if (IsOfKind(kind, ResourcePropertyKind.Key) && Nullable.GetUnderlyingType(propertyResourceType.InstanceType) != null) { throw new ArgumentException(Strings.ResourceProperty_KeyPropertiesCannotBeNullable); } Debug.Assert(propertyResourceType.ResourceTypeKind != ResourceTypeKind.EntityCollection, "EntityCollectionResourceType is not a supported type for ResourceProperty."); }
/// <summary> /// Return true if this property is of the given kind. /// </summary> /// <param name="checkKind">Flag which needs to be checked on the current property kind.</param> /// <returns>true if the current property is of the given kind.</returns> public bool IsOfKind(ResourcePropertyKind checkKind) { DebugUtils.CheckNoExternalCallers(); return(ResourceProperty.IsOfKind(this.kind, checkKind)); }
internal static ResourceProperty CreateNonClrProperty(string name, ResourcePropertyKind kind, ResourceType propertyType) { ResourceProperty property = new ResourceProperty(name, kind, propertyType); property.CanReflectOnInstanceTypeProperty = false; return property; }
/// <summary> /// Returns true if the specified kind enum has the specified flags set. /// </summary> /// <param name="kind">The kind enum to test.</param> /// <param name="flag">The flag to look for.</param> /// <returns>true if the flag is set; false otherwise.</returns> internal static bool HasFlag(this ResourcePropertyKind kind, ResourcePropertyKind flag) { DebugUtils.CheckNoExternalCallers(); return((kind & flag) == flag); }
public ResourcePropertyWithDescription(string name, ResourcePropertyKind kind, ResourceType myType) : base(name, kind, myType) { }
public ResourceProperty (string name, ResourcePropertyKind kind, ResourceType propertyResourceType) { this.Name = name; this.Kind = kind; this.ResourceType = propertyResourceType; }