我正在运行时编译动态程序集.它需要引用另一个dll.只要我在CompilerParameters中设置了OutputAssembly,一切正常.但是一旦我设置了GenerateInMemory = true; 它失败:
var compilerParameters = new CompilerParameters();
if( compileInMemory )
compilerParameters.GenerateInMemory = true;
else
compilerParameters.OutputAssembly = "<my_dynamic_dll_path>";
compilerParameters.ReferencedAssemblies.Add( "<other_dll_path>" );
var compilerResults = new CSharpCodeProvider().CompileAssemblyFromDom( compilerParameters, codeCompileUnit );
// Here: compilerResults.Errors.HasErrors == false
foreach( var type in compilerResults.CompiledAssembly.GetTypes() )
{
// Exception:
// Unable to load one or more of the requested types.
// Retrieve the LoaderExceptions property for more information.
}
Run Code Online (Sandbox Code Playgroud)
LoaderExceptions告诉我无法找到"other_dll".为什么只要我不在内存中编译就可以工作,为了让它在内存中工作,我该怎么办呢?
某些方法(如string.Format()或.Parse())需要IFormatProvider.你是如何提供的?
在封闭环境应用程序中(您知道永远不需要本地化),您是否只是跳过它并在没有IFormatProvider的情况下调用方法?
在可能已本地化的应用程序中,您是否考虑了每个方法调用的正确值,并将其设置在那里?这可能是'CultureInfo.CurrentCulture'或'CultureInfo.CurrentUiCulture'.
或者您是否使用"MyUiCultureInfo"和"MyCultureInfo"等全局变量来通过更改其值来切换本地化?您如何以及在何处存储这些变量?
我开发库或框架时有什么需要考虑的 - 在这种情况下如何处理本地化?
鉴于以下课程 - 我想知道这两个成员中的哪一个是抽象的:
abstract class Test
{
public abstract bool Abstract { get; set; }
public bool NonAbstract { get; set; }
}
var type = typeof( Test );
var abs = type.GetProperty( "Abstract" );
var nonAbs = type.GetProperty( "NonAbstract" );
// now, something like:
if( abs.IsAbstract ) ...
Run Code Online (Sandbox Code Playgroud)
不幸的是,没有像IsAbstract
-property 那样的东西.
我需要选择一个类的所有非抽象字段/属性/方法 - 但也没有BindingFlags
缩小选择范围.
请看下面的代码:
var splashForm = new SplashForm();
m_Thread = new Thread( () => System.Windows.Forms.Application.Run( splashForm ) )
m_Thread.Start();
// Do some initialization
// ...
// the following method just invokes `Close()` on the right thread
splashForm.Shutdown();
// Loop until the thread is no longer alive
// ...
System.Windows.Forms.Application.Run( mainForm );
Run Code Online (Sandbox Code Playgroud)
它看起来好像一切正常:首先我看到了闪屏,后来主变形开始了.但不知怎的,我得到了奇怪的错误,例如:图形元素(无尽的ProgressBar)没有正确显示.
编辑:我有两个进度条,一个在启动画面上,在主窗体上.他们都在无尽模式中表现出相同(错误)的行为:没有进步,只有纯粹的背景./编辑
在我看来,这是由于Application.Run()
不同线程的调用.在启动启动画面之前,可以通过调用mainForm的任何函数/属性来消除此错误 - 例如
mainForm.Text = mainForm.Text;
Run Code Online (Sandbox Code Playgroud)
任何人都可以请确认此代码可能会导致问题 - 或者它应该表现良好,我必须在其他地方寻找错误?
我已经看过了flashscreen实现,我知道它可以以不同的方式完成.但我有兴趣了解这个实现及其可能存在的问题.谢谢!
有时我的课程需要获取一些构建信息。我不是在谈论对其他对象(将被注入)的引用,而是在谈论(例如)包含唯一信息的字符串:
// Scoped as singleton!
class Repository
{
public Repository( InjectedObject injectedObject, string path ) { ... }
}
Run Code Online (Sandbox Code Playgroud)
你如何注入这个字符串?一种可能性是编写一个Init()
方法并避免注入字符串:
class Repository
{
public Repository( InjectedObject injectedObject ) { ... }
public void Init( string path ) { ... }
}
Run Code Online (Sandbox Code Playgroud)
另一种可能性是将信息包装到一个可以注入的对象中:
class InjectedRepositoryPath
{
public InjectedRepositoryPath( string path ) { ... }
public string Path { get; private set; }
}
class Repository
{
public Repository( InjectedObject injectedObject, InjectedRepositoryPath path ) { ... }
}
Run Code Online (Sandbox Code Playgroud)
这样我就必须InjectedRepositoryPath …
我正在尝试使用c ++代码编写一个相当简单的ActiveX.问题是Release二进制文件在MFC90.DLL和MSVCR90.DLL上具有依赖性,它在调试时没有出现.怎么攻击这个?
我试图使用反射来检查给定类上的属性是否设置了ReadOnly属性.我使用的类是MVC视图模型(使用元数据的部分"伙伴"类.
public partial class AccountViewModel
{
public virtual Int32 ID { get; set; }
public virtual decimal Balance { get; set; }
}
[MetadataType(typeof(AccountViewModelMetaData))]
public partial class AccountViewModel
{
class AccountViewModelMetaData
{
[DisplayName("ID")]
public virtual Int32 ID { get; set; }
[DisplayName("Balance")]
[DataType(DataType.Currency)]
[ReadOnly(true)]
public virtual decimal Balance { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我想检查"Balance"是否具有ReadOnly属性.如果我在AccountViewModel的Balance属性上设置ReadOnly属性,我可以这样检索它:
Type t = typeof(AccountViewModel);
PropertyInfo pi = t.GetProperty("Balance");
bool isReadOnly = ReadOnlyAttribute.IsDefined(pi,typeof( ReadOnlyAttribute);
Run Code Online (Sandbox Code Playgroud)
如果它位于元数据类中,我无法检索属性信息.如何检查属性是否存在?我为所有视图模型定义了元数据类,并且需要通用的方法来检查元数据类的属性.
有什么建议?
我有一个对我的应用程序至关重要的工作线程.
它创建时new Thread( method ).Start();
我不加入它,我只是希望只要我的程序运行就会运行.
但是,可能会发生此线程上发生异常; 并且作为一个结果,线程将(除了一些最后的日志记录)关闭.此严重错误无法恢复.由于线程对于应用程序至关重要,因此它也必须关闭.
现在我的问题是:我如何监控线程的状态?
你会
IsAlive
?AppDomain.CurrentDomain.UnhandledException
?event
会发出后台线程结束的信号?BackgroundWorker
,哪个实现RunWorkerCompleted
?(但是对于长时间运行的线程,BackgroundWorker真的是正确的选择吗?)编辑:
现在,我通过调用Application.Exit()
- > 早期和经常崩溃来解决问题.这也是一个选择:)
如何在SQL Server 2008中比较印度时间与世界其他国家/地区的时间?
意味着我想知道在印度它的中午1点是通过SQL Server 2008在其他国家的时机
我希望一些共享变量应该在源文件main.c和secondary.c之间访问,我的头文件是all.h定义了共享数据类型,
#ifndef ALL_H
#define ALL_H
struct foo {
double v;
int i;
};
struct bar {
double x;
double y;
};
#endif
Run Code Online (Sandbox Code Playgroud)
main.c如下
/* TEST*/
#include "all.h"
#include "second.h"
int main(int argc, char* argv[])
{
struct foo fo; // should be accessed in second.c
fo.v= 1.1;
fo.i = 12;
struct bar ba; // should be accessed in second.c
ba.x= 2.1;
ba.y= 2.2;
sec(); // function defined in second.c
return 0;
}
Run Code Online (Sandbox Code Playgroud)
下面给出了secondary.h
#include …
Run Code Online (Sandbox Code Playgroud) c# ×6
reflection ×3
.net ×1
attributes ×1
c ×1
c++ ×1
localization ×1
mfc ×1
sql ×1
t-sql ×1
timezone ×1