/// <summary> /// Return a ScriptSource object from string contents. These are helpers for creating ScriptSources' with the right language binding. /// </summary> public ScriptSource CreateScriptSourceFromString(string code, string path, SourceCodeKind kind) { ContractUtils.RequiresNotNull(code, "code"); ContractUtils.Requires(EnumBounds.IsValid(kind), "kind"); return(CreateScriptSource(new SourceStringContentProvider(code), path, kind)); }
/// <summary> /// These methods return ScriptSource objects from stream contents with the current engine as the language binding. /// /// The encoding defaults to Encoding.Default. /// </summary> public ScriptSource CreateScriptSource(StreamContentProvider content, string path, Encoding encoding, SourceCodeKind kind) { ContractUtils.RequiresNotNull(content, "content"); ContractUtils.RequiresNotNull(encoding, "encoding"); ContractUtils.Requires(EnumBounds.IsValid(kind), "kind"); return(CreateScriptSource(new LanguageBoundTextContentProvider(_language, content, encoding), path, kind)); }
public SourceUnit CreateSourceUnit(TextContentProvider contentProvider, string path, SourceCodeKind kind) { ContractUtils.RequiresNotNull(contentProvider, "contentProvider"); ContractUtils.Requires(path == null || path.Length > 0, "path", Strings.EmptyStringIsInvalidPath); ContractUtils.Requires(EnumBounds.IsValid(kind), "kind"); ContractUtils.Requires(CanCreateSourceCode); return(new SourceUnit(this, contentProvider, path, kind)); }
/// <summary> /// This method returns a ScriptSource with the content provider supplied with the current engine as the language binding. /// /// This helper lets you own the content provider so that you can implement a stream over internal host data structures, such as an editor's text representation. /// </summary> public ScriptSource CreateScriptSource(TextContentProvider contentProvider, string path, SourceCodeKind kind) { ContractUtils.RequiresNotNull(contentProvider, "contentProvider"); ContractUtils.Requires(EnumBounds.IsValid(kind), "kind"); if (!_language.CanCreateSourceCode) { throw new NotSupportedException("Invariant engine cannot create scripts"); } return(new ScriptSource(this, _language.CreateSourceUnit(contentProvider, path, kind))); }
/// <summary> /// Return a ScriptSource object from file contents with the current engine as the language binding. /// /// The path's extension does NOT have to be in ScriptRuntime.GetRegisteredFileExtensions /// or map to this language engine with ScriptRuntime.GetEngineByFileExtension. /// /// The ScriptSource's Path property will be the path argument. /// </summary> public ScriptSource CreateScriptSourceFromFile(string path, Encoding encoding, SourceCodeKind kind) { ContractUtils.RequiresNotNull(path, "path"); ContractUtils.RequiresNotNull(encoding, "encoding"); ContractUtils.Requires(EnumBounds.IsValid(kind), "kind"); if (!_language.CanCreateSourceCode) { throw new NotSupportedException("Invariant engine cannot create scripts"); } return(new ScriptSource(this, _language.CreateFileUnit(path, encoding, kind))); }