Beispiel #1
0
        /// <summary>
        /// Clone the element of the source signal into a new destination signal.
        /// This does NOT clone the signal--it is designed to clone the specific child semantic element of the supplied signal.
        /// </summary>
        public dynamic Clone(dynamic sourceSignal, ISemanticElement childElem)
        {
            dynamic subsignal = null;

            if (sourceSignal != null)
            {
                PropertyInfo pi  = sourceSignal.GetType().GetProperty(childElem.Name);                                  // Get the property of the source's sub-type, which will/must be a semantic element
                object       val = pi.GetValue(sourceSignal);                                                           // Get the instance of the semantic element we are cloning.

                // A sub-ST can be null, especially as produced by the persistence engine with outer joins.
                if (val != null)
                {
                    subsignal = Create(childElem.Name);                                                                                                 // Create the sub-signal
                    ISemanticTypeStruct subSemStruct = GetSemanticTypeStruct(childElem.Name);

                    foreach (INativeType nativeType in subSemStruct.NativeTypes)
                    {
                        // Copy any native types.
                        object ntVal = nativeType.GetValue(this, val);
                        nativeType.SetValue(this, subsignal, ntVal);
                    }

                    // Recurse drilling into semantic types of this type and copying any potential native types.
                    foreach (ISemanticElement semanticElem in subSemStruct.SemanticElements)
                    {
                        dynamic      se    = Clone((dynamic)val, semanticElem);                                                 // Clone the sub-semantic type
                        PropertyInfo piSub = subsignal.GetType().GetProperty(semanticElem.Name);                                // Get the PropertyInfo for this type.
                        piSub.SetValue(subsignal, se);                                                                          // Assign the instance of the created semantic type to the value for this property.
                    }
                }
            }

            return(subsignal);
        }
Beispiel #2
0
        /// <summary>
        /// Internal recursion to flatten the hierarcy of semantic elements.
        /// </summary>
        protected void FlattenedSemanticTypes(List <ISemanticTypeStruct> ret, ISemanticElement se)
        {
            ret.Add(se.Element.Struct);

            foreach (ISemanticElement s in se.Element.Struct.SemanticElements)
            {
                FlattenedSemanticTypes(ret, s);
            }
        }
Beispiel #3
0
		/// <summary>
		/// Internal recursion to flatten the hierarcy of semantic elements.
		/// </summary>
		protected void FlattenedSemanticTypes(List<ISemanticTypeStruct> ret, ISemanticElement se)
		{
			ret.Add(se.Element.Struct);

			foreach (ISemanticElement s in se.Element.Struct.SemanticElements)
			{
				FlattenedSemanticTypes(ret, s);
			}
		}
		/// <summary>
		/// Registers a foreign key name and value to be associated with the specified semantic structure, which is used when the ST is inserted
		/// after all child elements have been resolved.
		/// </summary>
		protected void RegisterForeignKeyID(Dictionary<ISemanticTypeStruct, List<FKValue>> stfkMap, ISemanticTypeStruct sts, ISemanticElement child, int id)
		{
			// Associate the ID to this ST's FK for that child table.
			string fieldName = "FK_" + child.Name + "ID";
			CreateKeyIfMissing(stfkMap, sts);
			stfkMap[sts].Add(new FKValue(fieldName, id, child.UniqueField));
		}
		/// <summary>
		/// Given a signal and the child element, returns the value of the child instance.
		/// </summary>
		protected object GetChildSignal(object signal, ISemanticElement child)
		{
			PropertyInfo piSub = signal.GetType().GetProperty(child.Name);
			object childSignal = piSub.GetValue(signal);

			return childSignal;
		}
Beispiel #6
0
		/// <summary>
		/// Clone the element of the source signal into a new destination signal.  
		/// This does NOT clone the signal--it is designed to clone the specific child semantic element of the supplied signal.
		/// </summary>
		public dynamic Clone(dynamic sourceSignal, ISemanticElement childElem)
		{
			dynamic subsignal = null;

			if (sourceSignal != null)
			{
				PropertyInfo pi = sourceSignal.GetType().GetProperty(childElem.Name);			// Get the property of the source's sub-type, which will/must be a semantic element
				object val = pi.GetValue(sourceSignal);										// Get the instance of the semantic element we are cloning.

				// A sub-ST can be null, especially as produced by the persistence engine with outer joins.
				if (val != null)
				{
					subsignal = Create(childElem.Name);										// Create the sub-signal
					ISemanticTypeStruct subSemStruct = GetSemanticTypeStruct(childElem.Name);

					foreach (INativeType nativeType in subSemStruct.NativeTypes)
					{
						// Copy any native types.
						object ntVal = nativeType.GetValue(this, val);
						nativeType.SetValue(this, subsignal, ntVal);
					}

					// Recurse drilling into semantic types of this type and copying any potential native types.
					foreach (ISemanticElement semanticElem in subSemStruct.SemanticElements)
					{
						dynamic se = Clone((dynamic)val, semanticElem);								// Clone the sub-semantic type
						PropertyInfo piSub = subsignal.GetType().GetProperty(semanticElem.Name);	// Get the PropertyInfo for this type.
						piSub.SetValue(subsignal, se);												// Assign the instance of the created semantic type to the value for this property.
					}
				}
			}

			return subsignal;
		}