コード例 #1
0
ファイル: SemanticElement.cs プロジェクト: keithshort/HOPE
		/// <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
ファイル: SemanticElement.cs プロジェクト: keithshort/HOPE
		/// <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
ファイル: SemanticElement.cs プロジェクト: keithshort/HOPE
		/// <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;
		}