本文整理汇总了C#中System.IO.AsReadOnly方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.AsReadOnly方法的具体用法?C# System.IO.AsReadOnly怎么用?C# System.IO.AsReadOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO
的用法示例。
在下文中一共展示了System.IO.AsReadOnly方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Require
public MondValue Require(MondState state, string fileName)
{
if (_require.Loader == null)
throw new MondRuntimeException("require: module loader is not set");
const string cacheObjectName = "__modules";
MondValue cacheObject;
// make sure we have somewhere to cache modules
if (state[cacheObjectName].Type != MondValueType.Object)
{
cacheObject = new MondValue(state);
cacheObject.Prototype = MondValue.Null;
state[cacheObjectName] = cacheObject;
}
else
{
cacheObject = state[cacheObjectName];
}
// return cached module if it exists
var cachedExports = cacheObject[fileName];
if (cachedExports.Type == MondValueType.Object)
return cachedExports;
// create a new object to store the exports
var exports = new MondValue(state);
exports.Prototype = MondValue.Null;
// instantly cache it so we can have circular dependencies
cacheObject[fileName] = exports;
try
{
var searchDirectories = new[] { Path.GetDirectoryName(state.CurrentScript), "" };
var moduleSource = _require.Loader(fileName, searchDirectories.AsReadOnly());
// wrap the module script in a function so we can pass out exports object to it
var source = _require.Definitions + "return fun (exports) {\n" + moduleSource + " return exports; };";
var options = new MondCompilerOptions
{
FirstLineNumber = -1
};
var requireOptions = _require.Options;
if (requireOptions != null)
{
options.DebugInfo = requireOptions.DebugInfo;
options.MakeRootDeclarationsGlobal = requireOptions.MakeRootDeclarationsGlobal;
options.UseImplicitGlobals = requireOptions.UseImplicitGlobals;
}
var program = MondProgram.Compile(source, fileName, options);
var initializer = state.Load(program);
var result = state.Call(initializer, exports);
if (result.Type != MondValueType.Object)
throw new MondRuntimeException("require: module must return an object (`{0}`)", fileName);
if (!ReferenceEquals(exports, result))
{
// module returned a different object, merge with ours
foreach (var kv in result.Object)
{
var key = kv.Key;
var value = kv.Value;
exports[key] = value;
}
exports.Prototype = result.Prototype;
if (result.IsLocked)
exports.Lock();
}
}
catch
{
// if something goes wrong, remove the entry from the cache
cacheObject[fileName] = MondValue.Undefined;
throw;
}
return exports;
}