Exemple #1
0
 public static dynamic GetValue(this IEntity e, string property)
 {
     if (e.ContainsProperty(property))
     {
         var bp = e.GetType().GetProperty(property);
         return bp.GetValue(property, null);
     }
     return null;
 }
        /// <summary>
        /// Gets the property info for the EDM property on the specified type.
        /// </summary>
        /// <param name="typeReference">The type to get the property on.</param>
        /// <param name="property">Property instance to get the property info for.</param>
        /// <param name="model">Model containing annotations.</param>
        /// <returns>Returns the PropertyInfo object for the specified property.</returns>
        /// <remarks>The method searches this type as well as all its base types for the property.</remarks>
        internal static PropertyInfo GetPropertyInfo(this IEdmStructuredTypeReference typeReference, IEdmProperty property, IEdmModel model)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(typeReference != null, "typeReference != null");
            Debug.Assert(property != null, "property != null");
            Debug.Assert(model != null, "model != null");
            Debug.Assert(property.GetCanReflectOnInstanceTypeProperty(model), "property.CanReflectOnInstanceTypeProperty()");
#if DEBUG
            Debug.Assert(typeReference.ContainsProperty(property), "The typeReference does not define the specified property.");
#endif

            IEdmStructuredType structuredType = typeReference.StructuredDefinition();
            return PropertyInfoTypeAnnotation.GetPropertyInfoTypeAnnotation(structuredType, model).GetPropertyInfo(structuredType, property, model);
        }
Exemple #3
0
        public static bool SetValue(this IEntity e, string property, dynamic value)
        {
            var success = false;
            try
            {
                if (e.ContainsProperty(property))
                {
                    var type = e.GetType();

                    var prop = type.GetProperty(property);

                    prop.SetValue(e, value, null);

                    success = true;
                }
            }
            catch
            {
                success = false;
            }
            return success;
        }