您在MS Excel(2003/2007)中使用了哪些版本的控制系统?你会推荐什么?为什么?您的顶级版本控制系统有哪些限制?
为了正确看待这一点,这里有几个用例:
请考虑以下示例代码:
class SampleClass
{
public long SomeProperty { get; set; }
}
public void SetValue(SampleClass instance, decimal value)
{
// value is of type decimal, but is in reality a natural number => cast
instance.SomeProperty = (long)value;
}
Run Code Online (Sandbox Code Playgroud)
现在我需要通过反思来做类似的事情:
void SetValue(PropertyInfo info, object instance, object value)
{
// throws System.ArgumentException: Decimal can not be converted to Int64
info.SetValue(instance, value)
}
Run Code Online (Sandbox Code Playgroud)
请注意,我不能假设PropertyInfo总是表示long,而且该值始终不是小数.但是,我知道可以将值转换为该属性的正确类型.
如何通过反射将'value'参数转换为PropertyInfo实例表示的类型?
在使用类型安全的VB.NET时,是否有等效的C#4'vynamic'关键字,即Option Strict On?
我的单页应用程序加载主页,我想显示一系列想法.每个想法都显示在一个动画flash容器中,动画显示在想法之间循环.
想法使用$ http加载:
$scope.flash = new FlashInterface scope:$scope,location:$location
$http.get("/competition.json")
.success (data) ->
$scope.flash._init data
Run Code Online (Sandbox Code Playgroud)
但是,要从历史导航和UX中受益,我希望更新地址栏以使用$ location显示每个想法的正确URL:
$location.path "/i/#{idea.code}"
$scope.$apply()
Run Code Online (Sandbox Code Playgroud)
我在这里调用$ apply,因为这个事件来自AngularJS上下文,即Flash.我希望保留当前的控制器/视图,并使视图不重新加载.这非常糟糕,因为重新加载视图会导致整个flash对象被抛弃并且预加载器循环再次开始.
我试过听$ routeChangeStart来做一个preventDefault:
$scope.$on "$routeChangeStart", (ev,next,current) ->
ev.preventDefault()
$scope.$on "$routeChangeSuccess", (ev,current) ->
ev.preventDefault()
Run Code Online (Sandbox Code Playgroud)
但无济于事.如果我在改变$ location.path时想出一种覆盖视图重载的方法,那么整个事情就会变得很糟糕.
我仍然非常感觉AngularJS,所以我很高兴有关如何构建应用程序以实现我的目标的任何指示!
这是关于使用反射转换值的问题的后续行动.将某种类型的对象转换为另一种类型可以这样做:
object convertedValue = Convert.ChangeType(value, targetType);
Run Code Online (Sandbox Code Playgroud)
给定两个Type实例(比如FromType和ToType),有没有办法测试转换是否成功?
我可以写一个像这样的扩展方法:
public static class TypeExtensions
{
public static bool CanChangeType(this Type fromType, Type toType)
{
// what to put here?
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:这就是我现在所拥有的.丑陋,但我还没有看到另一种方式......
bool CanChangeType(Type sourceType, Type targetType)
{
try
{
var instanceOfSourceType = Activator.CreateInstance(sourceType);
Convert.ChangeType(instanceOfSourceType, targetType);
return true; // OK, it can be converted
}
catch (Exception ex)
{
return false;
}
Run Code Online (Sandbox Code Playgroud) 问题几乎告诉了一切.
Continoustests是一个Windows安装程序(http://continuoustests.com/download.html),因此这里描述的技巧不起作用.
unit-testing continuous-testing visual-studio-2013 mightymoose
这一定是显而易见的,但我不能让它发挥作用.
我正在尝试使用环境变量($env:programfiles(x86))构建一个应该包含现有文件路径的变量.但是我一直在收到错误,我不明白为什么.
这工作正常(如果文件存在):
PS C:\> $f = "C:\Program Files (x86)" + '\sometextfile.txt'
PS C:\> $f
C:\Program Files (x86)\sometextfile.txt
PS C:\> gci $f
Directory: C:\Program Files (x86)
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 13/12/2010 14:03 0 sometextfile.txt
PS C:\>
Run Code Online (Sandbox Code Playgroud)
但是,这不是:
PS C:\> "$env:programfiles(x86)"
C:\Program Files(x86)
PS C:\> $f = "$env:ProgramFiles(x86)" + '\sometextfile.txt'
PS C:\> $f
C:\Program Files(x86)\sometextfile.txt
PS C:\> gci $f
Get-ChildItem : Cannot find path 'C:\Program Files(x86)\sometextfile.txt' because it does not exist.
At line:1 char:4 …Run Code Online (Sandbox Code Playgroud) 在 c# 9 中,我们现在(终于)有了记录类型:
public record SomeRecord(int SomeInt, string SomeString);
Run Code Online (Sandbox Code Playgroud)
这为我们提供了像值语义这样的好东西:
var r1 = new SomeRecord(0, "zero");
var r2 = new SomeRecord(0, "zero");
Console.WriteLine(r1 == r2); // true - property based equality
Run Code Online (Sandbox Code Playgroud)
在尝试使用此功能时,我意识到定义(非字符串)引用类型的属性可能会导致违反直觉(尽管如果您仔细考虑的话可以完美解释)行为:
public record SomeRecord(int SomeInt, string SomeString, int[] SomeArray);
var r1 = new SomeRecord(0, "test", new[] {1,2});
var r2 = new SomeRecord(0, "test", new[] {1,2});
Console.WriteLine(r1 == r2); // false, since int[] is a non-record reference type
Run Code Online (Sandbox Code Playgroud)
.Net(或第 3 方)中是否存在具有值语义的集合类型可用于此场景?我查看了 ImmutableArray 等,但这些也不提供此功能。
我们的(ASP.Net)应用程序必须与LDAP/Active Directory服务器通信以验证用户组.现在我们团队的几个成员需要能够断开连接.
有没有办法在开发机器上设置本地LDAP服务器(Windows 7 Pro)?
鉴于:
public interface IMyInterface{
}
public class MyClass:IMyInterface{
public MyClass(){}
}
public struct MyStruct:IMyInterface{
private int _myField;
public MyStruct(int myField){_myField = myField;}
}
Run Code Online (Sandbox Code Playgroud)
我为什么要写:
IEnumerable<IMyInterface> myClassImps = new[] {
new MyClass(),
new MyClass(),
new MyClass()
};
Run Code Online (Sandbox Code Playgroud)
但不是:
IEnumerable<IMyInterface> myStructImps = new[]{
new MyStruct(0),
new MyStruct(1),
new MyStruct(2)
};
Run Code Online (Sandbox Code Playgroud)
这给了我以下警告:
错误29无法隐式转换类型 'MyApp.MyNS.MyStruct []' 为 'System.Collections.Generic.IEnumerable <MyApp.MyNS.IMyInterface>'
而且必须写成:
IEnumerable<IMyInterface> myStructImps = new IMyInterface[]{
new MyStruct(0),
new MyStruct(1),
new MyStruct(2)
};
Run Code Online (Sandbox Code Playgroud) c# ×5
reflection ×2
.net ×1
angularjs ×1
c#-9.0 ×1
casting ×1
dynamic ×1
excel ×1
ldap ×1
mightymoose ×1
powershell ×1
unit-testing ×1
vb.net ×1
windows ×1