本文整理汇总了C#中Microsoft.OData.Service.Providers.ResourceType.GetAllPropertiesLazily方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceType.GetAllPropertiesLazily方法的具体用法?C# ResourceType.GetAllPropertiesLazily怎么用?C# ResourceType.GetAllPropertiesLazily使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.OData.Service.Providers.ResourceType
的用法示例。
在下文中一共展示了ResourceType.GetAllPropertiesLazily方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeCollectionProperties
private void InitializeCollectionProperties(ResourceType type, ResourceInstance instance, UpdatableToken token, Func<ResourceProperty, bool> filter)
{
foreach (ResourceProperty property in type.GetAllPropertiesLazily().Where(filter))
{
string propertyName = property.Name;
Type collectionType = this.GetCollectionPropertyType(type.FullName, propertyName);
if (collectionType != null)
{
var newCollection = Activator.CreateInstance(collectionType);
token.PendingPropertyUpdates[propertyName] = newCollection;
this.pendingChanges.Add(() => instance[propertyName] = newCollection);
}
}
}
示例2: ConvertPropertyValueType
/// <summary>
/// Converts the the property value to the expected property type if it is a declared primitive property.
/// </summary>
/// <param name="propertyName">Name of the property.</param>
/// <param name="propertyValue">The property value.</param>
/// <param name="targetResourceType">Type of the target resource/entity.</param>
/// <returns>The converted property value</returns>
protected virtual object ConvertPropertyValueType(string propertyName, object propertyValue, ResourceType targetResourceType)
{
var resourceProperty = targetResourceType.GetAllPropertiesLazily().SingleOrDefault(p => p.Name == propertyName);
if (resourceProperty == null || !resourceProperty.Kind.HasFlag(ResourcePropertyKind.Primitive))
{
return propertyValue;
}
else
{
if (!resourceProperty.ResourceType.InstanceType.IsAssignableFrom(propertyValue.GetType()))
{
var propertyValueString = propertyValue as string;
if (propertyValueString != null)
{
propertyValue = this.ConvertStringToType(propertyValueString, resourceProperty.ResourceType.InstanceType);
}
else
{
propertyValue = Convert.ChangeType(propertyValue, resourceProperty.ResourceType.InstanceType, CultureInfo.InvariantCulture);
}
}
}
return propertyValue;
}