本文整理汇总了C#中System.Data.Services.Providers.ResourceType.AddProperty方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceType.AddProperty方法的具体用法?C# ResourceType.AddProperty怎么用?C# ResourceType.AddProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Services.Providers.ResourceType
的用法示例。
在下文中一共展示了ResourceType.AddProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddComplexCollectionProperty
internal void AddComplexCollectionProperty(ResourceType resourceType, string name, ResourceType complexType)
{
CollectionResourceType collectionResourceType = ResourceType.GetCollectionResourceType(complexType);
ResourceProperty resourcePropertyWithDescription = new ResourcePropertyWithDescription(name, ResourcePropertyKind.Collection, collectionResourceType);
resourcePropertyWithDescription.CanReflectOnInstanceTypeProperty = false;
PropertyCustomState propertyCustomState = new PropertyCustomState();
resourcePropertyWithDescription.CustomState = propertyCustomState;
resourceType.AddProperty(resourcePropertyWithDescription);
}
示例2: AddComplexProperty
internal void AddComplexProperty(ResourceType resourceType, string name, ResourceType complexType)
{
if (complexType.ResourceTypeKind == ResourceTypeKind.ComplexType)
{
ResourceProperty resourcePropertyWithDescription = new ResourcePropertyWithDescription(name, ResourcePropertyKind.ComplexType, complexType);
resourcePropertyWithDescription.CanReflectOnInstanceTypeProperty = false;
PropertyCustomState propertyCustomState = new PropertyCustomState();
resourcePropertyWithDescription.CustomState = propertyCustomState;
resourceType.AddProperty(resourcePropertyWithDescription);
return;
}
else
{
throw new InvalidResourceTypeException(complexType.Name, complexType.ResourceTypeKind.ToString(), ResourceTypeKind.ComplexType.ToString());
}
}
示例3: AddComplexProperty
/// <summary>Adds a complex 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="complexType">Complex type to use for the property.</param>
public void AddComplexProperty(ResourceType resourceType, string name, ResourceType complexType)
{
if (complexType.ResourceTypeKind != ResourceTypeKind.ComplexType)
{
throw new ArgumentException("The specified type for the complex property is not a complex type.");
}
ResourceProperty property = new ResourceProperty(name, ResourcePropertyKind.ComplexType, complexType);
property.CanReflectOnInstanceTypeProperty = false;
resourceType.AddProperty(property);
}
示例4: AddReferenceProperty
/// <summary>Helper method to add a reference 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="targetResourceSet">The resource set the resource reference property points to.</param>
/// <param name="resourceSetReference">true if the property should be a resource set reference, false if it should be resource reference.</param>
private void AddReferenceProperty(ResourceType resourceType, string name, ResourceSet targetResourceSet, bool resourceSetReference)
{
ResourceProperty property = new ResourceProperty(
name,
resourceSetReference ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference,
targetResourceSet.ResourceType);
property.CanReflectOnInstanceTypeProperty = false;
resourceType.AddProperty(property);
// We don't support type inheritance so the property can only point to the base resource type of the target resource set
// We also don't support MEST, that is having two resource sets with the same resource type, so we can determine
// the resource set from the resource type. That also means that the property can never point to different resource sets
// so we can precreate the ResourceAssociationSet for this property right here as we have all the information.
property.CustomState = new ResourcePropertyAnnotation()
{
ResourceAssociationSet = new ResourceAssociationSet(
resourceType.Name + "_" + name + "_" + targetResourceSet.Name,
new ResourceAssociationSetEnd(resourceType.GetAnnotation().ResourceSet, resourceType, property),
new ResourceAssociationSetEnd(targetResourceSet, targetResourceSet.ResourceType, null))
};
}
示例5: AddPrimitiveProperty
/// <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);
}
示例6: AddCollectionProperty
/// <summary>Adds a collection of complex or primitive items 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="itemType">The resource type of the item in the collection.</param>
public void AddCollectionProperty(ResourceType resourceType, string name, ResourceType itemType)
{
ResourceProperty property = new ResourceProperty(
name,
ResourcePropertyKind.Collection,
ResourceType.GetCollectionResourceType(itemType));
property.CanReflectOnInstanceTypeProperty = false;
resourceType.AddProperty(property);
}
示例7: AddComplexProperty
/// <summary>Adds a complex 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="complexType">Complex type to use for the property.</param>
public void AddComplexProperty(ResourceType resourceType, string name, ResourceType complexType)
{
if (complexType.ResourceTypeKind != ResourceTypeKind.ComplexType)
{
throw new ArgumentException("The specified type for the complex property is not a complex type.");
}
PropertyInfo propertyInfo = resourceType.InstanceType.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
if (propertyInfo == null)
{
throw new ArgumentException("Can't add a property which does not exist on the instance type.");
}
if (propertyInfo.PropertyType != complexType.InstanceType)
{
throw new ArgumentException("The resource type for the complex property doesn't match the instance type of the property.");
}
ResourceProperty property = new ResourceProperty(name, ResourcePropertyKind.ComplexType, complexType);
property.CanReflectOnInstanceTypeProperty = true;
property.CustomState = new ResourcePropertyAnnotation() { InstanceProperty = propertyInfo };
resourceType.AddProperty(property);
}
示例8: AddPrimitiveProperty
/// <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="typeName">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, bool isKey)
{
PropertyInfo propertyInfo = resourceType.InstanceType.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
if (propertyInfo == null)
{
throw new ArgumentException("Can't add a property which does not exist on the instance type.");
}
ResourceType type = ResourceType.GetPrimitiveResourceType(propertyInfo.PropertyType);
ResourcePropertyKind kind = ResourcePropertyKind.Primitive;
if (isKey)
{
kind |= ResourcePropertyKind.Key;
}
ResourceProperty property = new ResourceProperty(propertyInfo.Name, kind, type);
property.CanReflectOnInstanceTypeProperty = true;
property.CustomState = new ResourcePropertyAnnotation() { InstanceProperty = propertyInfo };
resourceType.AddProperty(property);
}
示例9: AddPrimitiveProperty
/// <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)
{
var type = ResourceType.GetPrimitiveResourceType(propertyType);
if (type == null)
{
throw new ArgumentException(string.Format("Unable to resolve primitive type {0}", propertyType), "propertyType");
}
var kind = ResourcePropertyKind.Primitive;
if (isKey)
{
kind |= ResourcePropertyKind.Key;
}
var property = new ResourceProperty(name, kind, type);
property.CanReflectOnInstanceTypeProperty = false;
resourceType.AddProperty(property);
}
示例10: BuildTypeProperties
//.........这里部分代码省略.........
else
{
kind = ResourcePropertyKind.Primitive;
}
}
else
{
kind = ResourcePropertyKind.Primitive;
}
}
else if (resourceType.ResourceTypeKind == ResourceTypeKind.ComplexType)
{
kind = ResourcePropertyKind.ComplexType;
}
else if (resourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
{
kind = collection ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference;
}
#endregion // Already Known Type
}
else
{
resourceType = IsEntityOrComplexType(resourcePropertyType, knownTypes, childTypes, unvisitedTypes);
if (resourceType != null)
{
if (resourceType.ResourceTypeKind == ResourceTypeKind.ComplexType)
{
kind = ResourcePropertyKind.ComplexType;
}
else
{
Debug.Assert(resourceType.ResourceTypeKind == ResourceTypeKind.EntityType, "Must be an entity type");
kind = collection ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference;
}
}
}
// if resource type is null OR
// if resource type is a collection of primitive or complex types OR
// if complex type has a property of entity type
if (resourceType == null ||
(resourceType.ResourceTypeKind != ResourceTypeKind.EntityType && collection) ||
(resourceType.ResourceTypeKind == ResourceTypeKind.EntityType && parentResourceType.ResourceTypeKind == ResourceTypeKind.ComplexType))
{
if (resourceType == null)
{
if (CommonUtil.IsUnsupportedType(resourcePropertyType))
{
throw new InvalidOperationException(Strings.BadProvider_UnsupportedPropertyType(property.Name, parentResourceType.FullName));
}
throw new InvalidOperationException(Strings.ReflectionProvider_InvalidProperty(property.Name, parentResourceType.FullName));
}
else
{
// collection of complex types not supported
throw new InvalidOperationException(Strings.ReflectionProvider_CollectionOfPrimitiveOrComplexNotSupported(property.Name, parentResourceType.FullName));
}
}
if (resourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
{
container = InternalGetContainerForResourceType(resourcePropertyType, entitySets);
if (container == null)
{
throw new InvalidOperationException(Strings.ReflectionProvider_EntityPropertyWithNoEntitySet(parentResourceType.FullName, property.Name));
}
}
if (etagPropertyNames.Remove(property.Name))
{
kind |= ResourcePropertyKind.ETag;
}
ResourceProperty resourceProperty = new ResourceProperty(property.Name, kind, resourceType);
MimeTypeAttribute attribute = MimeTypeAttribute.GetMimeTypeAttribute(property);
if (attribute != null)
{
resourceProperty.MimeType = attribute.MimeType;
}
parentResourceType.AddProperty(resourceProperty);
}
else
{
throw new InvalidOperationException(Strings.ReflectionProvider_InvalidProperty(property.Name, parentResourceType.FullName));
}
}
if (parentResourceType.ResourceTypeKind == ResourceTypeKind.EntityType &&
(parentResourceType.KeyProperties == null || parentResourceType.KeyProperties.Count == 0))
{
throw new InvalidOperationException(Strings.ReflectionProvider_KeyPropertiesCannotBeIgnored(parentResourceType.FullName));
}
if (etagPropertyNames.Count != 0)
{
throw new InvalidOperationException(Strings.ReflectionProvider_ETagPropertyNameNotValid(etagPropertyNames.ElementAt(0), parentResourceType.FullName));
}
}
示例11: AddResourceSetReferenceProperty
internal void AddResourceSetReferenceProperty(ResourceType sourceType, string name, ResourceType targetType, Schema.AssociationType assocType)
{
ResourceProperty resourcePropertyWithDescription = new ResourcePropertyWithDescription(name, ResourcePropertyKind.ResourceSetReference, targetType);
resourcePropertyWithDescription.CanReflectOnInstanceTypeProperty = false;
resourcePropertyWithDescription.CustomState = new ReferenceCustomState(true);
resourcePropertyWithDescription.GetReferenceCustomState().AssociationType = assocType;
sourceType.AddProperty(resourcePropertyWithDescription);
}
示例12: AddPrimitiveProperty
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");
}
}
示例13: AddPrimitiveCollectionProperty
internal void AddPrimitiveCollectionProperty(ResourceType resourceType, string name, Type propertyType, object defaultValue)
{
CollectionResourceType collectionResourceType = ResourceType.GetCollectionResourceType(ResourceType.GetPrimitiveResourceType(propertyType));
ResourceProperty resourcePropertyWithDescription = new ResourcePropertyWithDescription(name, ResourcePropertyKind.Collection, collectionResourceType);
resourcePropertyWithDescription.CanReflectOnInstanceTypeProperty = false;
PropertyCustomState propertyCustomState = new PropertyCustomState();
propertyCustomState.DefaultValue = defaultValue;
resourcePropertyWithDescription.CustomState = propertyCustomState;
resourceType.AddProperty(resourcePropertyWithDescription);
}
示例14: BuildTypeProperties
//.........这里部分代码省略.........
else if (kind3 == kind)
{
collection = ResourcePropertyKind.Key | ResourcePropertyKind.Primitive;
}
else
{
collection = ResourcePropertyKind.Primitive;
}
}
else
{
collection = ResourcePropertyKind.Primitive;
}
}
}
else if (collectionResourceType.ResourceTypeKind == ResourceTypeKind.ComplexType)
{
collection = flag ? ResourcePropertyKind.Collection : ResourcePropertyKind.ComplexType;
}
else if (collectionResourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
{
collection = flag ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference;
}
}
else
{
collectionResourceType = IsEntityOrComplexType(propertyType, knownTypes, childTypes, unvisitedTypes);
if (collectionResourceType != null)
{
if (collectionResourceType.ResourceTypeKind == ResourceTypeKind.ComplexType)
{
if (flag)
{
if (BaseServiceProvider.GetIEnumerableElement(propertyType) != null)
{
throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_CollectionOfCollectionProperty(info.Name, parentResourceType.FullName));
}
collection = ResourcePropertyKind.Collection;
}
else
{
collection = ResourcePropertyKind.ComplexType;
}
}
else
{
collection = flag ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference;
}
}
}
if ((collectionResourceType == null) || ((collectionResourceType.ResourceTypeKind == ResourceTypeKind.EntityType) && (parentResourceType.ResourceTypeKind == ResourceTypeKind.ComplexType)))
{
if (collectionResourceType != null)
{
throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_ComplexTypeWithNavigationProperty(info.Name, parentResourceType.FullName));
}
if (flag && (BaseServiceProvider.GetIEnumerableElement(propertyType) != null))
{
throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_CollectionOfCollectionProperty(info.Name, parentResourceType.FullName));
}
if (flag)
{
throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_CollectionOfUnsupportedTypeProperty(info.Name, parentResourceType.FullName, propertyType));
}
if (CommonUtil.IsUnsupportedType(propertyType))
{
throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnsupportedPropertyType(info.Name, parentResourceType.FullName));
}
throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_InvalidProperty(info.Name, parentResourceType.FullName));
}
if ((collectionResourceType.ResourceTypeKind == ResourceTypeKind.EntityType) && (InternalGetContainerForResourceType(propertyType, entitySets) == null))
{
throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_EntityPropertyWithNoEntitySet(parentResourceType.FullName, info.Name));
}
if (collection == ResourcePropertyKind.Collection)
{
collectionResourceType = ResourceType.GetCollectionResourceType(collectionResourceType);
}
if (source.Remove(info.Name))
{
collection |= ResourcePropertyKind.ETag;
}
ResourceProperty property = new ResourceProperty(info.Name, collection, collectionResourceType);
MimeTypeAttribute mimeTypeAttribute = MimeTypeAttribute.GetMimeTypeAttribute(info);
if (mimeTypeAttribute != null)
{
property.MimeType = mimeTypeAttribute.MimeType;
}
parentResourceType.AddProperty(property);
}
}
if ((parentResourceType.ResourceTypeKind == ResourceTypeKind.EntityType) && ((parentResourceType.KeyProperties == null) || (parentResourceType.KeyProperties.Count == 0)))
{
throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_KeyPropertiesCannotBeIgnored(parentResourceType.FullName));
}
if (source.Count != 0)
{
throw new InvalidOperationException(System.Data.Services.Strings.ReflectionProvider_ETagPropertyNameNotValid(source.ElementAt<string>(0), parentResourceType.FullName));
}
}
示例15: CreateResourceType
private static ResourceType CreateResourceType(Type type, ResourceTypeKind kind, ResourceType baseType, IDictionary<Type, ResourceType> knownTypes, IDictionary<ResourceType, List<ResourceType>> childTypes)
{
ResourceType type2 = new ResourceType(type, kind, baseType, type.Namespace, CommonUtil.GetModelTypeName(type), type.IsAbstract) {
IsOpenType = false
};
if (type.GetCustomAttributes(typeof(HasStreamAttribute), true).Length == 1)
{
type2.IsMediaLinkEntry = true;
}
foreach (object obj2 in type.GetCustomAttributes(typeof(NamedStreamAttribute), baseType == null))
{
type2.AddProperty(new ResourceProperty(((NamedStreamAttribute) obj2).Name, ResourcePropertyKind.Stream, ResourceType.PrimitiveResourceTypeMap.GetPrimitive(typeof(Stream))));
}
knownTypes.Add(type, type2);
childTypes.Add(type2, null);
if (baseType != null)
{
if (childTypes[baseType] == null)
{
childTypes[baseType] = new List<ResourceType>();
}
childTypes[baseType].Add(type2);
}
return type2;
}