我们正在研究使用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) 我看了一下Path.Combine
,注意到它有四个重载:
string
, string
string
,string
,string
string
,string
,string
,string
params string[]
前三个重载如何有用?
我看到它的方式,第四次超载使其他人毫无意义.我查看了源代码,我确实看到第四个重载的实现有点不同,但即使在这种情况下,我也希望只有一个params
重载决定根据数组的长度使用哪个实现.
据我所知,如果声明了变量Lazy
,那么当我们使用该Value
属性时会调用它的构造函数.
我需要将一些参数传递给此Lazy
实例,但无法找到正确的语法.这不是我的设计,我正在使用MEF ExportFactory
,它会返回我Lazy
的部件实例.我的部分有构造函数,我需要用一些参数调用这些构造函数.
要翻译我的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的样式没有正确应用......
如何使用我的标记扩展并更改按钮上的文本而不会破坏在按钮内设置字符串样式的能力?
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) 我正在创建列表视图布局并收到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) 我正在尝试使用正则表达式从网站中检索名称.但是,当我运行程序时,我使用"路径中的非法字符"得到错误.这是代码:
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* ", 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
但它仍然无法正常工作.我很感激帮助.
我的用户界面中有一个数据网格。数据表将绑定到它。因为数据表可能有不同的格式,所以我在后面的代码中为网格添加了列和绑定值。见下文:
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 中设置网格的列,因为这个网格会有不同的格式。
我能做什么?
由于ProgressChanged
事件处理程序是从事件处理程序中的某个地方引发的DoWork
,因此它们不应该在异步操作线程DoWork
上调用,而线程也在运行,而不是UI线程,因此需要调用或BeginInvoke
操作控件?
我的猜测是在ReportProgress
方法中发生了一些魔法,但它怎么知道,哪一个是调用ProgressChanged
事件处理程序的正确线程?
我有如下功能.
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# ×7
.net ×4
wpf ×2
xaml ×2
android ×1
constructor ×1
datagrid ×1
datatrigger ×1
generics ×1
mef ×1
overloading ×1
webforms ×1