我正在玩这两个原生的win32函数:
[DllImport( "oleacc.dll" )]
public static extern int AccessibleObjectFromWindow(
IntPtr hwnd,
int dwObjectID,
ref Guid refID,
ref Accessibility.IAccessible ppvObject );
[DllImport( "oleacc.dll" )]
public static extern uint AccessibleChildren(
Accessibility.IAccessible paccContainer,
int iChildStart,
int cChildren,
[Out] object[] rgvarChildren,
out int pcObtained );
Run Code Online (Sandbox Code Playgroud)
而且我很难搞清楚我是否应该/需要在任何返回的对象上调用Marshal.ReleaseComObject.我很感激有人可以开导我这个话题!这是一个示例用法:
Accessibility.IAccessible test(
int hWnd,
string accessName )
{
Guid guidCOM = new Guid( 0x618736E0, 0x3C3D, 0x11CF, 0x81, 0xC, 0x0, 0xAA, 0x0, 0x38, 0x9B, 0x71 );
Accessibility.IAccessible a = null;
AccessibleObjectFromWindow(
new IntPtr( hWnd ),
-4,
ref guidCOM,
ref …Run Code Online (Sandbox Code Playgroud) 我有一个实现IDisposable的类,因为它有一个私有成员字段"foo",它是IDisposable(在构造函数中初始化).我出乎意料地得到了CA2000代码分析错误,这要求我确保丢弃foo.但是,我在我的类的Dispose()代码中有foo.Dispose(),它应该处理这个问题.
我做了一些搜索,令人惊讶的是找不到答案.我究竟做错了什么?显然我遗漏了一些基本的东西.如何编写代码来克服这个问题?
我的VB代码:
Public Class Bar
Implements IDisposable
Private Foo As SomeDisposableThing
Public Sub New()
Foo = New SomeDisposableThing() With {.name = "hello"}
End Sub
'''' snip ''''
Private disposedValue As Boolean = False ' To detect redundant calls '
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
If Foo IsNot Nothing Then Foo.Dispose()
End If
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
End Class
Run Code Online (Sandbox Code Playgroud) 我有一个对象,我正在序列化为xml.看来其中一个属性中的值包含十六进制字符0x1E.我已经尝试将XmlWriterSettings的Encoding属性设置为"utf-16"和"unicode"但我仍然会抛出异常:
这是生成XML文档的错误.---> System.InvalidOperationException:生成XML文档时出错.---> System.ArgumentException:'',十六进制值0x1E,是无效字符.
有没有办法让这些字符进入xml?如果没有,是否还有其他字符会导致问题?
我很困惑为什么new运营商没有像我预期的那样工作.
注意:以下所有类都在同一名称空间中定义,并在同一文件中定义.
此类允许您使用一些提供的文本为写入控制台的任何内容添加前缀.
public class ConsoleWriter
{
private string prefix;
public ConsoleWriter(string prefix)
{
this.prefix = prefix;
}
public void Write(string text)
{
Console.WriteLine(String.Concat(prefix,text));
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个基类:
public class BaseClass
{
protected static ConsoleWriter consoleWriter = new ConsoleWriter("");
public static void Write(string text)
{
consoleWriter.Write(text);
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个实现的类:
public class NewClass : BaseClass
{
protected new static ConsoleWriter consoleWriter = new ConsoleWriter("> ");
}
Run Code Online (Sandbox Code Playgroud)
现在这是执行此操作的代码:
class Program
{
static void Main(string[] args)
{
BaseClass.Write("Hello World!");
NewClass.Write("Hello World!");
Console.Read(); …Run Code Online (Sandbox Code Playgroud) 你如何明确地告诉EF一个表位于特定模式中?
例如,AdventureWorks数据库定义了Production.Product表.使用该OnModelCreating方法时,我使用以下代码:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
EntityTypeConfiguration<Product> config = modelBuilder.Entity<Product>();
config.HasKey(p => p.ProductID);
config.Property(p => p.Price).HasColumnName("ListPrice");
config.ToTable("Product");
}
Run Code Online (Sandbox Code Playgroud)
然而,当它运行时,它说Invalid object name: dbo.Product.
我试过了:
config.ToTable("Production.Product");
//and
config.HasEntityName("Production");
Run Code Online (Sandbox Code Playgroud)
但两者都失败了.
CA2000是关于IDisposable接口的警告:
CA2000:Microsoft.Reliability:在方法'ImportProcessor.GetContext(string)'中,在对所有引用超出范围之前,在对象'c'上调用System.IDisposable.Dispose.
我的方法用于存储上下文缓存,如下所示:
public class RegionContext : IDisposable { /* Implement Dispose() here */ }
private Dictionary<string, RegionContext> contextCache = new ..... ();
public RegionContext GetContext(string regionCode)
{
RegionContext rc = null;
if (!this.contextCache.TryGetValue(regionCode.ToUpper(), out rc))
{
rc = new RegionContext(regionCode);
this.contextCache.Add(regionCode.ToUpper(), rc);
}
return rc;
}
Run Code Online (Sandbox Code Playgroud)
你会在哪里使用using()修复此编译器警告的语句?
我的外部类实际上会迭代并处理contextCache其自己的实现中的内容.我要压制它,还是有办法正确摆脱这个警告?
有一个月我正在使用logstash,所以我仍在学习它的基础知识,还有elasticsearch和kibana.昨天,我尝试安装并开始使用新版本"logstash 1.4.0".为此,我按照此链接,但当我尝试使用以下命令运行logstash时:
bin\logstash -e 'input { stdin { } } output { stdout {} }'
我收到此错误:
"bin"不被识别为内部或外部命令,可操作程序或批处理文件.
输出如下:
No such command "-e"
Usage: logstash <command> [command args]
Run a command with the --help flag to see the arguments.
For example: logstash agent --help
Available commands:
agent - runs the logstash agent
version - emits version info about this logstash
web - runs the logstash web ui (called Kibana)
rspec - runs tests
Run Code Online (Sandbox Code Playgroud)
有关信息,当我运行java-version时,我得到这个:
java version "1.7.0_40"
Java(TM) SE …Run Code Online (Sandbox Code Playgroud) MessageBox.Show()在MonoMac中是否有相同的内容,或者我是否必须专门为此目的创建某种弹出类?
Autofac新手在这里想要更好地理解以下异常,任何帮助/指针将非常感谢!
Unhandled Exception:
Autofac.Core.DependencyResolutionException:
None of the constructors found with 'Public binding flags' on type 'Test.Authorization.LoginService' can be invoked with the available services and parameters:
Cannot resolve parameter 'System.Func`1[System.IO.Stream] readStream' of constructor 'Void .ctor(System.Func`1[System.IO.Stream], System.Func`1[System.IO.Stream])'.
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) in \autofac\src\Source\Autofac\Core\Activators\Reflection\ReflectionActivator.cs:line 117
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) in \autofac\src\Source\Autofac\Core\Resolving\InstanceLookup.cs:line 79
at Autofac.Core.Resolving.InstanceLookup.Execute() in \autofac\src\Source\Autofac\Core\Resolving\InstanceLookup.cs:line 62
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters) in \autofac\src\Source\Autofac\Core\Resolving\ResolveOperation.cs:line 124
at Autofac.Core.Resolving.InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters) in \autofac\src\Source\Autofac\Core\Resolving\InstanceLookup.cs:line 115
at Autofac.Features.Collections.CollectionRegistrationSource.c__DisplayClass4.c__DisplayClass6.b__1(IComponentRegistration cr) in \autofac\src\Source\Autofac\Features\Collections\CollectionRegistrationSource.cs:line 80 at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() … c# ×5
.net ×4
autofac ×1
ca2000 ×1
com ×1
css ×1
data-access ×1
fxcop ×1
html ×1
idisposable ×1
inheritance ×1
interop ×1
logstash ×1
monomac ×1
navbar ×1
new-operator ×1
vb.net ×1
xml ×1