如何检查C#中文件夹的读写权限

在我的网站中,我想创建一个新文件夹,然后复制其中的一些文件,我也想通过C#代码创建一个html文件。 我想知道 如何检查文件夹的读写权限 如何在项目根目录中的运行时创建html文件 我使用Asp.net MVC 2和C# 。

你如何在Ruby中做多态?

在C#中,我可以这样做: class Program { static void Main(string[] args) { List animals = new List(); animals.Add(new Dog()); animals.Add(new Cat()); foreach (Animal a in animals) { Console.WriteLine(a.MakeNoise()); a.Sleep(); } } } public class Animal { public virtual string MakeNoise() { return String.Empty; } public void Sleep() { Console.Writeline(this.GetType().ToString() + ” is sleeping.”); } } public class Dog […]

将euler转换为矩阵,将矩阵转换为euler

我正在尝试使用.NET / C#将使用欧拉角度描述的3D旋转转换为矩阵然后返回。 我的约定是: 左撇子系统(x右,y上,z前进) 旋转顺序:绕y前进,绕x旋转,绕z倾斜 使用左手规则(拇指指向+无穷大)旋转是正的 我的试用期是: Euler到矩阵 (为了简化,我删除了x,y,z平移部分) Matrix3D matrix = new Matrix3D() { M11 = cosH * cosB – sinH * sinP * sinB, M12 = – sinB * cosP, M13 = sinH * cosB + cosH * sinP * sinB, M21 = cosH * sinB + sinH * sinP * cosB, […]

如何配置Swashbuckle忽略模型上的属性

我正在使用Swashbuckle为webapi2项目生成swagger文档\ UI。 我们的模型与一些传统接口共享,因此我想在模型上忽略一些属性。 我不能使用JsonIgnore属性,因为旧版接口也需要序列化为JSON,因此我不想全局忽略这些属性,只是在Swashbuckle配置中。 我在这里找到了一种记录方法: https://github.com/domaindrivendev/Swashbuckle/issues/73 但这与目前的Swashbuckle版本似乎已经过时了。 推荐用于旧版Swashbuckle的方法是使用IModelFilter实现,如下所示: public class OmitIgnoredProperties : IModelFilter { public void Apply(DataType model, DataTypeRegistry dataTypeRegistry, Type type) { var ignoredProperties = … // use reflection to find any properties on // type decorated with the ignore attributes foreach (var prop in ignoredProperties) model.Properties.Remove(prop.Name); } } SwaggerSpecConfig.Customize(c => c.ModelFilter()); 但我不确定如何配置Swashbuckle在当前版本中使用IModelFilter? 我正在使用Swashbuckle […]

与CancellationTokenSource的Task.Factory.FromAsync

我有以下代码行用于从NetworkStream异步读取: int bytesRead = await Task.Factory.FromAsync(this.stream.BeginRead, this.stream.EndRead, buffer, 0, buffer.Length, null); 我想支持取消。 我看到我可以使用CancellationTokenSource取消任务 ,但是我没有看到任何方法可以将它传递给TaskFactory.FromAsync() 。 是否可以使FromAsync()构造的任务支持取消? 编辑:我想取消已经运行的任务。

如何将外部项目中的控制器和视图包含到MVC6中?

我有一些模块,有控制器和视图。 它基本上是我的Web应用程序的扩展。 每个模块都在一个类库中。 我想从我的Web应用程序加载这些程序集。 但我在这里没有运气。 我的解决方案文件结构如下: src | |– Web.Common (Class Library Project) | |- Files like: filters, my own controller etc… | |– WebApplication (ASP.NET5 WebSite) | |- wwwroot | |- Controllers | |- Views | |- etc… | |– Module 1 (Class Library Project) | |- Controllers | |- Views | |– Module […]

为所有控制器全局validationModelState.IsValid

在我的ASP.NET核心控制器中,我总是检查ModelState是否有效: [HttpPost(“[action]”)] public async Task DoStuff([FromBody]DoStuffRequest request) { if (!ModelState.IsValid) { return BadRequest(“invalid parameters”); } else { return Ok(“some data”)); } } 有没有办法使用filter全局检查ModelState的有效性,所以我不必再次在每个控制器的每个API项目中执行此操作? 如果动作可以依赖于模型状态有效而不需要检查,那将是很好的: [HttpPost(“[action]”)] public async Task DoStuff([FromBody]DoStuffRequest request) { return Ok(“some data”)); }

如何解决错误:不一致的可访问性:通用c#接口的参数类型?

在将此代码写入我的项目时,我收到了错误 错误1可访问性不一致:字段类型’System.Collections.Generic.List’比字段’Jain_milan.addchild.m_children’更难访问 错误2可访问性不一致:参数类型’System.Collections.Generic.List’比方法’Jain_milan.addchild.addchild(System.Collections.Generic.List)’更难访问 namespace Jain_milan { public partial class addchild : Form { List label = new List(); List textbox = new List(); List combobox = new List(); List datetimepicker = new List(); public List m_children = new List(); public addchild(List children) { InitializeComponent(); this.m_children = children; //Initialize the same List as sent by Mainform […]

整个窗口上的MouseHover / MouseLeave事件

我有Form子类,带有MouseHover和MouseLeave处理程序。 当指针位于窗口的背景上时,事件工作正常,但当指针移动到窗口内的控件上时,它会导致MouseLeave事件。 无论如何有一个覆盖整个窗口的事件。 (.NET 2.0,Visual Studio 2005,Windows XP。)

LINQ to XML – 使用前缀访问后代

我有一个像这样的示例xml文件 Name address Zip 所有节点都有一个前缀值作为vs,谁能告诉我如何解析这个文件来读取名称和地址信息? 我是LINQ的新手。 任何有关这方面的帮助将不胜感激。 谢谢!