使用LINQ-to-SQL或Entity Framework时,我可以轻松地为每个表生成一个类来处理CRUD基础知识:
Info info = new Info();
info.Title = "testing";
db.Infos.InsertOnSubmit(info);
db.SubmitChanges();
Run Code Online (Sandbox Code Playgroud)
当我对数据库表进行结构更改时,我可以轻松地重新生成表的模型类(只需在设计器中删除它并再次将表拖到设计器中).但是,这当然会覆盖课堂上的所有内容.
因此,为了在每次重新生成模型时不会删除的每个类中添加额外的功能,我发现自己每个表都有一个额外的模型类,因此有两个数据层生效.
这是常见的做法还是有一种方法可以为生成的类添加功能,这些类在重新生成类时不会被覆盖?
我有以下课程:
public abstract class Item
{
//...
}
public class Customer : Item
{
//...
}
public class Address : Item
{
//...
}
Run Code Online (Sandbox Code Playgroud)
我希望能够使用这样的自定义反射类创建精确的克隆:
Customer customer = new Customer();
ItemReflector irCustomer = new ItemReflector(customer);
Customer customerClone = irCustomer.GetClone<Customer>();
Run Code Online (Sandbox Code Playgroud)
但我遇到了GetClone方法的语法问题:
public class ItemReflector
{
private Item item;
public ItemReflector(Item item)
{
this.item = item;
}
public Item GetClone<T>()
{
T clonedItem = new T();
//...manipulate the clonedItem with reflection...
return clonedItem;
} …Run Code Online (Sandbox Code Playgroud) 我希望能够将大量的XML 粘贴到我的C#代码中.
但是,我能做的最好的是以下,但是我必须搜索并替换 "with"".
有没有办法在C#代码中定义多行XML而不必像这样改变XML文本?
public static string GetXml1()
{
return @"
<Customer>
<FirstName status=""required"">Jim</FirstName>
<LastName status=""required"">Smith</LastName>
</Customer>
";
}
Run Code Online (Sandbox Code Playgroud) 我一直在研究Silverlight应用程序. 我刚刚注意到.xap文件现在是原来的四倍,可能是什么造成的呢?
这是其他一些信息:
之前和之后构建目录的屏幕截图:
当前,此正则表达式返回一个匹配项:
世界上最好的语言和最快的语言
如何获取返回两个匹配项的信息:
最好的语言
最快的语言
string text = "C# is the best language in the world and the fastest language in the world";
string search = @"\bthe\b.*\blanguage\b";
MatchCollection matches = Regex.Matches(text, search);
Console.WriteLine("{0} matches", matches.Count);
foreach (Match match in matches)
{
Console.WriteLine("match '{0}' was found at index {1}", match.Value, match.Index);
}
Console.WriteLine("---");
Run Code Online (Sandbox Code Playgroud) 我有一个Grid对象,想要从中获取一个特定的复选框.
我可以使用这种语法:
CheckBox cbChange = grid.Children[4] as CheckBox;
Run Code Online (Sandbox Code Playgroud)
但是如何通过x/y坐标来访问这个孩子,例如:
CheckBox cbChange = grid.GetXYChild(2,3) as CheckBox; //PSEUDO-CODE
Run Code Online (Sandbox Code Playgroud)

using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace TestGrid92292
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
List<string> rowNames = new List<string>
{
"Marketing",
"Sales",
"Development"
};
Grid grid = new Grid();
grid.Margin = new Thickness(5);
ColumnDefinition col1 = new ColumnDefinition();
col1.Width = new GridLength(100, GridUnitType.Pixel);
grid.ColumnDefinitions.Add(col1);
ColumnDefinition col2 = new ColumnDefinition();
col2.Width = new GridLength(1, GridUnitType.Star);
grid.ColumnDefinitions.Add(col2);
ColumnDefinition …Run Code Online (Sandbox Code Playgroud) 在WPF中,tb.HorizontalContentAlignment = HorizontalAlignment.Center 作品:

WPF XAML:
<Window x:Class="TestText2343434.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel x:Name="MainContent" Margin="10" HorizontalAlignment="Left"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
WPF代码背后:
using System.Windows;
using System.Windows.Controls;
namespace TestText2343434
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
TextBox tb = new TextBox();
tb.Width = 30;
tb.MaxLength = 1;
tb.HorizontalContentAlignment = HorizontalAlignment.Center;
MainContent.Children.Add(tb);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在Silverlight中,tb.HorizontalContentAlignment = HorizontalAlignment.Center 不起作用:

Silverlight XAML:
<UserControl x:Class="TestContent222.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot"> …Run Code Online (Sandbox Code Playgroud) 我有以下Excel VBA脚本,在Excel for Mac 2011中使用该脚本将 Excel 文件的所有工作表导出到 .csv 文件。
Sub save_all_csv()
On Error Resume Next
Dim ExcelFileName As String
ExcelFileName = ThisWorkbook.Name
For Each objWorksheet In ThisWorkbook.Worksheets
ExcelFileNameWithoutExtension = RemoveExtension(ExcelFileName)
CsvFileName = ExcelFileNameWithoutExtension & "__" & objWorksheet.Name & ".csv"
Application.DisplayAlerts = False
objWorksheet.SaveAs Filename:="data:storage:original_excel:" & CsvFileName, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = True
Next
Application.DisplayAlerts = False
Application.Quit
End Sub
Function RemoveExtension(strFileName As String)
strFileName = Replace(strFileName, ".xlsx", "")
strFileName = Replace(strFileName, ".xls", "")
RemoveExtension = strFileName
End Function …Run Code Online (Sandbox Code Playgroud) 在PHP/Kohana中,我有控制器动作方法,它做了一些处理.完成后,我想将它发送到另一个控制器,例如:
public function action_import_csv()
{
Kohana_Import_Driver_Csv::process_files_from_csv_to_mysql($this->import_directory);
//url::redirect(Route::get('backend_application')->uri()); //undefined method URL::redirect()
//redirect(Route::get('backend_application')->uri(), null); //undefined function
}
Run Code Online (Sandbox Code Playgroud)
根据此文档,至少第一个重定向应该有效.我正在使用Kohana 3.
如何从此控制器操作方法向新控制器/操作发送执行?
由于某种原因,url :: redirect不可用,这是我得到的代码完成url:::

@bharath,我试过url::current()并得到了这个错误:

我想只需单击一个按钮并执行一些ExtJS代码进行测试,但是这个ExtJS代码给了我错误this.el is null.我需要做些什么才能使此代码生效?
main.js:
Ext.onReady(function() {
var button = new Ext.Button('button-div', {
text: 'hello',
handler: function() {
alert('pressed');
}
});
viewport = new Ext.Viewport({
layout: 'border',
items: [ button ]
});
viewport.doLayout();
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css">
<script type="text/javascript" src="ext/adapter/ext/ext-base.js">
</script>
<script type="text/javascript" src="ext/ext-all-debug.js">
</script>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
感谢指针@Mchl,它现在可以使用这段代码:
Ext.onReady(function() {
var button = new Ext.Button({
text: "Click this",
handler: function() {
alert('pressed');
}
});
var regionContent …Run Code Online (Sandbox Code Playgroud)