예제 #1
0
        /// <summary>
        /// Binds two objects and its properties with no regard to the fact if they are
        /// originally designed with SDB in mind or not
        /// </summary>
        /// <param name="aDirection">
        /// Direction in which data flows <see cref="EBindDirection"/>
        /// </param>
        /// <param name="aObj1">
        /// First object <see cref="System.Object"/>
        /// </param>
        /// <param name="aPropName1">
        /// Property name for first object <see cref="System.String"/>
        /// </param>
        /// <param name="aObj2">
        /// Second object <see cref="System.Object"/>
        /// </param>
        /// <param name="aPropName2">
        /// Property name for second object <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// DataLinker object which can be used if it is needed to be handled manually <see cref="DataLinker"/>
        /// </returns>
        public static DataLinker Bind(EBindDirection aDirection, object aObj1, string aPropName1, object aObj2, string aPropName2)
        {
            if ((aObj1 == null) || (aObj2 == null) || (aPropName1 == "") || (aPropName2 == ""))
            {
                return(null);
            }
            // Search for existing link
            foreach (DataLinker dl in links)
            {
                if ((aObj1 == dl.Source) && (aObj2 == dl.Destination))
                {
                    if ((aPropName1 == dl.SourceProperty) && (aPropName2 == dl.DestinationProperty))
                    {
                        return(dl);
                    }
                }
                if ((aObj1 == dl.Destination) && (aObj2 == dl.Source))
                {
                    if ((aPropName1 == dl.DestinationProperty) && (aPropName2 == dl.SourceProperty))
                    {
                        return(dl);
                    }
                }
            }

            // If it came to here then this binding is unique
            DataLinker ndl = new DataLinker(aDirection, aObj1, aPropName1, aObj2, aPropName2);

            links.Add(ndl);
            return(ndl);
        }
예제 #2
0
 internal DataLinker(EBindDirection aDirection, object aObj1, string aPropName1, object aObj2, string aPropName2)
 {
     active                     = false;
     source                     = new Adaptor();
     destination                = new Adaptor();
     source.DataChanged        += SourceDataChanged;
     source.TargetChanged      += SourceTargetChanged;
     destination.DataChanged   += DestinationDataChanged;
     destination.TargetChanged += DestinationTargetChanged;
     source.Target              = aObj1;
     destination.Target         = aObj2;
     source.Mappings            = aPropName1;
     destination.Mappings       = aPropName2;
     active                     = true;
     TransferData(source, destination);
 }