在VS2005 C#项目中,我添加了对System.configuration的引用.在对象浏览器中,我可以看到System.Configuration.ConfigurationManager.在Intellisense System.Configuration中只有旧的ConfigurationSettings,而不是ConfigurationManager.
我的代码System.Configuration.ConfigurationManager.AppSettings ["MySetting"]
突出显示为语法错误,不编译.
在一个不同的项目中,完全相同的设置工作正常...任何线索关于发生了什么?
如何获得(可能)在GAC中注册的DLL的(物理)安装路径?此DLL是一个控件,可以托管在.Net应用程序以外的东西中(包括除VS之外的IDE ...).
当我使用System.Reflection.Assembly.GetExecutingAssembly().Location时,它给出了winnt\system32中GAC文件夹的路径 - 或者在VS中的设计模式中给出了VS IDE的路径.
我需要获得实际安装物理dll的路径 - 或者VS的bin/debug或(release)文件夹.
原因是我需要在此文件夹中获取一个XML文件,其配置设置既可以在设计模式下使用,也可以在运行时使用.
或者如何处理这种情况最好?我目前在设计模式中使用了一个可疑的网络位置...(不要认为ApplicationData文件夹会削减它(但是因为通过ClickOnce ans安装的.Net版本可以使用Clickonce数据)文件夹))
在以前的项目中的各个地方使用带有此代码的Copy方法(处理具有相同命名属性但不从公共基类派生或实现公共接口的对象).
新的工作场所,新的代码库 - 现在它在SetValue失败,"对象与目标类型不匹配",即使是非常简单的例子......它在上周工作了....
public static void Copy(object fromObj, object toObj)
{
Type fromObjectType = fromObj.GetType();
Type toObjectType = toObj.GetType();
foreach (System.Reflection.PropertyInfo fromProperty in
fromObjectType.GetProperties())
{
if (fromProperty.CanRead)
{
string propertyName = fromProperty.Name;
Type propertyType = fromProperty.PropertyType;
System.Reflection.PropertyInfo toProperty =
toObjectType.GetProperty(propertyName);
Type toPropertyType = toProperty.PropertyType;
if (toProperty != null && toProperty.CanWrite)
{
object fromValue = fromProperty.GetValue(fromObj,null);
toProperty.SetValue(toProperty,fromValue,null);
}
}
}
}
private class test
{
private int val;
private string desc;
public int Val { get { return val; } …Run Code Online (Sandbox Code Playgroud) 我想我和这里有同样的问题,但是那里的答案还不够.
我正在使用Like按钮(在静态XFBML页面上的iframe中)允许用户喜欢YouTube视频,目的是自用户点击"赞"时将其分享到他们的墙上.
会发生什么,他们点击Like,它说"你喜欢这个",但没有发布,然后在一个随机的短暂间隔后,Like按钮被Confirm超链接取代.
我真正想要的是没有"确认"阶段,因为a)它很笨拙而b)用户可能已经离开了页面.我知道至少有一个应用程序可以做到这一点......这种行为是否可以让我编码,如果是的话,怎么做?
我正在使用由其他人为我设置的机器.我已经在本地拥有各种项目/解决方案的代码.当我从Source Control Explorer尝试"获取最新版本"时,它告诉我"服务器文件夹未映射".很公平,我使用对话框尝试映射它 - 并获得"已在工作区中映射的路径"
这让我疯狂 - 我希望这很简单!
如果重要的话,我没有服务器访问权限.
我知道我之前已经完成了这个,但我认为我的构造函数的执行顺序是我认为....
public class Class1
{
Class2 _class2;
public Class1()
{
_class2 = new Class2(this);
}
}
public class Class2
{
Class1 _parent; //corrected typo
public Class2(Class1 parent)
{
_parent = parent;
}
}
Run Code Online (Sandbox Code Playgroud)
麻烦的是,父总是以null结尾.
这样做的正确方法是什么?(也许我可以归咎于我患感冒的缓慢......)
编辑纠正TYPO(这不是真正的代码中的问题!)
我有一本关于F#的书,但此刻我很不知情,所以我想我会问.从很少有人知道F#,我很难看到它在C#bar上获得了什么可能的语法整洁.在概念上似乎没什么新东西,或者说在piian C中不可行#
当(20年前差不多!)时我做了Forth回来了,并且我已经将传递函数委托作为参数合并到方法中(似乎永远都在做那种事情).
从文体上来说,我并不热衷于匿名方法 - 这会成为一个问题吗?
虽然我认为句法整洁不会被嗤之以鼻:-)
我知道我可以有一个属性,但这比我想去的工作更多......而且不够通用.
我想做点什么
class Whotsit
{
private string testProp = "thingy";
public string TestProp
{
get { return testProp; }
set { testProp = value; }
}
}
...
Whotsit whotsit = new Whotsit();
string value = GetName(whotsit.TestProp); //precise syntax up for grabs..
Run Code Online (Sandbox Code Playgroud)
在哪里我期望价值等于"TestProp"
但我不能为我的生活找到正确的反射方法来编写GetName方法...
编辑:我为什么要这样做?我有一个类来存储从'name','value'表中读取的设置.这由基于反射的通用方法填充.我很想反写...
/// <summary>
/// Populates an object from a datatable where the rows have columns called NameField and ValueField.
/// If the property with the 'name' exists, and is not read-only, it is populated from the …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用put-bucket-policy通过aws s3api(Windows)将策略添加到s3存储桶.
我正在使用此处给出的政策代码http://docs.aws.amazon.com/AmazonS3/latest/dev/AccessPolicyLanguage_UseCases_s3_a.html 在"授予匿名用户权限"下,我的桶名被替换.
我正进入(状态
A client error (MalformedPolicy) occured: policies must be valid JSON and the first byte must be '{'
Run Code Online (Sandbox Code Playgroud)
有线索吗?
编辑:内联JSON工作 - 因此它是某种文件格式问题 - 只是我看不到的.很高兴能够使用文件.
编辑:为了帮助那些可能在这里结束的人,应该用小写命名桶.如果没有,一些s3/s3api操作可以正常工作,但其他操作则不然.看到这里
我正在尝试使用aws change-resource-record-sets来添加别名.我们的想法是允许通过我们域上的URL访问Cloudfront分发(例如mydomainname.mycompany.co.uk而不是mydomainname.cloudfront.net,其中mydomainname =类似于d4dzc6m38sq0mk)
在解决了我解决的各种其他JSON错误后,我仍然遇到问题.
A client error (InvalidChangeBatch) occurred: RRSet with DNS name
mydomainname.cloudfront.net. is not permitted in zone mycompany.co.uk.
Run Code Online (Sandbox Code Playgroud)
我有什么问题?
JSON:
{
"Comment": "Recordset for mydomainname",
"Changes": [
{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "mydomainname",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"DNSName": "mydomainname.cloudfront.net.",
"EvaluateTargetHealth": false
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
编辑以澄清HostedZoneID.
c# ×5
reflection ×2
.net ×1
amazon-s3 ×1
constructor ×1
dll ×1
f# ×1
facebook ×1
file ×1
gac ×1
properties ×1
setvalue ×1
tfs ×1