我有一些像这样的基类:
public class AbstractData
{
public int ID { get; set; }
}
public class Person: AbstractData
{
public string Name { get; set; }
}
public class AbstractManager<T> where T: AbstractData
{
public virtual List<T> GetAll()
{
}
public virtual T GetOne(int id)
{
}
}
public class PersonManager: AbstractManager<Person>
{
public override List<Person> GetAll()
{
//...
}
public override Person GetOne(int id)
{
//...
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我有一个Windows窗体基类,如下所示:
public class BaseForm: Form
{
public virtual AbstractManager<T> GetManager<T>() where T: …Run Code Online (Sandbox Code Playgroud) 我有一个类InputConfig,其中包含List<IncludeExcludeRule>:
public class InputConfig
{
// The rest of the class omitted
private List<IncludeExcludeRule> includeExcludeRules;
public List<IncludeExcludeRule> IncludeExcludeRules
{
get { return includeExcludeRules; }
set { includeExcludeRules = value; }
}
}
public class IncludeExcludeRule
{
// Other members omitted
private int idx;
private string function;
public int Idx
{
get { return idx; }
set { idx = value; }
}
public string Function
{
get { return function; }
set { function = value; …Run Code Online (Sandbox Code Playgroud) 我有一个带有object参数的重写方法.我确定这是否是一个数组,然后想确定它的长度:
public override bool IsValid(object value)
{
Type type = value.GetType();
if (type.IsArray)
{
return ((object[]) value).Length > 0;
}
else
{
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是如果value是int[],当我尝试强制转换时它会出错object[].有没有办法处理这个演员,所以它适用于任何类型的数组?
假设我们有一个Person班级:
public class Person
{
public string FamilyName {get;set;}
public string GivenName {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
并且有一个控件以某种方式显示人员列表的信息.这是aspx的伪代码:
<uc1:EmployeesViewer runat="server">
<Employees>
<Person>
<GivenName>John</GivenName>
<FamilyName>Kerry</GivenName>
</Person>
<Person>
<GivenName>Jack</GivenName>
<FamilyName>Lew</GivenName>
</Person>
<Employees>
</uc1:EmployeesViewer>
Run Code Online (Sandbox Code Playgroud)
EmployeesViewer.Employees是List<Person>属性的类型[PersistenceMode(PersistenceMode.InnerProperty)].
但是Visual Studio不会编译它.是否可以Person使用标记声明对象?
我有一个<asp:FileUpload>控件,其属性AllowMultiple设置为true:
<asp:fileupload id="FileUpload" runat="server" allowmultiple="true" cssclass="fileUpload btn btn-sm btn-default" onchange="preloadImages()" />
<div class="field col-md-2 col-md-offset-1 immScarpePreview MainPreviewBox">
<asp:image id="Image1" runat="server" visible="false" cssclass="img-responsive" />
<asp:button id="ImmButton" runat="server" text="Upload" onclick="ImmButton_Click" cssclass="hidden" />
</div>
Run Code Online (Sandbox Code Playgroud)
在我的JavaScript函数中,我模拟了对隐形按钮的单击:
<script>
function preloadImages() {
$('#<%=ImmButton.ClientID%>').trigger('click');
}
</script>
Run Code Online (Sandbox Code Playgroud)
在代码隐藏中,我将文件保存到临时文件夹,然后在<asp:Image>控件中显示上传的图像:
protected void ImmButton_Click(object sender, EventArgs e)
{
if (FileUpload.HasFile)
{
try
{
int cont = 0;
byte[] fileData = null;
foreach (HttpPostedFile file in FileUpload.PostedFiles)
{
if (cont == 0)
{
using (var binaryReader = new …Run Code Online (Sandbox Code Playgroud) 我的If病情有什么问题?
If Not IsEmpty(Wrkgps_L3) And Not IsEmpty(Wrkgps_L4) Then
Wrkgps_L3L4 = Wrkgps_L3 & "," & Wrkgps_L4
End If
Run Code Online (Sandbox Code Playgroud)
这种Not情况似乎不起作用.在中的代码If语句被执行,即使两者Wrkgps_L3并Wrkgps_L4为空字符串.
Wrkgps_L3并且Wrkgps_L4是包含从函数返回的结果的变量.我注意到了,IsEmpty(Wrkgps_L3) = False尽管如此Wrkgps_L3 = "".我不得不重写我的代码
If (Wrkgps_L3 <> "") And (Wrkgps_L4 <> "") Then
Run Code Online (Sandbox Code Playgroud)
在任何情况下,我仍然很想知道为什么IsEmpty不对变量起作用""?
我尝试将@Reflect.metadata装饰器应用于TypeScript类,遵循reflect-metadata.d.ts第82-84行的示例:
/// <reference path="node_modules/reflect-metadata/reflect-metadata.d.ts"/>
@Reflect.metadata('key', 0)
class C {
}
Run Code Online (Sandbox Code Playgroud)
但是,TypeScript 1.7.2编译器@Reflect.metadata在行上生成以下错误:
错误TS1238:当作为表达式调用时,无法解析类装饰器的签名.
无法调用类型缺少调用签名的表达式.
怎么了?
我正在使用SqlDataReader从SQL Server 2012数据库中获取数据:
SqlConnection connection = (SqlConnection)_db.Database.GetDbConnection();
await connection.OpenAsync();
SqlCommand command = new SqlCommand("dbo.[sp_MyStoredPrc] @InputId=1", connection);
var reader = await command.ExecuteReaderAsync();
if (reader.HasRows)
{
while (reader.Read())
{
int? var1 = (int?)reader["Column1Name"];
}
}
Run Code Online (Sandbox Code Playgroud)
int从数据库读取NULL 字段时,该字段
reader["Column1Name"]为空,因此代码在运行时引发InvalidCastException。
我试过了
reader.GetInt32(reader.GetOrdinal("Column1Name"))
Run Code Online (Sandbox Code Playgroud)
但这会引发System.Data.SqlTypes.SqlNullValueException。
我也尝试过
reader.GetSqlInt32(reader.GetOrdinal("Column1Name"))
Run Code Online (Sandbox Code Playgroud)
返回null,但类型SqlInt32不是int?我想要的。
我最终做了
if (!reader.IsDBNull(reader.GetOrdinal("Column1Name")))
int? var1 = (int?)reader["Column1Name"];
Run Code Online (Sandbox Code Playgroud)
哪个有效。
问题:
有没有比调用该IsDBNull方法更简单的方法?
为什么为什么reader["Column1Name"]返回nulldb 而不是db值为NULL且字段为a int?
有了这个代码:
using (var stream = new MemoryStream())
{
thumbnail.Save(stream); // you get the idea
stream.Position = 0; // <- is this needed?
WriteStreamToDisk(stream);
}
Run Code Online (Sandbox Code Playgroud)
如果我有一个写入内存流的方法,然后我想将该流写入磁盘,我是否需要将位置设置为 0?
或者,流是否有不同的读/写指针?
常规
使用 Unity 引擎开发游戏模组。
我尝试使用以下代码附加到activeSceneChanged事件的问题:
SceneManager.activeSceneChanged += OnSceneChanged;
Run Code Online (Sandbox Code Playgroud)
这会导致错误:
CS0229 “SceneManager.activeSceneChanged”和“SceneManager.activeSceneChanged”之间存在歧义
检查这里发生的情况后,该成员似乎activeSceneChanged既是用户生成的又是 [CompilerGenerate]:
老实说,我自己尝试过,
我根本不知道如何解决这样的问题。我以前从未遇到过。问了我认识的其他一些开发人员,但他们也从未见过。使用 ILSpy 反编译 Unity DLL 文件,结果发现 CompilerGenerate 代码不在那里(有点有意义,因为它是由我假设的编译器生成的)。
我真的很想得到一些关于如何处理和解决这个问题的帮助。
编辑
为了帮助加快速度,这里有一个指向该模组的 Github 链接: https: //github.com/skarab42/ValheimTwitch
在 Plugin.cs 的第 93 行弹出错误
c# ×8
.net ×4
asp.net ×2
webforms ×2
ado.net ×1
ambiguity ×1
arrays ×1
events ×1
file-upload ×1
generics ×1
if-statement ×1
methods ×1
sql-server ×1
stream ×1
string ×1
typescript ×1
vba ×1
virtual ×1
whitespace ×1
xml ×1