/// <summary> /// Initializes a new <see cref="ServiceOperation"/> instance. /// </summary> /// <param name="name">name of the service operation.</param> /// <param name="resultKind">Kind of result expected from this operation.</param> /// <param name="resultType">Type of element of the method result.</param> /// <param name="resultSet">EntitySet of the result expected from this operation.</param> /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param> /// <param name="parameters">In-order parameters for this operation.</param> public ServiceOperation( string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters) { WebUtil.CheckStringArgumentNull(name, "name"); WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind"); WebUtil.CheckStringArgumentNull(method, "method"); if ((resultKind == ServiceOperationResultKind.Void && resultType != null) || (resultKind != ServiceOperationResultKind.Void && resultType == null)) { throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndKindMustMatch("resultKind", "resultType", ServiceOperationResultKind.Void)); } if ((resultType == null || resultType.ResourceTypeKind != ResourceTypeKind.EntityType) && resultSet != null) { throw new ArgumentException(Strings.ServiceOperation_ResultSetMustBeNull("resultSet", "resultType")); } if (resultType != null && resultType.ResourceTypeKind == ResourceTypeKind.EntityType && (resultSet == null || !resultSet.ResourceType.IsAssignableFrom(resultType))) { throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndResultSetMustMatch("resultType", "resultSet")); } if (method != XmlConstants.HttpMethodGet && method != XmlConstants.HttpMethodPost) { throw new ArgumentException(Strings.ServiceOperation_NotSupportedProtocolMethod(method, name)); } this.name = name; this.resultKind = resultKind; this.resultType = resultType; this.resourceSet = resultSet; this.method = method; if (parameters == null) { this.parameters = ServiceOperation.emptyParameterCollection; } else { this.parameters = new ReadOnlyCollection <ServiceOperationParameter>(new List <ServiceOperationParameter>(parameters)); HashSet <string> paramNames = new HashSet <string>(StringComparer.Ordinal); foreach (ServiceOperationParameter p in this.parameters) { if (!paramNames.Add(p.Name)) { throw new ArgumentException(Strings.ServiceOperation_DuplicateParameterName(p.Name), "parameters"); } } } }
/// <summary> /// Initializes a new <see cref="ServiceOperationParameter"/>. /// </summary> /// <param name="name">Name of parameter.</param> /// <param name="parameterType">resource type of parameter value.</param> public ServiceOperationParameter(string name, ResourceType parameterType) { WebUtil.CheckStringArgumentNull(name, "name"); WebUtil.CheckArgumentNull(parameterType, "parameterType"); if (parameterType.ResourceTypeKind != ResourceTypeKind.Primitive) { throw new ArgumentException(Strings.ServiceOperationParameter_TypeNotSupported(name, parameterType.FullName)); } this.name = name; this.type = parameterType; }
/// <summary> /// Constructs a new ResourceSet instance using the specified name and ResourceType instance /// </summary> /// <param name="name">name of the resource set</param> /// <param name="elementType">Reference to clr type that this resource set is a collection of</param> public ResourceSet(string name, ResourceType elementType) { WebUtil.CheckStringArgumentNull(name, "name"); WebUtil.CheckArgumentNull(elementType, "elementType"); if (elementType.ResourceTypeKind != ResourceTypeKind.EntityType) { throw new ArgumentException(Strings.ResourceContainer_ContainerMustBeAssociatedWithEntityType); } this.name = name; this.elementType = elementType; }
/// <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> /// Constructs a resource association set instance. /// </summary> /// <param name="name">Name of the association set.</param> /// <param name="end1">end1 of the association set.</param> /// <param name="end2">end2 of the association set.</param> public ResourceAssociationSet(string name, ResourceAssociationSetEnd end1, ResourceAssociationSetEnd end2) { WebUtil.CheckStringArgumentNull(name, "name"); WebUtil.CheckArgumentNull(end1, "end1"); WebUtil.CheckArgumentNull(end2, "end2"); if (end1.ResourceProperty == null && end2.ResourceProperty == null) { throw new ArgumentException(Strings.ResourceAssociationSet_ResourcePropertyCannotBeBothNull); } if (end1.ResourceType == end2.ResourceType && end1.ResourceProperty == end2.ResourceProperty) { throw new ArgumentException(Strings.ResourceAssociationSet_SelfReferencingAssociationCannotBeBiDirectional); } this.name = name; this.end1 = end1; this.end2 = end2; }