GetValue() public method

Returns a value of the specified property.
public GetValue ( string propertyName ) : object
propertyName string The name of the property to return.
return object
        /// <summary>Gets a value of a declared property for a resource.</summary>
        /// <param name="target">The target resource to get a value of the property from.</param>
        /// <param name="resourceProperty">The name of the property to get.</param>
        /// <returns>The value of the property.</returns>
        /// <remarks>The returned value's type should match the type declared in the resource's resource type.</remarks>
        public object GetPropertyValue(object target, ResourceProperty resourceProperty)
        {
            DSPResource entity = target as DSPResource;

            if (entity != null)
            {
                return(entity.GetValue(resourceProperty.Name));
            }
            else
            {
                throw new NotSupportedException("Unrecognized resource type.");
            }
        }
Esempio n. 2
0
 public static BsonDocument CreateBSonDocument(DSPResource resource, MongoMetadata mongoMetadata, string resourceName)
 {
     var document = new BsonDocument();
     var resourceSet = mongoMetadata.ResolveResourceSet(resourceName);
     if (resourceSet != null)
     {
         foreach (var property in resourceSet.ResourceType.Properties)
         {
             var propertyValue = resource.GetValue(property.Name);
             if (propertyValue != null)
             {
                 document.Set(property.Name, BsonValue.Create(propertyValue));
             }
         }
     }
     return document;
 }
Esempio n. 3
0
 private static void AssignNullCollections(DSPResource resource, ResourceType resourceType)
 {
     foreach (var resourceProperty in resourceType.Properties)
     {
         var propertyValue = resource.GetValue(resourceProperty.Name);
         if (resourceProperty.Kind == ResourcePropertyKind.Collection)
         {
             if (propertyValue == null)
             {
                 resource.SetValue(resourceProperty.Name, new object[0]);
             }
         }
         else if (propertyValue is DSPResource)
         {
             AssignNullCollections(propertyValue as DSPResource, resourceProperty.ResourceType);
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Adds the given value to the collection
        /// </summary>
        /// <param name="targetResource">target object which defines the property</param>
        /// <param name="propertyName">name of the property whose value needs to be updated</param>
        /// <param name="resourceToBeAdded">value of the property which needs to be added</param>
        /// <remarks>Adds resource instance <paramref name="resourceToBeAdded"/> into a resource reference set
        /// <paramref name="propertyName"/> on resource <paramref name="targetResource"/>.
        /// Both resources, that is <paramref name="targetResource"/> and <paramref name="resourceToBeAdded"/>, are specified
        /// in the parameters as the resource "handle".
        /// All changes made by this method should be creates as pending until SaveChanges is called which will commit them (or if it's not called and ClearChanges
        /// is called instead they should be discarded).</remarks>
        public void AddReferenceToCollection(object targetResource, string propertyName, object resourceToBeAdded)
        {
            // We don't use resource "handles" so both resources passed in as parameters are the real resource instances.
            DSPResource dspTargetResource    = ValidateDSPResource(targetResource);
            DSPResource dspResourceToBeAdded = ValidateDSPResource(resourceToBeAdded);

            // All resource set reference properties must be of type IList<DSPResource> (assumption of this provider)
            // Note that we don't support bi-directional relationships so we only handle the one resource set reference property in isolation.

            IList <DSPResource> list = dspTargetResource.GetValue(propertyName) as IList <DSPResource>;

            if (list == null)
            {
                throw new ArgumentException("The value of the property '" + propertyName + "' does not implement IList<DSPResource>, which is a requirement for resource set reference property.");
            }

            this.pendingChanges.Add(() =>
            {
                list.Add(dspResourceToBeAdded);
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the value of the given property on the target object
        /// </summary>
        /// <param name="targetResource">target object which defines the property</param>
        /// <param name="propertyName">name of the property whose value needs to be updated</param>
        /// <returns>the value of the property for the given target resource</returns>
        /// <remarks>The method gets a resource "handle" in the <paramref name="targetResource"/> and the name of a resource property
        /// defined on it and should return the value of that property.</remarks>
        public object GetValue(object targetResource, string propertyName)
        {
            DSPResource dspTargetResource = ValidateDSPResource(targetResource);

            return(dspTargetResource.GetValue(propertyName));
        }