我看过很多关于.NET 3.5 SP1变化的帖子,但发现了一个我昨天还没有看到文档的帖子.我的代码在我的机器上工作得很好,从VS,msbuild命令行,一切,但它在构建服务器上运行失败(运行.NET 3.5 RTM).
[XmlRoot("foo")]
public class Foo
{
static void Main()
{
XmlSerializer serializer = new XmlSerializer(typeof(Foo));
string xml = @"<foo name='ack' />";
using (StringReader sr = new StringReader(xml))
{
Foo foo = serializer.Deserialize(sr) as Foo;
}
}
[XmlAttribute("name")]
public string Name { get; set; }
public Foo Bar { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
在SP1中,上面的代码运行得很好.在RTM中,您会收到InvalidOperationException:
无法生成临时类(result = 1).错误CS0200:属性或索引器'ConsoleApplication2.Foo.Bar'无法分配 - 它是只读的
当然,使其在RTM下运行所需的只是将[XmlIgnore]添加到Bar属性.
我的google fu显然无法找到这些变化的文档.是否有任何列出此更改的更改列表(以及类似的引擎盖下的更改,可能会跳起来并大喊"问题")?这是一个错误还是一个功能?
编辑:在SP1中,如果我添加了一个<Bar />元素,或者为Bar属性设置了[XmlElement],它将不会被反序列化.它在尝试反序列化时不会在SP1之前失败 - 它在构造XmlSerializer时抛出异常.
这让我更倾向于它是一个bug,特别是如果我为Foo.Bar设置[XmlElement]属性.如果它无法做我要求它做的事情,它应该抛出异常而不是默默地忽略Foo.Bar.XML序列化属性的其他无效组合/设置会导致异常.
编辑:谢谢TonyB,我不知道设置临时文件的位置.对于那些在将来遇到类似问题的人,您需要一个额外的配置标志:
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" …Run Code Online (Sandbox Code Playgroud) 我正在尝试向我的BitMap添加一个事件监听器.Tile扩展了gameProps,扩展了BitMap.我尝试使用addEventListener.那不起作用.但是Adobe文档说Bitmap有一个addEventListener对象.
package {
import flash.display.BitmapData;
import flash.events.*;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.geom.Point;
public class Tile extends gameProps {
public var tileNum:Number = 0;
public function Tile(tileNumber:Number):void
{
tileNum = tileNumber;
addEventListener(MouseEvent.MOUSE_OVER, respond);
}
public function respond(e:MouseEvent):void
{ trace("HELLO");
}
}
}
Run Code Online (Sandbox Code Playgroud) 在我的服务中,所有暴露方法都有:
try
{
// the method core is written here
}
catch(Exception ex)
{
Log.Append(ex);
}
Run Code Online (Sandbox Code Playgroud)
一遍又一遍地重复它是无聊和丑陋的.有什么办法可以避免吗?有没有更好的方法来保持服务正常工作,即使发生异常并继续向Log类发送异常详细信息?
首先,这似乎是一个很长的问题.我认为不是......代码只是我目前正在做的事情的概述.这感觉不对,所以我正在寻找建设性的批评和警告,以及我能做些什么的陷阱和建议.
我有一个包含业务对象的数据库.
我需要访问父对象的属性.
我需要通过业务对象维护某种状态.
如果你看一下这些类,我认为访问修饰符是不对的.我不认为它的结构很好.大多数关系都是用公共属性建模的.SubAccount.Account.User.ID < - 所有这些都是公开的..
是否有更好的方法来建立类之间的关系而不是这样,所以它不是那么"公开"?
这个问题的另一部分是关于资源:
如果我要创建一个返回List的User.GetUserList()函数,并且我有9000个用户,当我调用GetUsers方法时,它将生成9000个User对象,并且内部将生成9000个新的AccountCollection对象.我该怎么做才能使这个项目不那么资源匮乏?
请找到下面的代码并将其撕成碎片.
public class User {
public string ID {get;set;}
public string FirstName {get; set;}
public string LastName {get; set;}
public string PhoneNo {get; set;}
public AccountCollection accounts {get; set;}
public User {
accounts = new AccountCollection(this);
}
public static List<Users> GetUsers() {
return Data.GetUsers();
}
}
public AccountCollection : IEnumerable<Account> {
private User user;
public AccountCollection(User user) {
this.user = user;
}
public IEnumerable<Account> GetEnumerator() {
return Data.GetAccounts(user);
} …Run Code Online (Sandbox Code Playgroud) 我正在使用PhoneGap并拥有FBConnect.使用childBrowser和blog'http://www.pushittolive.com/post/1239874936/facebook-login-on-iphone-phonegap',我已登录到应用程序.但无法从应用程序注销.它每次登录时都会自动登录.
任何人都可以告诉我如何使用Childbrowsern PhoneGap从FBConnect注销?
我正在尝试学习如何使用WPF绑定和MVVM架构.我在Dependency Properties遇到了一些麻烦.我试图通过将它绑定到DataContext中的DependencyProperty来控制视图上项目的可见性,但它不起作用.无论我GridVisible在下面的视图模型的构造函数中设置值,它在运行代码时始终显示为可见.
谁能看到我哪里出错了?
C#代码(ViewModel):
public class MyViewModel : DependencyObject
{
public MyViewModel ()
{
GridVisible = false;
}
public static readonly DependencyProperty GridVisibleProperty =
DependencyProperty.Register(
"GridVisible",
typeof(bool),
typeof(MyViewModel),
new PropertyMetadata(false,
new PropertyChangedCallback(GridVisibleChangedCallback)));
public bool GridVisible
{
get { return (bool)GetValue(GridVisibleProperty); }
set { SetValue(GridVisibleProperty, value); }
}
protected static void GridVisibleChangedCallback(
DependencyObject source,
DependencyPropertyChangedEventArgs e)
{
// Do other stuff in response to the data change.
}
}
Run Code Online (Sandbox Code Playgroud)
XAML代码(查看):
<UserControl ... >
<UserControl.Resources>
<BooleanToVisibilityConverter x:Key="BoolToVisConverter" /> …Run Code Online (Sandbox Code Playgroud) 我有datagridview,DataSource设置为myBindingList.列表项目实现INotifyPropertyChanged,因此datagridview自动响应列表中的更改.
现在我必须计算一些datagridview列的摘要.
它应该在以下时间完成:
第一个很清楚,但第二个问题我遇到了一个小问题.
当用户通过控制或更改时更改单元格的值时,将触发OnCellValueChanged:
myDataGridView.Rows[x].Cells[y].Value=newValue;
Run Code Online (Sandbox Code Playgroud)
但是关于:
myBindingList[myInvoice].Property1=newValue;
Run Code Online (Sandbox Code Playgroud)
DataGridView会自动刷新(INotifyPropertyChanged),但它不会触发OnCellValueChanged事件.
知道如何从我的DataGridView获取此类信息?它必须在DataGridView级别上完成,因为我正在编写自己的控件,扩展了dgv.
谢谢您的帮助.
我需要一种可以在运行时定义列类型的方法.
这是我的代码:
foreach (DataGridViewColumn column in this.dataGrid.Columns)
{
???
//i.e. column.type = checkbox
}
Run Code Online (Sandbox Code Playgroud)
如何在此foreach循环中定义列类型?
所以我在C#(使用.NET表单)中有一个文本框,我将接受一些输入的用户字符串.
此字符串在开头已经有文本(参数),无论如何都将存在于字符串的开头.一定是在那里.我希望他们知道这一点,但不能删除文本框中的单词(所以他们不会认为他们已经删除了它,无论如何它会在那里)
因此,不能删除或编辑这些第一个参数.
这些参数之后的任何文本都可以像往常一样自由添加或修改.
这可能在C#中吗?
我有一个带有Datagridview的窗体,其中包含来自xml文件的数据.DGV的设置如下:日期,产品,价格
有10行数据.
我试图计算价格从一行到下一行的变化,并且很难找到解决方案.例如:
1/1/12, ABC, $2.00
1/1/12, ABC, $2.50
Net Change: .50
Run Code Online (Sandbox Code Playgroud)
在列中,我可以使用Table.Columns.Expression,但我不清楚如何将此计算减去先前与当前.
我想过迭代列,添加到一个新表并以这种方式计算,但似乎是一个低于标准的解决方案.一旦我得到更改ID,就像将其添加到Datagridview.
没有经过测试,但是这样的话:
if (dataGridView1.Rows.Count > 0)
{
specifier = "###,###.00";
double tier1Minus = 0;
double tier2Minus = 0;
for (int i = 0; i < dataGridView1.Rows.Count; ++i)
{
tier1Minus += Convert.ToDouble(dataGridView1.Rows[i].Cells["Price"].Value);
tier2Minus += Convert.ToDouble(dataGridView1.Rows[i+1].Cells["Price"].Value);
}
// then add to dataGridView1
}
Run Code Online (Sandbox Code Playgroud) c# ×7
datagridview ×3
.net ×2
winforms ×2
.net-3.5 ×1
actionscript ×1
column-types ×1
cordova ×1
data-access ×1
datacontext ×1
flash ×1
iphone ×1
logging ×1
protected ×1
refactoring ×1
textbox ×1
wpf ×1
xaml ×1
xml ×1