小编Adi*_*ter的帖子

Unity中调用站点截获方法的完整堆栈跟踪

我们正在研究使用Unity来处理带有拦截的日志服务方法.但是,一个问题是呼叫站点没有完整的堆栈跟踪; 它只在拦截器调用中可用.

这是一个示例设置:

public interface IExceptionService
{
    void ThrowEx();
}

public class ExceptionService : IExceptionService
{
    public void ThrowEx()
    {
        throw new NotImplementedException();
    }
}

public class DummyInterceptor : IInterceptionBehavior
{
    public IEnumerable<Type> GetRequiredInterfaces()
    {
        return Type.EmptyTypes;
    }

    public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
    {
        IMethodReturn ret = getNext()(input, getNext);
        if (ret.Exception != null)
            Console.WriteLine("Interceptor: " + ret.Exception.StackTrace + "\r\n");
        return ret;
    }

    public bool WillExecute
    {
        get { return true; }
    }
}

class Program
{
    static void Main(string[] …
Run Code Online (Sandbox Code Playgroud)

.net unity-container unity-interception

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

使用"params"关键字的方法的几个重载

我看了一下Path.Combine,注意到它有四个重载:

  1. string, string
  2. string,string,string
  3. string,string,string,string
  4. params string[]

前三个重载如何有用?
我看到它的方式,第四次超载使其他人毫无意义.我查看了源代码,我确实看到第四个重载的实现有点不同,但即使在这种情况下,我也希望只有一个params重载决定根据数组的长度使用哪个实现.

.net c# overloading params-keyword

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

初始化惰性实例时,将参数传递给构造函数

据我所知,如果声明了变量Lazy,那么当我们使用该Value属性时会调用它的构造函数.

我需要将一些参数传递给此Lazy实例,但无法找到正确的语法.这不是我的设计,我正在使用MEF ExportFactory,它会返回我Lazy的部件实例.我的部分有构造函数,我需要用一些参数调用这些构造函数.

c# constructor mef lazy-initialization

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

数据触发器中的标记扩展

要翻译我的WPF应用程序,我使用Markup扩展,它返回一个Binding对象.这允许我在应用程序运行时切换语言.我像这样使用这个Markup:

<TextBlock Text="{t:Translate 'My String'}" />"
Run Code Online (Sandbox Code Playgroud)

我想通过数据触发器更改按钮文本:

<Button>
    <Button.Style>
        <Style TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <!-- Custom control template, note the TextBlock formating -->
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid x:Name="ContentHolder">
                            <ContentPresenter TextBlock.Foreground="Red" TextBlock.FontWeight="Bold" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <!-- Custom text triggered by Data Binding... -->
            <Style.Triggers>
                <DataTrigger Binding="{Binding MessageRowButton}" Value="Retry">
                    <Setter Property="Button.Content" Value="{t:Translate Test}" />
                </DataTrigger>
                <DataTrigger Binding="{Binding MessageRowButton}" Value="Acknowledge">
                    <Setter Property="Button.Content" Value="{t:Translate Test}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Button.Style>
</Button>
Run Code Online (Sandbox Code Playgroud)

这导致以下异常:

无法在"Setter"类型的"Value"属性上设置"绑定".'绑定'只能在DependencyObject的DependencyProperty上设置.

好的,这对我来说很有意义.我试图在我的资源中定义TextBlock并{StaticResource MyResource}在DataTrigger的Setter Value中使用.但是当我这样做时,我的Button的样式没有正确应用......

如何使用我的标记扩展并更改按钮上的文本而不会破坏在按钮内设置字符串样式的能力?

wpf xaml datatrigger markup-extensions

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

为什么我在此代码中获得"参数无效"异常?

private void button8_Click(object sender, EventArgs e)
{
    List<long> averages;
    long res = 0;
    _fi = new DirectoryInfo(subDirectoryName).GetFiles("*.bmp");
    averages = new List<long>(_fi.Length);
    for (int i = 0; i < _fi.Length; i++)
    {
        Bitmap myBitmaps = new Bitmap(_fi[i].Name);
        //long[] tt = list_of_histograms[i];
        long[] HistogramValues = GetHistogram(myBitmaps);
        res = GetTopLumAmount(HistogramValues,1000);
        averages.Add(res);
    }
}
Run Code Online (Sandbox Code Playgroud)

例外是在线:

Bitmap myBitmaps = new Bitmap(_fi[i].Name);
Run Code Online (Sandbox Code Playgroud)

.net c#

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

ArrayAdapter是原始类型警告?

我正在创建列表视图布局并收到ArrayAdapter警告.错误消息如下.警告消息指向以下文本:

new ArrayAdapter(this, android.R.layout.simple_list_item_1, populateList());
Run Code Online (Sandbox Code Playgroud)

任何帮助都会有所帮助

警告信息:

说明资源路径位置类型ArrayAdapter是原始类型.对泛型类型ArrayAdapter的引用应该参数化为LoginList.java/LoginPlus/src/com/loginplus/home line 95 Java问题

@Override
protected void onResume() {
    super.onResume();
loginListAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, populateList());
    loginList.setAdapter(loginListAdapter);
}
Run Code Online (Sandbox Code Playgroud)

android android-arrayadapter

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

web.downloadstring路径中的非法字符

我正在尝试使用正则表达式从网站中检索名称.但是,当我运行程序时,我使用"路径中的非法字符"得到错误.这是代码:

private void button1_Click(object sender, EventArgs e)
{
    List<string> givenNames = new List<string>();

    WebClient web = new WebClient();

    for (int i = 10000; i <= 33852; i++)
    {   
        string numberurl = i.ToString();
        string mainurl = "www.cpso.on.ca/docsearch/details.aspx?view=1&id=+" + numberurl;
        String html = web.DownloadString(mainurl);

        Match m = Regex.Match(html, @"</strong>\s*(.+?)\s*&nbsp;", RegexOptions.Singleline);

        string givenName = m.Groups[1].Value;
        givenNames.Add(givenName);
    }
    listBox1.DataSource = givenNames; 
}
Run Code Online (Sandbox Code Playgroud)

错误发生在String html = web.DownloadString(mainurl);.我尝试使用HttpUtility.UrlEncode但它仍然无法正常工作.我很感激帮助.

c# webforms

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

通过后台代码设置 DataGridTextColumn.ElementStyle

我的用户界面中有一个数据网格。数据表将绑定到它。因为数据表可能有不同的格式,所以我在后面的代码中为网格添加了列和绑定值。见下文:

for (int iLoop = 0; iLoop < dtGroup.Columns.Count; iLoop++)
{
    DataGridTextColumn dgColumn = new DataGridTextColumn();
    dgColumn.Header = dtGroup.Columns[iLoop].ColumnName;
    dgColumn.Binding = new Binding(dtGroup.Columns[iLoop].ColumnName);


    this.dgGroupMatrix.Columns.Add(dgColumn);
}
Run Code Online (Sandbox Code Playgroud)

我想要的是让网格单元格的背景颜色基于值。

我可以通过 XAML 做到这一点。

<DataGrid.Columns>
    <DataGridTextColumn Binding="{Binding Path= operation_name}" Header="operation_name">
        <DataGridTextColumn.ElementStyle>
            <Style TargetType="{x:Type TextBlock}">
                <Style.Triggers>
                    <Trigger Property="Text" Value="V31">
                        <Setter Property="Background" Value="LightGreen"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </DataGridTextColumn.ElementStyle>
    </DataGridTextColumn>
</DataGrid.Columns>
Run Code Online (Sandbox Code Playgroud)

但是我不能在 XAML 中设置网格的列,因为这个网格会有不同的格式。

我能做什么?

c# wpf xaml datagrid

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

为什么BackgroundWorker不需要在ProgressChanged事件处理程序中调用?

由于ProgressChanged事件处理程序是从事件处理程序中的某个地方引发的DoWork,因此它们不应该在异步操作线程DoWork上调用,而线程也在运行,而不是UI线程,因此需要调用或BeginInvoke操作控件?

我的猜测是在ReportProgress方法中发生了一些魔法,但它怎么知道,哪一个是调用ProgressChanged事件处理程序的正确线程?

.net c# backgroundworker

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

如何使用泛型将我的类转换为动态类型<T>

我有如下功能.

private IList<ContactList> getEmptyRow()
{
    var _ContactList = new List<ContactList>();
    _ContactList.Add(new ContactList()
    {
        Email = string.Empty,
        Name = string.Empty
    });

    return _ContactList;
}
Run Code Online (Sandbox Code Playgroud)

我想把我的班级ContactList改为

private IList<T> getEmptyRow() {  ..... T.Add(new T()....
Run Code Online (Sandbox Code Playgroud)

这可能吗 ?如何 ?
每个建议都将不胜感激.

c# generics

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