예제 #1
0
        ////////////////////////////////////////////////

        public PainObject CloneBySerialize()
        {
            PainObject obj = this.SerializeToBytes().Deserialize <PainObject>();

            return(obj);
        }
예제 #2
0
        //////////////////////////////////////////////

        //public PainState PushContext(String DisplayName, Guid ObjectID, PainContextType ContextType)
        public PainState PushContext(
            PainProgram Program,
            PainContextType ContextType,
            IList <Object> Parameters)
        {
            PainState  state = new PainState(Program, ContextType); // DisplayName, ObjectID, ContextType);
            PainObject obj   = state.Object;

            this.Stack.Push(state);
            this.CurrentState = state;

            List <PainMethodParam> finalParameters = new List <PainMethodParam>();
            Int32 index = -1;

            if (Program is PainMethod)
            {
                PainMethod method = (PainMethod)Program;
                foreach (String parameter in method.Parameters)
                {
                    index++;

                    Object parameterValue = Parameters == null ? null :
                                            index < Parameters.Count ?
                                            Parameters[index] :
                                            new Undefined();

                    if (obj != null)
                    {
                        obj[parameter] = parameterValue;
                        finalParameters.Add(new PainMethodParam()
                        {
                            Name  = parameter,
                            Value = parameterValue
                        });
                    }
                }
            }

            if (obj != null)
            {
                foreach (PainMethod painMethod in Program.Methods)
                {
                    if (state.Program is PainClass)
                    {
                        PainMethod newMethod = (PainMethod)painMethod.Clone();
                        newMethod.ParentObject = obj;
                        obj[newMethod.Name]    = newMethod;
                    }
                    else
                    {
                        obj[painMethod.Name] = painMethod;
                    }
                }

                foreach (PainClass painClass in Program.Classes)
                {
                    obj[painClass.Name] = painClass;
                }
            }

            RaiseProgramStart(
                state,
                finalParameters);

            return(state);
        }