小编Ran*_*ica的帖子

企业库4 dataconfiguration标记

我正在使用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)

asp.net enterprise-library asp.net-3.5

4
推荐指数
1
解决办法
7809
查看次数

Enterprise Library日志块的编程配置

我以前使用过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)

c# logging unit-testing enterprise-library

3
推荐指数
1
解决办法
6541
查看次数

如何使用Enterprise Library Logging登录到用户的ApplicationData文件夹?

我正在使用MS EnterpriseLibrary.Logging并且工作正常但日志文件放在程序可执行文件目录中.

如何将我的日志文件放在单个用户的applicationData文件夹中?

我正在谈论的文件夹是你通过调用获得的文件夹:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Run Code Online (Sandbox Code Playgroud)

.net logging enterprise-library

3
推荐指数
1
解决办法
3470
查看次数

从Canvas Scaler(Unity)中检索缩放量

我目前正在开发一个健康栏,慢慢消耗你的健康状况.我按照本教程获取了我想要的健康栏: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)

c# 2d unity-game-engine

3
推荐指数
1
解决办法
6760
查看次数

在C#中转换类型为Func <T,T>的对象时出现问题

为什么不编译?我想有办法解决这个问题; 只是好奇.

谢谢!

    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)

c# generics lambda

2
推荐指数
2
解决办法
660
查看次数

减少重复代码

我有一些像这样的颜色结构的代码

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)

因此,该值基本上是指所使用的变量.这有名字吗?这是反射的意义吗?或类似的东西......有没有办法做到这一点?

c# readability

2
推荐指数
1
解决办法
318
查看次数

动态注册通用类型

我想使用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# unity-container

2
推荐指数
1
解决办法
1253
查看次数

没有双重链表

我在C程序中使用双向链表.我对释放记忆感到困惑.

  1. 我应该逐节点地释放列表吗?
  2. 或者,通过将头节点和尾节点分配给NULL?

c linked-list

1
推荐指数
2
解决办法
5321
查看次数

c#中List <T>和List(Of T)之间的区别是什么

我很困惑,为什么微软文档有时指的是List类的List<T>,有时List(Of T).

c#

1
推荐指数
1
解决办法
89
查看次数

Unity 5防止滚动矩形移动鼠标

如何防止Scroll Rect用鼠标移动说例如我只想滚动条移动它而不是用鼠标拖动图像或文本?

unity-game-engine

1
推荐指数
1
解决办法
2805
查看次数