예제 #1
0
		/// <summary>
		/// Returns the underlying native type of an element in a semantic structure, resolving sub-semenantic elements as well down to their native type.
		/// </summary>
		public Type GetImplementingType(ISemanticTypeSystem sts)
		{
			Type ret = null;
			List<INativeType> ntypes = sts.GetSemanticTypeStruct(Name).NativeTypes;
			List<ISemanticElement> stypes = sts.GetSemanticTypeStruct(Name).SemanticElements;
			Assert.That(ntypes.Count + stypes.Count == 1, "Getting the element type of a semantic type requires that the semantic type defines one and only one native type or child semantic type in order to resolve the native type property whose value is to be set.");

			if (ntypes.Count == 1)
			{
				ret = ntypes[0].GetImplementingType(sts);
			}
			else
			{
				ret = stypes[0].GetImplementingType(sts);
			}

			return ret;
		}
예제 #2
0
        /// <summary>
        /// Returns the underlying native type of an element in a semantic structure, resolving sub-semenantic elements as well down to their native type.
        /// </summary>
        public Type GetImplementingType(ISemanticTypeSystem sts)
        {
            Type ret = null;
            List <INativeType>      ntypes = sts.GetSemanticTypeStruct(Name).NativeTypes;
            List <ISemanticElement> stypes = sts.GetSemanticTypeStruct(Name).SemanticElements;

            Assert.That(ntypes.Count + stypes.Count == 1, "Getting the element type of a semantic type requires that the semantic type defines one and only one native type or child semantic type in order to resolve the native type property whose value is to be set.");

            if (ntypes.Count == 1)
            {
                ret = ntypes[0].GetImplementingType(sts);
            }
            else
            {
                ret = stypes[0].GetImplementingType(sts);
            }

            return(ret);
        }
예제 #3
0
        /// <summary>
        /// Resolve the ST down to it's singleton native type and return the value.
        /// </summary>
        public void SetValue(ISemanticTypeSystem sts, object instance, object value)
        {
            // Don't set the value if it's null from the DB.
            if (value != DBNull.Value)
            {
                PropertyInfo pi = instance.GetType().GetProperty(Name);

                if (pi == null)
                {
                    // The instance IS the native type that is wrapped by the semantic type.
                    List <INativeType> ntypes = sts.GetSemanticTypeStruct(Name).NativeTypes;
                    Assert.That(ntypes.Count == 1, "Setting a value on a semantic type requires that the semantic type defines one and only one native type or child semantic type in order to resolve the native type property whose value is to be set.");
                    PropertyInfo piTarget = instance.GetType().GetProperty(ntypes[0].Name);
                    piTarget.SetValue(instance, value);
                }
                else
                {
                    Type type = pi.GetType();

                    List <INativeType>      ntypes = sts.GetSemanticTypeStruct(Name).NativeTypes;
                    List <ISemanticElement> stypes = sts.GetSemanticTypeStruct(Name).SemanticElements;
                    Assert.That(ntypes.Count + stypes.Count == 1, "Setting a value on a semantic type requires that the semantic type defines one and only one native type or child semantic type in order to resolve the native type property whose value is to be set.");
                    object item = pi.GetValue(instance);

                    if (ntypes.Count == 1)
                    {
                        PropertyInfo piTarget = item.GetType().GetProperty(ntypes[0].Name);
                        piTarget.SetValue(item, value);
                    }
                    else
                    {
                        stypes[0].SetValue(sts, item, value);
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Resolve the ST down to it's singleton native type and return the value.
        /// </summary>
        public object GetValue(ISemanticTypeSystem sts, object instance)
        {
            object ret = null;

            PropertyInfo pi = instance.GetType().GetProperty(Name);

            List <INativeType>      ntypes = sts.GetSemanticTypeStruct(Name).NativeTypes;
            List <ISemanticElement> stypes = sts.GetSemanticTypeStruct(Name).SemanticElements;

            Assert.That(ntypes.Count + stypes.Count == 1, "Getting a value on a semantic type requires that the semantic type defines one and only one native type or child semantic type in order to resolve the native type property whose value is to be set.");
            object item = pi.GetValue(instance);

            if (ntypes.Count == 1)
            {
                PropertyInfo piTarget = item.GetType().GetProperty(ntypes[0].Name);
                ret = piTarget.GetValue(item);
            }
            else
            {
                ret = stypes[0].GetValue(sts, item);
            }

            return(ret);
        }
예제 #5
0
		/// <summary>
		/// Resolve the ST down to it's singleton native type and return the value.
		/// </summary>
		public void SetValue(ISemanticTypeSystem sts, object instance, object value)
		{
			// Don't set the value if it's null from the DB.
			if (value != DBNull.Value)
			{
				PropertyInfo pi = instance.GetType().GetProperty(Name);

				if (pi == null)
				{
					// The instance IS the native type that is wrapped by the semantic type.
					List<INativeType> ntypes = sts.GetSemanticTypeStruct(Name).NativeTypes;
					Assert.That(ntypes.Count == 1, "Setting a value on a semantic type requires that the semantic type defines one and only one native type or child semantic type in order to resolve the native type property whose value is to be set.");
					PropertyInfo piTarget = instance.GetType().GetProperty(ntypes[0].Name);
					piTarget.SetValue(instance, value);
				}
				else
				{
					Type type = pi.GetType();

					List<INativeType> ntypes = sts.GetSemanticTypeStruct(Name).NativeTypes;
					List<ISemanticElement> stypes = sts.GetSemanticTypeStruct(Name).SemanticElements;
					Assert.That(ntypes.Count + stypes.Count == 1, "Setting a value on a semantic type requires that the semantic type defines one and only one native type or child semantic type in order to resolve the native type property whose value is to be set.");
					object item = pi.GetValue(instance);

					if (ntypes.Count == 1)
					{
						PropertyInfo piTarget = item.GetType().GetProperty(ntypes[0].Name);
						piTarget.SetValue(item, value);
					}
					else
					{
						stypes[0].SetValue(sts, item, value);
					}
				}
			}
		}
예제 #6
0
		/// <summary>
		/// Resolve the ST down to it's singleton native type and return the value.
		/// </summary>
		public object GetValue(ISemanticTypeSystem sts, object instance)
		{
			object ret = null;

			PropertyInfo pi = instance.GetType().GetProperty(Name);

			List<INativeType> ntypes = sts.GetSemanticTypeStruct(Name).NativeTypes;
			List<ISemanticElement> stypes = sts.GetSemanticTypeStruct(Name).SemanticElements;
			Assert.That(ntypes.Count + stypes.Count == 1, "Getting a value on a semantic type requires that the semantic type defines one and only one native type or child semantic type in order to resolve the native type property whose value is to be set.");
			object item = pi.GetValue(instance);

			if (ntypes.Count == 1)
			{
				PropertyInfo piTarget = item.GetType().GetProperty(ntypes[0].Name);
				ret = piTarget.GetValue(item);
			}
			else
			{
				ret = stypes[0].GetValue(sts, item);
			}

			return ret;
		}