我有类似下面的代码...有人在这里提到WebClient,Stream和StreamReader对象都可以从使用块中受益.两个简单的问题:
1:这个小片段看起来如何使用块?我做自己的研究没有问题,所以资源链接很好但是看到一个例子会更快更容易,我会从中理解它.
2:我想养成良好的编码标准的习惯,如果我对使用积木更好的原因有所了解会有所帮助...是否只是让你不必担心关闭或在那里更多原因?谢谢!
WebClient client = new WebClient();
Stream stream = client.OpenRead(originGetterURL);
StreamReader reader = new StreamReader(stream);
JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadLine());
string encryptionKey = (string)jObject["key"];
string originURL = (string)jObject["origin_url"];
stream.Close()
reader.Close()
Run Code Online (Sandbox Code Playgroud) 在我的项目中,我不仅需要时间,还需要有关 UTC 偏移量的信息。因此我考虑使用DateTimeOffset类。
我没有做任何魔法,只是声明了struct包含shortfor offset 和longfor ticks (与 中相同DateTimeOffset) - 当然还定义了ProtoContract和ProtoMember属性。
但是:即使这个值没有初始化(两个字段都为零),线路上还有 2 个额外的字节(我用 a 进行了交叉检查class)!
我尝试继承DefaultValueAttribute并设置我的默认值 - 但也无济于事。
原因是 protobuf-net 检查按DefaultValueAttribute名称(在MetaType.ApplyDefaultBehaviour(bool isEnum, ProtoMemberAttribute normalizedAttribute))。
if ((attrib = GetAttribute(attribs, "System.ComponentModel.DefaultValueAttribute")) != null)
{
object tmp;
if(attrib.TryGet("Value", out tmp)) defaultValue = tmp;
}
Run Code Online (Sandbox Code Playgroud)
但即使我改变了这一点,我也会抱怨例外DefaultValueDecorator.Read(Compiler.CompilerContext ctx, Compiler.CodeLabel label):
default:
throw new NotSupportedException("Type cannot be represented as …Run Code Online (Sandbox Code Playgroud) 我已经通过 phpmyadmin 添加了这个存储过程:
CREATE DEFINER=`root`@`localhost` PROCEDURE `SelectUser`()
LANGUAGE SQL
NOT DETERMINISTIC
NO SQL
SQL SECURITY DEFINER
COMMENT ''
Select * from User
Run Code Online (Sandbox Code Playgroud)
在我的 edmx 中,但是当创建一个复杂类型并执行 Get 列信息时
存储过程不返回任何列
我试图首先以实体框架代码创建数据库,但是我总是收到这样的错误:
InvalidOperationException:无法将表'Device'用于实体类型'IpMac',因为它已用于实体类型'Device',并且主键{'DeviceIP'}与主键{'DeviceID'}之间没有关系。”
这些是我的模型类:
public class IpMac
{
[Key]
public string DeviceIP { get; set; }
//[ForeignKey("Device")]
public int DeviceID { get; set; }
public string DeviceMAC { get; set; }
//public Device Device { get; set; }
public ICollection<Device> Device { get; set; }
}
public class Device
{
//[Key]
public int DeviceID { get; set; }
public string DeviceName { get; set; }
public string UserName { get; set; }
//public string DeviceMAC { get; set; }
public IpMac …Run Code Online (Sandbox Code Playgroud) 我使用 ef-core 将 Swashbuckle 添加到了 .net core web-api 项目。我的问题是我的 ef 自动生成的类的虚拟属性被添加到 swagger 示例响应中,这使得响应变得巨大,我只想显示表属性,而不是关系。
控制器的代码示例:
[HttpGet("devices", Name = "GetDevices")]
public async Task<ActionResult<List<Device>>> Devices()
{
var devices = await _deviceDa.GetDevices();
return Json(devices);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是 ef 自动生成的类位于一个单独的类库中,我无权更改。我不能简单地将 JsonIgnore 添加到这些虚拟属性中。
是否有可能让 Swashbuckle 忽略所有虚拟属性?
我需要Include()在 EF Core 选择期间执行多级查询。我将 AutoMapper 与ProjectTo<>().
我已在映射中指定ExplicitExpansion(),这意味着导航属性不会自动填充,因为我希望有可能多次执行相同的查询和一次Include()导航属性,但第二次忽略它。
ProjectTo<>()方法具有参数,允许我将导航属性包含到我的选择中,但我需要执行多级包含。这可能吗?这种语法Include(e => e.Collection.Select(sc => sc.MyProperty))在这种情况下不起作用。
我尝试使用Include().ThenInclude()forDbContext然后执行ProjectTo,但在这种情况下ProjectTo会覆盖我的包含内容并且它们会被忽略。
现在我不确定是否有可能在映射中ProjectTo指定ExplicitExpansion()并具有多级包含?
请参阅MSDN中的代码示例:(http://msdn.microsoft.com/en-us/library/b1yfkh5e ( v=VS.100 ) .aspx)
// Design pattern for a base class.
public class Base: IDisposable
{
private bool disposed = false;
//Implement IDisposable.
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
// Free other state (managed objects).
}
// Free your own state (unmanaged objects).
// Set large fields to null.
disposed = true;
}
}
// Use C# destructor syntax for finalization code.
~Base()
{ …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚XMLHttpRequest对象中上传属性的确切含义.在我看来,无论有没有它,一个xhr事件监听器的进展将监视一个xhr.send(file).
我查看了W3C并发现:"upload属性必须返回关联的XMLHttpRequestUpload对象."
但我不明白这与使用有什么关系,xhr.upload.addEventListener("progress", progressFunction, false);因为它xhr.addEventListener("progress", progressFunction, false);会做同样的事情.
我问,因为我希望为上传的进度创建自定义图形....我不打算使用HTML5进度元素或jquery.严格的Javascript为客户端.
我将 dll 安装到了 GAC 中,甚至更新了 dll 以将其安装到了 GAC 中,但出现以下错误:
“无法加载文件或程序集“Newtonsoft.Json,版本=4.5.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。系统找不到指定的文件。”:“Newtonsoft.Json,版本=4.5 .0.0,文化=中立,PublicKeyToken=30ad4fe6b2a6aeed”}
应用程序配置
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
广汽集团地点:
C:\ Windows \ Microsoft.NET \ assembly \ GAC_MSIL \ Newtonsoft.Json \ v4.0_12.0.0.0__30ad4fe6b2a6aeed \ Newtonsoft.Json.dll
我还将 dll 复制到了 C:\Windows\System32,但是当我尝试从该位置将其添加为引用时,视觉工作室看不到它。
我正在尝试在 Xamarin 表单中创建底部选项卡式页面,并且我正在为 Android 执行此操作。
我在这里使用最新版本的 Xamarin Forms。
我的示例底部选项卡页面如下所示。
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="clr-namespace:SampleTabbedPage.Views"
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
android:TabbedPage.ToolbarPlacement="Bottom"
android:TabbedPage.BarItemColor="Gray"
android:TabbedPage.BarSelectedItemColor="Blue"
mc:Ignorable="d"
x:Class="SampleTabbedPage.Views.SampleTabbed">
<!--Pages can be added as references or inline-->
<NavigationPage
Title="Main"
NavigationPage.HasNavigationBar="False">
<x:Arguments>
<views:SampleDetailsPage/>
</x:Arguments>
</NavigationPage>
<ContentPage Title="Tab 1" />
<ContentPage Title="Tab 2" />
</TabbedPage>
Run Code Online (Sandbox Code Playgroud)
我的示例详细信息页面如下
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="SampleTabbedPage.Views.SampleDetailsPage"
BackgroundColor="Gray">
<ContentPage.Content>
<StackLayout>
<ListView BackgroundColor="White" ItemTapped="ListView_ItemTapped">
<ListView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Mango</x:String>
<x:String>Banana</x:String>
<x:String>Pinaple</x:String>
<x:String>Apple</x:String>
<x:String>Avacado</x:String>
<x:String>Coconut</x:String>
<x:String>Dragan Fruit</x:String>
<x:String>Pomaganate</x:String>
<x:String>Wood Apple</x:String>
</x:Array>
</ListView.ItemsSource>
</ListView>
</StackLayout>
</ContentPage.Content>
</ContentPage> …Run Code Online (Sandbox Code Playgroud) c# ×9
asp.net-mvc ×2
.net ×1
.net-core ×1
automapper ×1
dispose ×1
finalizer ×1
gac ×1
javascript ×1
mysql ×1
progress ×1
protobuf-net ×1
ssis ×1
ssis-2012 ×1
stream ×1
streamreader ×1
swagger ×1
swashbuckle ×1
upload ×1
using ×1