private bool TryParseType(string scriptCode, string typeName, out Type type) { type = null; if (string.IsNullOrEmpty(scriptCode)) { typeName = typeName ?? ""; scriptCode = ParseScriptCode(typeName); } scriptCode = GetScriptCode(scriptCode); Assembly assembly = _csharpAssembly; ScriptFileInfo scriptInfo = _csharpCodeCache[scriptCode]; if (scriptInfo == null) { scriptInfo = _modelCodeCache[scriptCode]; assembly = _modelAssembly; } if (scriptInfo != null) { if (assembly != null) { type = assembly.GetType(typeName, false, true); if (type == null) { type = Execute(scriptInfo.Source).GetType(); } } return(type != null); } return(false); }
/// <summary> /// /// </summary> /// <param name="fileName"></param> /// <returns></returns> public override bool VerifyScriptHashCode(string fileName) { string ext = Path.GetExtension(fileName); if (string.Compare(ext, ".cs", StringComparison.OrdinalIgnoreCase) != 0) { return(base.VerifyScriptHashCode(fileName)); } string scriptCode = GetScriptCode(fileName); if (File.Exists(fileName)) { if (fileName.EndsWith("AssemblyInfo.cs", StringComparison.OrdinalIgnoreCase)) { return(true); } ScriptFileInfo code = null; if (_modelCodeCache.ContainsKey(scriptCode)) { code = _modelCodeCache[scriptCode]; } if (_csharpCodeCache.ContainsKey(scriptCode)) { code = _csharpCodeCache[scriptCode]; } if (code == null) { return(false); } string source = Decode(File.ReadAllText(fileName), ext); return(code.HashCode == CryptoHelper.ToMd5Hash(source)); } return(false); }
private ScriptFileInfo LoadScript(string scriptPath, string fileName) { ScriptFileInfo scriptFileInfo = null; string scriptCode = GetScriptCode(fileName); scriptFileInfo = CreateScriptFile(fileName); if (scriptFileInfo != null) { if (scriptPath == _modelScriptPath) { _modelCodeCache[scriptCode] = scriptFileInfo; } else { _csharpCodeCache[scriptCode] = scriptFileInfo; } } return(scriptFileInfo); }
/// <summary> /// 创建脚本文件信息对象 /// </summary> /// <param name="fileName"></param> /// <returns></returns> public ScriptFileInfo CreateScriptFile(string fileName) { ScriptFileInfo scriptFileInfo = null; if (!File.Exists(fileName)) { return(scriptFileInfo); } string ext = Path.GetExtension(fileName); if (string.Compare(ext, ".cs", StringComparison.OrdinalIgnoreCase) == 0) { string fileCode = GetScriptCode(fileName); scriptFileInfo = new CSharpFileInfo(fileCode, fileName); scriptFileInfo.Source = Decode(File.ReadAllText(fileName), ext); scriptFileInfo.HashCode = CryptoHelper.ToMd5Hash(scriptFileInfo.Source); } else { TraceLog.WriteError("Not supported \"{0}\" file type.", fileName); } return(scriptFileInfo); }