本文整理汇总了C#中IEdmStructuredType.Properties方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmStructuredType.Properties方法的具体用法?C# IEdmStructuredType.Properties怎么用?C# IEdmStructuredType.Properties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmStructuredType
的用法示例。
在下文中一共展示了IEdmStructuredType.Properties方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetPropertyIdentifierMappingsIfNameConflicts
// This is to solve duplicate names between property and type
internal void SetPropertyIdentifierMappingsIfNameConflicts(string typeName, IEdmStructuredType structuredType)
{
if (Context.EnableNamingAlias)
{
typeName = Customization.CustomizeNaming(typeName);
}
// PropertyName in VB is case-insensitive.
var isLanguageCaseSensitive = true;
// In VB, it is allowed that a type has a property whose name is same with the type's name
var allowPropertyNameSameWithTypeName = false;
Func<string, string> customizePropertyName = name => { return Context.EnableNamingAlias ? Customization.CustomizeNaming(name) : name; };
var propertyGroups = structuredType.Properties()
.GroupBy(p => isLanguageCaseSensitive ? customizePropertyName(p.Name) : customizePropertyName(p.Name).ToUpperInvariant());
// If the group contains more than one property, or the property in the group has the same name with the type (only for C#), we need to rename the property
var propertyToBeRenamedGroups = propertyGroups.Where(g => g.Count() > 1 || !allowPropertyNameSameWithTypeName && g.Key == typeName);
var knownIdentifiers = propertyGroups.Select(g => customizePropertyName(g.First().Name)).ToList();
if (!allowPropertyNameSameWithTypeName && !knownIdentifiers.Contains(typeName))
{
knownIdentifiers.Add(typeName);
}
var uniqueIdentifierService =
new UniqueIdentifierService(knownIdentifiers, isLanguageCaseSensitive);
IdentifierMappings.Clear();
foreach (var g in propertyToBeRenamedGroups)
{
var hasPropertyNameSameWithCustomizedPropertyName = false;
var itemCount = g.Count();
for (var i = 0; i < itemCount; i++)
{
var property = g.ElementAt(i);
var customizedPropertyName = customizePropertyName(property.Name);
if (Context.EnableNamingAlias && customizedPropertyName == property.Name)
{
hasPropertyNameSameWithCustomizedPropertyName = true;
}
if (isLanguageCaseSensitive)
{
// If a property name is same as its customized property name, then we don't rename it.
// Or we don't rename the last property in the group
if (customizedPropertyName != typeName
&& (customizedPropertyName == property.Name
|| (!hasPropertyNameSameWithCustomizedPropertyName && i == itemCount - 1)))
{
continue;
}
}
else
{
// When EnableNamingAlias = true, If a property name is same as its customized property name, then we don't rename it.
// Or we don't rename the last property in the group.
if ((Context.EnableNamingAlias && customizedPropertyName == property.Name)
|| (!hasPropertyNameSameWithCustomizedPropertyName && i == itemCount - 1))
{
continue;
}
}
var renamedPropertyName = uniqueIdentifierService.GetUniqueIdentifier(customizedPropertyName);
IdentifierMappings.Add(property.Name, renamedPropertyName);
}
}
}
示例2: ResolveProperty
/// <summary>
/// Resolve property from property name
/// </summary>
/// <param name="type">The declaring type.</param>
/// <param name="propertyName">The property name.</param>
/// <returns>The resolved <see cref="IEdmProperty"/></returns>
public virtual IEdmProperty ResolveProperty(IEdmStructuredType type, string propertyName)
{
if (EnableCaseInsensitive)
{
var result = type.Properties()
.Where(_ => string.Equals(propertyName, _.Name, StringComparison.OrdinalIgnoreCase))
.ToList();
if (result.Count == 1)
{
return result.Single();
}
else if (result.Count > 1)
{
throw new ODataException(Strings.UriParserMetadata_MultipleMatchingPropertiesFound(propertyName, type.FullTypeName()));
}
}
return type.FindProperty(propertyName);
}
示例3: GetEdmPropertyName
private static string GetEdmPropertyName(MemberInfo currentProperty, IEdmStructuredType edmType)
{
Contract.Requires(currentProperty != null);
Contract.Requires(edmType != null);
var edmProperty = edmType.Properties().SingleOrDefault(property => property.Name.Equals(currentProperty.Name, StringComparison.CurrentCultureIgnoreCase));
return edmProperty != null ? GetPropertyNameForEdmModel(currentProperty, edmProperty) : null;
}
示例4: WriteTypeStaticCreateMethod
internal void WriteTypeStaticCreateMethod(string typeName, IEdmStructuredType structuredType)
{
Debug.Assert(structuredType != null, "structuredType != null");
if (structuredType.IsAbstract)
{
return;
}
Func<IEdmProperty, bool> hasDefault = p => p.PropertyKind == EdmPropertyKind.Structural && ((IEdmStructuralProperty)p).DefaultValueString != null;
if (Context.EnableNamingAlias)
{
typeName = Customization.CustomizeNaming(typeName);
}
var parameters = structuredType.Properties()
.Where(p => !p.Type.IsNullable && !p.Type.IsCollection() && !hasDefault(p));
if (!parameters.Any())
{
return;
}
WriteSummaryCommentForStaticCreateMethod(typeName);
var uniqueIdentifierService = new UniqueIdentifierService( /*IsLanguageCaseSensitive*/true);
var instanceName = GetFixedName(uniqueIdentifierService.GetUniqueParameterName(typeName));
var propertyToParameterNamePairs = parameters
.Select(p =>
new KeyValuePair<IEdmProperty, string>(p,
uniqueIdentifierService.GetUniqueParameterName(
IdentifierMappings.ContainsKey(p.Name) ? IdentifierMappings[p.Name] : p.Name)))
.ToArray();
foreach (var propertyToParameterNamePair in propertyToParameterNamePairs)
{
var propertyName = propertyToParameterNamePair.Key.Name;
propertyName = IdentifierMappings.ContainsKey(propertyName) ?
IdentifierMappings[propertyName] : (Context.EnableNamingAlias ? Customization.CustomizeNaming(propertyName) : propertyName);
WriteParameterCommentForStaticCreateMethod(propertyToParameterNamePair.Value, propertyName);
}
propertyToParameterNamePairs = propertyToParameterNamePairs
.Select(p => p = new KeyValuePair<IEdmProperty, string>(p.Key, GetFixedName(p.Value)))
.ToArray();
WriteDeclarationStartForStaticCreateMethod(typeName, GetFixedName(typeName));
WriteStaticCreateMethodParameters(propertyToParameterNamePairs);
WriteDeclarationEndForStaticCreateMethod(GetFixedName(typeName), instanceName);
foreach (var propertyToParameterNamePair in propertyToParameterNamePairs)
{
var property = propertyToParameterNamePair.Key;
var parameterName = propertyToParameterNamePair.Value;
Debug.Assert(!property.Type.IsCollection(), "!property.Type.IsCollection()");
Debug.Assert(!property.Type.IsNullable, "!property.Type.IsNullable");
// The static create method only sets non-nullable properties. We should add the null check if the type of the property is not a clr ValueType.
// For now we add the null check if the property type is non-primitive. We should add the null check for non-ValueType primitives in the future.
if (!property.Type.IsPrimitive() && !property.Type.IsEnum())
{
WriteParameterNullCheckForStaticCreateMethod(parameterName);
}
var uniqIdentifier = IdentifierMappings.ContainsKey(property.Name) ?
IdentifierMappings[property.Name] : (Context.EnableNamingAlias ? Customization.CustomizeNaming(property.Name) : property.Name);
WritePropertyValueAssignmentForStaticCreateMethod(instanceName,
GetFixedName(uniqIdentifier),
parameterName);
}
WriteMethodEndForStaticCreateMethod(instanceName);
}
示例5: GetSchemaFromModel
private static RecordSchema GetSchemaFromModel(IEdmStructuredType type)
{
if (type.IsOpen)
{
throw new ApplicationException("not supported.");
}
RecordSchema rs = Schema.CreateRecord(type.FullTypeName(), null);
Schema.SetFields(rs, type.Properties().Select(property => Schema.CreateField(property.Name, GetSchemaFromModel(property.Type))));
return rs;
}
示例6: SetMimeTypeForProperties
/// <summary>
/// Find properties with dynamic MIME type related properties and
/// set the references from each ClientProperty to its related MIME type property
/// </summary>
/// <param name="edmStructuredType">Client edm type instance to wire up the mime type properties.</param>
private void SetMimeTypeForProperties(IEdmStructuredType edmStructuredType)
{
MimeTypePropertyAttribute attribute = (MimeTypePropertyAttribute)this.GetClientTypeAnnotation(edmStructuredType).ElementType.GetCustomAttributes(typeof(MimeTypePropertyAttribute), true).SingleOrDefault();
if (null != attribute)
{
IEdmProperty dataProperty = edmStructuredType.Properties().SingleOrDefault(p => p.Name == attribute.DataPropertyName);
if (dataProperty == null)
{
throw c.Error.InvalidOperation(c.Strings.ClientType_MissingMimeTypeDataProperty(this.GetClientTypeAnnotation(edmStructuredType).ElementTypeName, attribute.DataPropertyName));
}
IEdmProperty mimeTypeProperty = edmStructuredType.Properties().SingleOrDefault(p => p.Name == attribute.MimeTypePropertyName);
if (mimeTypeProperty == null)
{
throw c.Error.InvalidOperation(c.Strings.ClientType_MissingMimeTypeProperty(this.GetClientTypeAnnotation(edmStructuredType).ElementTypeName, attribute.MimeTypePropertyName));
}
this.GetClientPropertyAnnotation(dataProperty).MimeTypeProperty = this.GetClientPropertyAnnotation(mimeTypeProperty);
}
}
示例7: ValidateAnnotationWithMorePropertyThanType
private void ValidateAnnotationWithMorePropertyThanType(IEdmModel model, IEdmStructuredType actualType, IEnumerable<IEdmPropertyConstructor> annotationProperties)
{
var actualProperties = actualType.Properties();
foreach (var actualProperty in actualProperties)
{
var annotationProperty = annotationProperties.Where(n => n.Name.Equals(actualProperty.Name)).FirstOrDefault();
Assert.IsNotNull(annotationProperty, "Invalid property name.");
Action<IEdmModel, IEdmStructuredType, IEnumerable<IEdmPropertyConstructor>> validateAnnotation = (m, t, l) => this.ValidateAnnotationWithMorePropertyThanType(m, t, l);
ValidateAnnotationProperty(model, actualProperty, annotationProperty, validateAnnotation);
}
}
示例8: ValidateAnnotationWithExactPropertyAsType
private void ValidateAnnotationWithExactPropertyAsType(IEdmModel model, IEdmStructuredType actualType, IEnumerable<IEdmPropertyConstructor> annotationProperties)
{
Assert.AreEqual(actualType.Properties().Count(), annotationProperties.Count(), "Annotation does not have the same count of properties as it's declared type.");
foreach (var annotationProperty in annotationProperties)
{
var annotationName = annotationProperty.Name;
var actualProperty = actualType.FindProperty(annotationName);
Assert.IsNotNull(actualProperty, "Invalid property name.");
Action<IEdmModel, IEdmStructuredType, IEnumerable<IEdmPropertyConstructor>> validateAnnotation = (m, t, l) => this.ValidateAnnotationWithExactPropertyAsType(m, t, l);
ValidateAnnotationProperty(model, actualProperty, annotationProperty, validateAnnotation);
}
}
示例9: SetMimeTypeForProperties
private void SetMimeTypeForProperties(IEdmStructuredType edmStructuredType)
{
Func<IEdmProperty, bool> predicate = null;
Func<IEdmProperty, bool> func2 = null;
MimeTypePropertyAttribute attribute = (MimeTypePropertyAttribute) this.GetClientTypeAnnotation(edmStructuredType).ElementType.GetCustomAttributes(typeof(MimeTypePropertyAttribute), true).SingleOrDefault<object>();
if (attribute != null)
{
if (predicate == null)
{
predicate = p => p.Name == attribute.DataPropertyName;
}
IEdmProperty edmProperty = edmStructuredType.Properties().SingleOrDefault<IEdmProperty>(predicate);
if (edmProperty == null)
{
throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_MissingMimeTypeDataProperty(this.GetClientTypeAnnotation(edmStructuredType).ElementTypeName, attribute.DataPropertyName));
}
if (func2 == null)
{
func2 = p => p.Name == attribute.MimeTypePropertyName;
}
IEdmProperty property2 = edmStructuredType.Properties().SingleOrDefault<IEdmProperty>(func2);
if (property2 == null)
{
throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.ClientType_MissingMimeTypeProperty(this.GetClientTypeAnnotation(edmStructuredType).ElementTypeName, attribute.MimeTypePropertyName));
}
this.GetClientPropertyAnnotation(edmProperty).MimeTypeProperty = this.GetClientPropertyAnnotation(property2);
}
}