示例#1
0
        /// <summary>
        /// Returns node context which is dynamic type. It will contain all node default input/output properties.
        /// </summary>
        public object GetNodeContext()
        {
            const string stringTypeName = "System.String";

            if (nodeContext == null)
            {
                dynamic context = new DynamicNodeContext();

                foreach (var input in GetInputs())
                {
                    var contextName = input.Name.Replace(" ", "");
                    if (input.ParameterType.FullName.Replace("&", "") == stringTypeName)
                    {
                        context[contextName] = string.Empty;
                    }
                    else
                    {
                        try
                        {
                            context[contextName] = Activator.CreateInstance(AppDomain.CurrentDomain, input.ParameterType.Assembly.GetName().Name,
                                                                            input.ParameterType.FullName.Replace("&", "").Replace(" ", "")).Unwrap();
                        }
                        catch (MissingMethodException ex) //For case when type does not have default constructor
                        {
                            context[contextName] = null;
                        }
                    }
                }
                foreach (var output in GetOutputs())
                {
                    var contextName = output.Name.Replace(" ", "");
                    if (output.ParameterType.FullName.Replace("&", "") == stringTypeName)
                    {
                        context[contextName] = string.Empty;
                    }
                    else
                    {
                        try
                        {
                            context[contextName] = Activator.CreateInstance(AppDomain.CurrentDomain, output.ParameterType.Assembly.GetName().Name,
                                                                            output.ParameterType.FullName.Replace("&", "").Replace(" ", "")).Unwrap();
                        }
                        catch (MissingMethodException ex) //For case when type does not have default constructor
                        {
                            context[contextName] = null;
                        }
                    }
                }

                nodeContext = context;
            }
            return(nodeContext);
        }
        /// <summary>
        /// Returns node context which is dynamic type. It will contain all node default input/output properties.
        /// </summary>
        public object GetNodeContext()
        {
            if (nodeContext == null)
            {
                dynamic context = new DynamicNodeContext();

                foreach (var input in GetInputs())
                {
                    var p = input.ParameterType == typeof(string) ? "" :
                            Activator.CreateInstance(AppDomain.CurrentDomain, input.ParameterType.Assembly.GetName().Name,
                                                     input.ParameterType.FullName.Replace("&", "").Replace(" ", "")).Unwrap();
                    if (!Convert.IsDBNull(input.DefaultValue))
                    {
                        var def = Convert.ChangeType(input.DefaultValue, p.GetType());
                        if (def != null)
                        {
                            p = def;
                        }
                    }
                    context[input.Name.Replace(" ", "")] = p;
                }
                foreach (var output in GetOutputs())
                {
                    var p = output.ParameterType == typeof(string) ? "" :
                            Activator.CreateInstance(AppDomain.CurrentDomain, output.ParameterType.Assembly.GetName().Name,
                                                     output.ParameterType.FullName.Replace("&", "").Replace(" ", "")).Unwrap();
                    if (!Convert.IsDBNull(output.DefaultValue))
                    {
                        var def = Convert.ChangeType(output.DefaultValue, p.GetType());
                        if (def != null)
                        {
                            p = def;
                        }
                    }
                    context[output.Name.Replace(" ", "")] = p;
                }

                nodeContext = context;
            }
            return(nodeContext);
        }