本文整理汇总了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);
}
}
示例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");
}
示例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();
}
示例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;
}