Exemplo n.º 1
0
        /// <summary>
        /// Data constructor: Creates a Dynamic Goo instance from another Dynamic Goo instance.
        /// This creates a shallow copy of the passed Dynamic Goo instance.
        /// </summary>
        /// <param name="dynamicGoo"> Dynamic Goo instance to copy. </param>
        public GH_Dynamic(GH_Dynamic dynamicGoo)
        {
            if (dynamicGoo == null)
            {
                dynamicGoo = new GH_Dynamic();
            }

            this.Value = dynamicGoo.Value;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempt a cast from generic object.
        /// </summary>
        /// <param name="source"> Reference to source of cast. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool CastFrom(object source)
        {
            if (source == null)
            {
                return(false);
            }

            //Cast from Dynamic
            if (typeof(IDynamic).IsAssignableFrom(source.GetType()))
            {
                Value = source as IDynamic;
                return(true);
            }

            //Cast from Dynamic Goo
            if (typeof(GH_Dynamic).IsAssignableFrom(source.GetType()))
            {
                GH_Dynamic dynamicGoo = source as GH_Dynamic;
                Value = dynamicGoo.Value as IDynamic;
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Attempt a cast from generic object.
        /// </summary>
        /// <param name="source"> Reference to source of cast. </param>
        /// <returns> True on success, false on failure. </returns>
        public override bool CastFrom(object source)
        {
            if (source == null)
            {
                return(false);
            }

            //Cast from Code Line
            if (typeof(CodeLine).IsAssignableFrom(source.GetType()))
            {
                Value = source as CodeLine;
                return(true);
            }

            //Cast from Action
            if (typeof(Action).IsAssignableFrom(source.GetType()))
            {
                if (source is CodeLine action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Action Goo
            if (typeof(GH_Action).IsAssignableFrom(source.GetType()))
            {
                GH_Action actionGoo = source as GH_Action;
                if (actionGoo.Value is CodeLine action)
                {
                    Value = action;
                    return(true);
                }
            }

            //Cast from Dynamic
            if (typeof(IDynamic).IsAssignableFrom(source.GetType()))
            {
                if (source is CodeLine codeline)
                {
                    Value = codeline;
                    return(true);
                }
            }

            //Cast from Action Goo
            if (typeof(GH_Dynamic).IsAssignableFrom(source.GetType()))
            {
                GH_Dynamic dynamicGoo = source as GH_Dynamic;
                if (dynamicGoo.Value is CodeLine codeline)
                {
                    Value = codeline;
                    return(true);
                }
            }

            // Cast from Text
            if (typeof(GH_String).IsAssignableFrom(source.GetType()))
            {
                GH_String ghString = (GH_String)source;
                Value = new CodeLine(ghString.Value);
                return(true);
            }

            return(false);
        }