我正在使用Enterprise库进行数据访问.当我运行应用程序时,在CreateDatabase()语句中,我收到此异常:
用户代码未处理Microsoft.Practices.ObjectBuilder2.BuildFailedException消息="当前构建操作(构建密钥构建密钥[Microsoft.Practices.EnterpriseLibrary.Data.Database,null])失败:值不能为null或为空字符串.(策略类型Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy,index 2)"Source ="Microsoft.Practices.ObjectBuilder2"
现在,我google了一下,发现我必须放置
<dataConfiguration defaultDatabase="LocalSqlServer"/>
Run Code Online (Sandbox Code Playgroud)
但我不知道在哪里.这是正确的解决方案吗?
另外,在安装企业库时我没有看到任何连接字符串声明?所以,我想知道如何从web.config文件中获取连接字符串.
在我的web.config文件的连接字符串部分中,我有:
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
Run Code Online (Sandbox Code Playgroud) 我以前使用过log4net,但我现在的雇主使用Enterprise Library应用程序块.我之前已经为我的核心日志记录类开发了单元测试,如下所示,并且想知道是否有人知道以下针对日志记录应用程序块的OneTimeSetup代码(对于长代码帖子而言):
public abstract class DataGathererBase
{
public readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void CollectData()
{
this.LogDebug("Initialize started");
}
public static class Logger
{
private static LoggingSettings settings = LoggingSettings.GetLoggingSettings(new SystemConfigurationSource());
static Logger()
{
log4net.Config.XmlConfigurator.Configure();
}
public static void LogDebug(this DataGathererBase current, string message)
{
if (current.logger.IsDebugEnabled)
{
current.logger.Debug(string.Format("{0} logged: {1}", current.GetType().Name, message));
}
}
}
[TestFixture]
public class LoggerTests:DataGathererBase
{
private ListAppender appender;
private static ILog log;
[TestFixtureSetUp]
public void OneTimeSetup()
{
appender = new ListAppender();
appender.Layout = …Run Code Online (Sandbox Code Playgroud) 我正在使用MS EnterpriseLibrary.Logging并且工作正常但日志文件放在程序可执行文件目录中.
如何将我的日志文件放在单个用户的applicationData文件夹中?
我正在谈论的文件夹是你通过调用获得的文件夹:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个健康栏,慢慢消耗你的健康状况.我按照本教程获取了我想要的健康栏:https://www.youtube.com/watch?v = NgftVg3idB4
简而言之,它使用遮罩层和单独的绿色条来指示健康状况.通过向左移动绿色条,它会消失在遮罩层后面,从而显示出越来越少的健康状况.根据健康状况计算其位置的方法如下:代码(CSharp):
float maxXValue = healthTransform.position.x;
float minXValue = healthTransform.position.x - healthTransform.rect.width;
private void HandleHealth()
{
Stats attachedStats = attachedObject.GetComponent<Stats>();
float currentXValuePlayer = MapValues(attachedStats.currentHealth, 0, attachedStats.maxHealth, minXValue, maxXValue);
healthTransform.position = new Vector3(currentXValuePlayer, cachedY);
}
private float MapValues(float x, float inMin, float inMax, float outMin, float outMax)
{
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}
/*
EXPLANATION:
attachedStats.currentHealth is the current health the player has
attachedStats.maxHealth is the …Run Code Online (Sandbox Code Playgroud) 为什么不编译?我想有办法解决这个问题; 只是好奇.
谢谢!
static void Main(string[] args)
{
Func<int, int> f_int = n => n * n;
Func<int, double> f_double = (Func<int, double>)f_int;
}
Run Code Online (Sandbox Code Playgroud) 我有一些像这样的颜色结构的代码
public void ChangeColor()
{
thisColor.R = thisColor.R + 5;
}
Run Code Online (Sandbox Code Playgroud)
现在我需要创建一个方法,根据传递的内容更改不同的变量.这是代码现在的样子.
public void ChangeColor(int RGBValue)
{
switch(RGBValue)
{
case 1:
thisColor.R = thisColor.R + 5;
break;
case 2:
thiscolor.B = thisColor.B + 5;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,这是我通常不会质疑的东西,我只是在它周围抛出一个#region语句并称之为一天,但这只是我所拥有的一个例子,实际的功能很长.
我希望它看起来像这样:
public void ChangeColor(int RGBValue)
{
thiscolor.RGBValue = thiscolor.RGBValue;
}
Run Code Online (Sandbox Code Playgroud)
因此,该值基本上是指所使用的变量.这有名字吗?这是反射的意义吗?或类似的东西......有没有办法做到这一点?
我想使用Unity注册一个通用的Repository类.
这是我的通用类:
public class Repository<TModel>
: IRepository<TModel> where TModel : class, IModel
Run Code Online (Sandbox Code Playgroud)
TModel是与Entity一起使用的POCO对象.
如果我这样注册就行了.
IOC_Container.RegisterType(typeof(IRepository<Employee>), typeof(Repository<Employee>));
Run Code Online (Sandbox Code Playgroud)
这需要我注册每个TModel,这变得很麻烦.
我有一个使用反射动态注册我的服务类的引导程序,我想对存储库执行相同的操作.
这是服务的引导程序代码:
var currentAssembly = Assembly.LoadFrom(assembly);
var assemblyTypes = currentAssembly.GetTypes();
foreach (var assemblyType in assemblyTypes)
{
if (assemblyType.IsInterface)
{
continue;
}
if (assemblyType.FullName.EndsWith("Service"))
{
foreach (var requiredInterface in assemblyType.GetInterfaces())
{
if (requiredInterface.FullName.EndsWith("Service"))
{
var typeFrom = assemblyType.GetInterface(requiredInterface.Name);
var typeTo = assemblyType;
IOC_Container.RegisterType(typeFrom, typeTo);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
有什么建议?
我在C程序中使用双向链表.我对释放记忆感到困惑.
如何防止Scroll Rect用鼠标移动说例如我只想滚动条移动它而不是用鼠标拖动图像或文本?
c# ×6
logging ×2
.net ×1
2d ×1
asp.net ×1
asp.net-3.5 ×1
c ×1
generics ×1
lambda ×1
linked-list ×1
readability ×1
unit-testing ×1