出于调试目的,我可以在C/C++编译器中获取行号吗?(某些编译器的标准方式或特定方式)
例如
if(!Logical)
printf("Not logical value at line number %d \n",LineNumber);
// How to get LineNumber without writing it by my hand?(dynamic compilation)
Run Code Online (Sandbox Code Playgroud) 这就是我想要做的事情:
$clsName = substr(md5(rand()),0,10); //generate a random name
$cls = new $clsName(); //create a new instance
function __autoload($class_name)
{
//define that instance dynamically
}
Run Code Online (Sandbox Code Playgroud)
显然这不是我实际做的,但基本上我有一个类的未知名称,并根据名称,我想生成具有某些属性等的类.
我已经尝试过使用eval(),但它让我更适合私人和$ this->引用......
//编辑
好吧,很明显,我的短暂和甜蜜的"这就是我想做的事情"在那些可能提供答案的人中引起了巨大的冲突和惊愕.为了得到一个真正的答案,我会更详细.
我有一个验证框架,使用我维护的网站上的代码提示.每个函数都有两个定义
function DoSomething($param, $param2){
//code
}
function DoSomething_Validate(vInteger $param, vFloat $param2){
//return what to do if validation fails
}
Run Code Online (Sandbox Code Playgroud)
我想在我的数据库中为主键添加验证器.我不想为每个表创建一个单独的类(203).所以我的计划是做类似的事情
function DoSomething_Validate(vPrimaryKey_Products $id){ }
Run Code Online (Sandbox Code Playgroud)
__autoload将生成vPrimaryKey的子类并将table参数设置为Products.
现在开心?
我有一个非常有线的错误,我的一个自定义控件似乎是创建两个编译文件,当我尝试动态加载它LoadControl()
只是失败因为无法将一个转换为另一个 - 即使它们完全相同.我写的消息看到的一切都是一样的,只是改变了编译过的dll.
System.Web.HttpUnhandledException (0x80004005):
Exception of type 'System.Web.HttpUnhandledException' was thrown. --->
System.InvalidCastException:
[A]ASP.Modules_OneProduct_MedioumImage cannot be cast to
[B]ASP.Modules_OneProduct_MedioumImage.
Type A originates from 'App_Web_kg4bazz1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
in the context 'Default'
at location 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\80ed7513\10eb08d9\App_Web_kg4bazz1.dll'.
Type B originates from 'App_Web_oneproduct_mediumimage.ascx.d1003923.4xoxco7b, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
in the context 'Default'
at location 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\80ed7513\10eb08d9\App_Web_oneproduct_mediumimage.ascx.d1003923.4xoxco7b.dll'.
Run Code Online (Sandbox Code Playgroud)
在我完全按照MSDN上的内容编写后,这就是现在的代码:
foreach (int OneProductID in TheProductIdArrays)
{
// here is the throw.
ASP.Modules_OneProduct_MedioumImage OneProduct =
(ASP.Modules_OneProduct_MedioumImage)LoadControl(@"~/mod/OneProduct_MediumImage.ascx");
// do some work with
//OneProduct …
Run Code Online (Sandbox Code Playgroud) c# asp.net compiler-construction user-controls dynamic-compilation
我知道,通过ASP.NET网站下的动态编译,文件后面的代码可以编译成程序集.运行IIS Express时,这些DLL的存储位置在哪里?它只在记忆中吗?我没有在bin文件夹或临时目录(C:\ Windows\Microsoft.NET\Framework [64]\v4.0.30319)中看到它们.通常我会在我发布时预编译它们时生成它们.但在这种情况下,我看不到它们.
我错过了什么吗?
谢谢.
更新:
我确实在C:\ Users\Administrator\AppData\Local\Temp\Temporary ASP.NET Files\root下看到了dll
所以我认为它存储在那里?这是Visual Studio 2012,.NET 4.5.
我正在构建一个使用MEF的MVC 3应用程序.主要思想是具有插件机制,其中模型,控制器和视图在运行时从mef容器动态加载.
每个插件/模块由两个程序集组成:
并放在Web应用程序bin中的Plugins目录中:
还有所有其他模块引用的核心模块:ModuleCore.Data.dll和ModuleCore.Web.dll.
然后,在Global.asax中,以下列方式构建容器:
AggregateCatalog catalog = new AggregateCatalog();
var binCatalog = new DirectoryCatalog(HttpRuntime.BinDirectory, "Module*.dll");
var pluginsCatalot = new DirectoryCatalog(Path.Combine(HttpRuntime.BinDirectory, "Plugins"), "Module*.dll");
catalog.Catalogs.Add(binCatalog);
catalog.Catalogs.Add(pluginsCatalot);
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this);
AppDomain.CurrentDomain.AppendPrivatePath(Path.Combine(HttpRuntime.BinDirectory, "Plugins"));
Run Code Online (Sandbox Code Playgroud)
创建并注册CustomViewEngine并用于在模块程序集中查找视图:
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CustomViewEngine());
Run Code Online (Sandbox Code Playgroud)
控制器工厂从容器加载控制器:
ControllerBuilder.Current.SetControllerFactory(new MefControllerFactory(_container));
Run Code Online (Sandbox Code Playgroud)
以及从容器中获取程序集的自定义虚拟路径提供程序:
HostingEnvironment.RegisterVirtualPathProvider(new ModuleVirtualPathProvider());
Run Code Online (Sandbox Code Playgroud)
好的,所以处理可插拔模型,控制器和视图的整个基础设施已准备就绪.现在一切正常......除了一件事 - 强类型视图.
为了更详细地说明问题,让我们准备场景:
现在我们执行以下操作:
因此,似乎编译器/构建器没有查看Module1.Data.dll的bin/Plugins文件夹,因为当我将此文件复制到bin文件夹时 - 措辞很好. …
mef dynamic-compilation strongly-typed-view razor asp.net-mvc-3
我在Java 6中的动态编译工作正常.但是,我想改变输出路径.我已经尝试了很多东西(我会饶了你)无济于事.无论如何,这是工作代码
String[] filesToCompile = { "testFiles/Something.java" };
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(filesToCompile);
CompilationTask task = compiler.getTask(null, fileManager, null,null, null, compilationUnits);
System.out.println("Good? " + task.call());
Run Code Online (Sandbox Code Playgroud)
但输出转到源目录,这不是我想要的.
我怀疑答案可能在于答案,compiler.getTask
但API并不是非常清楚某些参数可能意味着什么.或者也许使用fileManager.我试过了
fileManager.setLocation(StandardLocation.locationFor("testFiles2"), null);
Run Code Online (Sandbox Code Playgroud)
但同样,猜测可能不是一个好主意.
谢谢!
编辑:我也试过使用选项,这样(对不起,如果有更紧凑的方式):
final List<String> optionsList = new ArrayList<String>();
optionsList.add("-d what");
Iterable<String> options = new Iterable<String>() {
public Iterator<String> iterator() {
return optionsList.iterator();
}
};
Run Code Online (Sandbox Code Playgroud)
然后将选项传递给getTask,但错误消息是"无效标志".
我有一个使用System.AddIn建立的插件向量,它接受预定义方法的主体,将方法体导入样板代码,生成程序集并执行方法.
程序集引用System
和System.Core
沙箱
var pset = new PermissionSet(PermissionState.None);
pset.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
Run Code Online (Sandbox Code Playgroud)
我可以找到唯一的例外参考可能会导致主机堆栈溢出,可以调用任意数量的创造性手段,例如关闭正文并声明递归方法等...
然后有被引用的程序集暴露的可能的攻击向量,System
和System.Core
.
我的问题是:这有多安全以及哪些恶意代码可能会导致主机崩溃以及防止此类攻击的可能方法?
更新:对于那些熟悉Managed AddIn Framework的人,也应用同样的问题AddInSecurityLevel.Internet
.
假设代码如下:
public class DynamicAspxHandler : IHttpHandler {
bool IHttpHandler.IsReusable { get { return false; } }
void IHttpHandler.ProcessRequest(HttpContext httpContext) {
string aspxContent = PlainASPXContent();
Page page = CreatePage(httpContext, aspxContent);
page.ProcessRequest(httpContext);
}
Page CreatePage(HttpContext context, string aspxContent) {
// How to implement this?
}
}
Run Code Online (Sandbox Code Playgroud)
如何实现CreatePage方法基于ASPX的纯字符串内容实例化页面?
注意,ASPX字符串本身可以包含对磁盘上已存在的MasterPage的引用.
我意识到这一点必然存在巨大的性能问题,但在这个阶段我只想知道如何做到这一点.显然我必须缓存结果.
谢谢.
我一直在尝试使用GHC API进行一些基本的动态代码编译,遵循此处的教程.
这段代码:
import GHC
import GHC.Paths
import DynFlags
import Unsafe.Coerce
main :: IO ()
main =
defaultErrorHandler defaultDynFlags $ do
func <- runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
setSessionDynFlags dflags
target <- guessTarget "Test.hs" Nothing
addTarget target
r <- load LoadAllTargets
case r of
Failed -> error "Compilation failed"
Succeeded -> do
m <- findModule (mkModuleName "Test") Nothing
setContext [] [m]
value <- compileExpr ("Test.print")
do let value' = (unsafeCoerce value) :: String -> IO …
Run Code Online (Sandbox Code Playgroud) 我一直在玩插件包.我希望主机应用程序在沙盒环境中动态编译和加载Haskell源文件.编译工作正常.只要插件仅引用沙箱中可用的模块,加载就会失败.这是我为插件所获得的:
module Plugin (resource) where
import ServerAPI
import System.Plugins -- this module is only available in the sandbox
resource = Interface { action = timesTwo }
timesTwo :: Integer -> IO Integer
timesTwo n = return $ n * 2
Run Code Online (Sandbox Code Playgroud)
从宿主应用程序加载插件如下所示:
pkgConfDir = "/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
loadedOk <- pdynload "Plugin.o" ["."] [pkgConfDir] "ServerAPI.Interface" "resource"
Run Code Online (Sandbox Code Playgroud)
这就是我在沙盒中得到的:
> cabal sandbox hc-pkg list
…
/home/me/plugins/.cabal-sandbox/x86_64-osx-ghc-7.8.4-packages.conf.d
plugins-1.5.4.0
…
Run Code Online (Sandbox Code Playgroud)
这是我在运行主机应用程序时得到的:
Failed to load interface for ‘System.Plugins.Env’
no package matching ‘plugins-1.5.4.0’ was found
Run Code Online (Sandbox Code Playgroud)
如上所述,当我摆脱import System.Plugins …