当前位置: 首页>>代码示例>>C#>>正文


C# ScriptScope.ContainsVariable方法代码示例

本文整理汇总了C#中ScriptScope.ContainsVariable方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptScope.ContainsVariable方法的具体用法?C# ScriptScope.ContainsVariable怎么用?C# ScriptScope.ContainsVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptScope的用法示例。


在下文中一共展示了ScriptScope.ContainsVariable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PythonSingleLayer

        public PythonSingleLayer(PythonScriptHost host, string code, string name)
        {
            Name = name;
            Code = code;
            Host = host;

            string[] codeWithoutWhitespace = code.Split(new char[] { ' ', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            string alltokens = "";

            foreach (string token in codeWithoutWhitespace)
            {
                alltokens += token;
            }

            _id = alltokens.GetHashCode().ToString();

            _scope = host.CreateScriptSource(code, name);

            if (_scope.ContainsVariable(_processannotations))
            {
                _processAnnotationsFunc = _scope.GetVariable(_processannotations);
            }

            if (_scope.ContainsVariable(_interpret))
            {
                _interpretFunc = _scope.GetVariable(_interpret);
            }
        }
开发者ID:prefab,项目名称:code,代码行数:28,代码来源:PythonSingleLayer.cs

示例2: InitScripting

        private void InitScripting(string scriptName)
        {
            this.engine = Python.CreateEngine();
            this.engine.Runtime.LoadAssembly(typeof(string).Assembly);
            this.engine.Runtime.LoadAssembly(typeof(DiagnosticMonitor).Assembly);
            this.engine.Runtime.LoadAssembly(typeof(RoleEnvironment).Assembly);
            this.engine.Runtime.LoadAssembly(typeof(Microsoft.WindowsAzure.CloudStorageAccount).Assembly);

            this.scope = this.engine.CreateScope();
            engine.CreateScriptSourceFromFile(scriptName).Execute(scope);

            if (scope.ContainsVariable("start"))
                this.pyStart = scope.GetVariable<Func<bool>>("start");

            this.pyRun = scope.GetVariable<Action>("run");

            if (scope.ContainsVariable("stop"))
                this.pyStop = scope.GetVariable<Action>("stop");
        }
开发者ID:AdamStrojek,项目名称:IronPythonAzure,代码行数:19,代码来源:PyRoleEntryPoint.cs

示例3: Load

        /// <summary>
        /// Loads this plugin
        /// </summary>
        public void Load()
        {
            // Load the plugin
            string code = File.ReadAllText(Filename);
            Name = Path.GetFileNameWithoutExtension(Filename);
            Scope = PythonEngine.CreateScope();
            var source = PythonEngine.CreateScriptSourceFromString(code, Path.GetFileName(Filename), SourceCodeKind.Statements);
            var compiled = source.Compile();
            compiled.Execute(Scope);
            if (!Scope.ContainsVariable(Name)) throw new Exception("Plugin is missing main class");
            Class = PythonEngine.Operations.CreateInstance(Scope.GetVariable(Name));
            PythonEngine.Operations.SetMember(Class, "Name", Name);

            // Read plugin attributes
            if (!PythonEngine.Operations.ContainsMember(Class, "Title") || PythonEngine.Operations.GetMember<string>(Class, "Title") == null) throw new Exception("Plugin is missing title");
            if (!PythonEngine.Operations.ContainsMember(Class, "Author") || PythonEngine.Operations.GetMember<string>(Class, "Author") == null) throw new Exception("Plugin is missing author");
            if (!PythonEngine.Operations.ContainsMember(Class, "Version") || PythonEngine.Operations.GetMember(Class, "Version").GetType() != typeof(VersionNumber)) throw new Exception("Plugin is missing version");
            Title = PythonEngine.Operations.GetMember<string>(Class, "Title");
            Author = PythonEngine.Operations.GetMember<string>(Class, "Author");
            Version = PythonEngine.Operations.GetMember<VersionNumber>(Class, "Version");
            if (PythonEngine.Operations.ContainsMember(Class, "Description")) Description = PythonEngine.Operations.GetMember<string>(Class, "Description");
            if (PythonEngine.Operations.ContainsMember(Class, "ResourceId")) ResourceId = PythonEngine.Operations.GetMember<int>(Class, "ResourceId");
            HasConfig = PythonEngine.Operations.ContainsMember(Class, "HasConfig") && PythonEngine.Operations.GetMember<bool>(Class, "HasConfig") || PythonEngine.Operations.ContainsMember(Class, "LoadDefaultConfig");

            // Set attributes
            PythonEngine.Operations.SetMember(Class, "Plugin", this);

            Globals = PythonEngine.Operations.GetMemberNames(Class);

            foreach (var name in Globals)
            {
                object func;
                if (!PythonEngine.Operations.TryGetMember(Class, name, out func) || !PythonEngine.Operations.IsCallable(func) || !PythonEngine.Operations.ContainsMember(func, "__dict__")) continue;
                var dict = PythonEngine.Operations.GetMember<PythonDictionary>(func, "__dict__");
                if (dict.ContainsKey("isCommand"))
                {
                    var names = ((IList<object>) dict["name"]).Cast<string>().ToArray();
                    var perms = ((IList<object>) dict["permission"]).Cast<string>().ToArray();
                    if (names.Length == 0)
                    {
                        Interface.Oxide.LogWarning("Command is missing name: {0} from plugin: {1}! Skipping...", name, Name);
                        continue;
                    }
                    AddCovalenceCommand(names, perms, (cmd, type, caller, args) =>
                    {
                        PythonEngine.Operations.InvokeMember(Class, name, caller, args);
                        return true;
                    });
                }
            }

            // Bind any base methods (we do it here because we don't want them to be hooked)
            BindBaseMethods();
        }
开发者ID:CypressCube,项目名称:Oxide,代码行数:57,代码来源:PythonPlugin.cs

示例4: IsSimilarButNotSameAs

        /// <summary>
        /// Check to make sure that two seperate (i.e. not references to same memory) 
        /// ScriptScope objects are equivalent.
        /// 
        /// 1) If they are NOT pointing at the same memory.
        /// 2) If they have the same number of elements and each scope element is the
        ///    same then they are both equal
        internal static bool IsSimilarButNotSameAs(this ScriptScope callingScope, ScriptScope scope)
        {
            // if reference of same object in memory return false
            if (callingScope == scope) return false;

            foreach (string varName in callingScope.GetVariableNames()) {
                if (!scope.ContainsVariable(varName))
                    return false;
                if (scope.GetVariable(varName) != callingScope.GetVariable(varName))
                    return false;
            }

            return true;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:21,代码来源:ScriptScopeTestHelper.cs


注:本文中的ScriptScope.ContainsVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。