本文整理汇总了C#中System.Data.Services.Providers.ResourceType.GetPropertyInfo方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceType.GetPropertyInfo方法的具体用法?C# ResourceType.GetPropertyInfo怎么用?C# ResourceType.GetPropertyInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.Services.Providers.ResourceType
的用法示例。
在下文中一共展示了ResourceType.GetPropertyInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteObjectProperties
/// <summary>Writes all the properties of the specified resource or complex object.</summary>
/// <param name="expanded">Expanded properties for the result.</param>
/// <param name="customObject">Resource or complex object with properties to write out.</param>
/// <param name="resourceType">resourceType containing metadata about the current custom object</param>
/// <param name="absoluteUri">absolute uri for the given resource</param>
/// <param name="relativeUri">relative uri for the given resource</param>
/// <param name="item">Item in which to place links / expansions.</param>
/// <param name="content">Content in which to place values.</param>
/// <param name="currentSourceRoot">Epm source sub-tree corresponding to <paramref name="customObject"/></param>
private void WriteObjectProperties(IExpandedResult expanded, object customObject, ResourceType resourceType, Uri absoluteUri, string relativeUri, SyndicationItem item, DictionaryContent content, EpmSourcePathSegment currentSourceRoot)
{
Debug.Assert(customObject != null, "customObject != null");
Debug.Assert(resourceType != null, "resourceType != null");
Debug.Assert(!String.IsNullOrEmpty(relativeUri), "!String.IsNullOrEmpty(relativeUri)");
if (absoluteUri == null && resourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
{
// entity type should have an URI, complex type should not have an URI
// If the static type of the object is "Object", we will mistreat an entity type as complex type and hit this situation
throw new DataServiceException(500, Strings.BadProvider_InconsistentEntityOrComplexTypeUsage(resourceType.Name));
}
this.RecurseEnter();
try
{
List<ResourcePropertyInfo> navProperties = null;
IEnumerable<ProjectionNode> projectionNodes = null;
if (resourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
{
Debug.Assert(this.CurrentContainer != null, "this.CurrentContainer != null");
if (this.Provider.IsEntityTypeDisallowedForSet(this.CurrentContainer, resourceType))
{
throw new InvalidOperationException(Strings.BaseServiceProvider_NavigationPropertiesOnDerivedEntityTypesNotSupported(resourceType.FullName, this.CurrentContainer.Name));
}
navProperties = new List<ResourcePropertyInfo>(resourceType.Properties.Count);
projectionNodes = this.GetProjections();
}
if (projectionNodes == null)
{
var action = resourceType.DictionarySerializerDelegate;
if (action == null && this.Provider.IsV1Provider)
{
Module module = typeof(SyndicationSerializer).Module;
Type customObjectType = customObject.GetType();
Type[] parameterTypes = new Type[] { typeof(object), typeof(DictionaryContent) };
DynamicMethod method = new DynamicMethod("content_populator", typeof(void), parameterTypes, module, false /* skipVisibility */);
ILGenerator generator = method.GetILGenerator();
MethodInfo methodWritePrimitiveValue = typeof(SyndicationSerializer).GetMethod("WritePrimitiveValue", BindingFlags.Static | BindingFlags.NonPublic);
// Downcast the argument.
generator.Emit(OpCodes.Ldarg_0);
generator.Emit(OpCodes.Castclass, customObjectType);
foreach (ResourceProperty property in resourceType.Properties.Where(p => p.TypeKind == ResourceTypeKind.Primitive))
{
if (SyndicationSerializer.EpmNeedToSkip(currentSourceRoot, property.Name))
{
continue;
}
// WritePrimitiveValue(propertyValue, property.Name, property.ResourceType, content);
generator.Emit(OpCodes.Dup);
generator.Emit(OpCodes.Call, resourceType.GetPropertyInfo(property).GetGetMethod());
if (property.Type.IsValueType)
{
generator.Emit(OpCodes.Box, property.Type);
}
generator.Emit(OpCodes.Ldstr, property.Name);
generator.Emit(OpCodes.Ldstr, property.ResourceType.FullName);
generator.Emit(OpCodes.Ldarg_1);
generator.Emit(OpCodes.Call, methodWritePrimitiveValue);
}
generator.Emit(OpCodes.Pop);
generator.Emit(OpCodes.Ret);
action = (Action<object, DictionaryContent>)method.CreateDelegate(typeof(Action<object, DictionaryContent>), null);
resourceType.DictionarySerializerDelegate = action;
}
if (action != null)
{
action(customObject, content);
}
else
{
foreach (ResourceProperty property in resourceType.Properties.Where(p => p.TypeKind == ResourceTypeKind.Primitive))
{
object propertyValue = WebUtil.GetPropertyValue(this.Provider, customObject, resourceType, property, null);
if (SyndicationSerializer.EpmNeedToSkip(currentSourceRoot, property.Name))
{
continue;
}
WritePrimitiveValue(propertyValue, property.Name, property.ResourceType.FullName, content);
}
//.........这里部分代码省略.........
示例2: CreatePropertyAccessExpression
/// <summary>
/// Creates an expression to access a property.
/// </summary>
/// <param name="source">The source expression which evaluates to the instance to access the property on.</param>
/// <param name="sourceResourceType">The resource type of the source expression.</param>
/// <param name="resourceProperty">The resource property to access.</param>
/// <returns>An expression which evaluates to the property value.</returns>
private static Expression CreatePropertyAccessExpression(Expression source, ResourceType sourceResourceType, ResourceProperty resourceProperty)
{
Debug.Assert(source != null, "source != null");
Debug.Assert(sourceResourceType != null, "sourceResourceType != null");
Debug.Assert(resourceProperty != null, "resourceProperty != null");
Debug.Assert(sourceResourceType.Properties.Contains(resourceProperty), "resourceProperty is not declared on sourceResourceType");
#if DEBUG
Debug.Assert(TypeUtils.AreTypesEquivalent(source.Type, sourceResourceType.InstanceType), "source.Type != sourceResourceType.InstanceType");
#endif
// TODO: Deal with null propagation???
if (resourceProperty.CanReflectOnInstanceTypeProperty)
{
return Expression.Property(source, sourceResourceType.GetPropertyInfo(resourceProperty));
}
else
{
// TODO: Support for untyped and open properties
throw new NotImplementedException();
}
}