C# GetManifestResourceStream 获取项目资源为null解决方案(亲测)

GetManifestResourceStream 获取项目资源为null

使用Stream s = assembly.GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + resourceName) 获取资源文件,返回流为null,如图所示:

在这里插入图片描述

解决方案

设置资源文件的 属性,将生成操作属性值设置为嵌入的资源,如图所示:

在这里插入图片描述
再次运行程序,发现返回流不再是null,如图所示:

在这里插入图片描述

Python.xshd文件

本项目是准备写个简单的python编辑器,刚开始动手,有些丑:

在这里插入图片描述
分享写的初版样式文件Python.xshd,后续还会继续更新,大家可以据此按需修改:

<?xml version="1.0"?>
<SyntaxDefinition name="Python" extensions=".py" xmlns="http://icsharpcode.net/sharpdevelop/syntaxdefinition/2008">
	<Color name="Comment" foreground="#008000" /> <!-- Green -->
	<Color name="String" foreground="#F2981D" /> <!-- Orange -->
	<Color name="Label" foreground="#000DBA" /> <!-- Blue -->
	<Color name="Note" foreground="#F2981D" /> <!-- Orange -->
	<Color name="Keywords_true" foreground="#2E9AFE" /> <!-- Blue -->
	<Color name="Keywords_print" foreground="#D7DF01" /> <!-- Yellow -->
	<Color name="Keywords_def" foreground="#045FB4" /> <!-- Blue -->
	<Color name="Keywords_int" foreground="#04B486" /> <!-- Green -->
	<Color name="Keywords_file" foreground="#00BFFF" /> <!-- Cyan -->
	<Color name="KeywordsStructure" foreground="#B404AE" /> <!-- Purple -->
	<Color name="KeywordsApi" foreground="#D7DF01" /> <!-- Yellow -->
	<Color name="KeywordsDigit" foreground="#99CC99" /> 

	<!-- This is the main ruleset. -->
	<RuleSet>
		<Span color="Comment" begin="#" />
		<Span color="Note" multiline="true" begin="&quot;&quot;&quot;" end="&quot;&quot;&quot;" />
		<Span color="Note" multiline="true" begin="'''" end="'''" />
		<!--<Delimiters>:</Delimiters>-->
		<Span color="String">
			<Begin>"</Begin>
			<End>"</End>
			<RuleSet>
				<!-- nested span for escape sequences -->
				<Span begin="\\" end="." /> 
			</RuleSet>
		</Span>

		<Span color="String">
			<Begin>'</Begin>
			<End>'</End>
			<RuleSet>
				<!-- nested span for escape sequences -->
				<Span begin="\\" end="." />
			</RuleSet>
		</Span>

		<Keywords color="Keywords_true">
			<Word>True</Word>
			<Word>False</Word>
			<Word>None</Word>
		</Keywords>
		<Keywords color="Keywords_print">
			<Word>print</Word>
			<Word>exec</Word>
		</Keywords>
		<Keywords color="Keywords_def">
			<Word>and</Word>
			<Word>class</Word>
			<Word>def</Word>
			<Word>is</Word>
			<Word>lambda</Word>
			<Word>not</Word>
			<Word>or</Word>
		</Keywords>
		<Keywords color="KeywordsStructure">
			<Word>as</Word>
			<Word>assert</Word>
			<Word>break</Word>
			<Word>continue</Word>
			<Word>del</Word>
			<Word>elif</Word>
			<Word>else</Word>
			<Word>except</Word>
			<Word>finally</Word>
			<Word>for</Word>
			<Word>from</Word>
			<Word>global</Word>
			<Word>if</Word>
			<Word>import</Word>
			<Word>in</Word>
			<Word>pass</Word>
			<Word>raise</Word>
			<Word>return</Word>
			<Word>triple</Word>
			<Word>try</Word>
			<Word>while</Word>
			<Word>with</Word>
			<Word>yield</Word>
		</Keywords>

		<Keywords color="Keywords_int">
			<Word>staticmethod</Word>
			<Word>int</Word>
			<Word>str</Word>
			<Word>super</Word>
			<Word>property</Word>
			<Word>tuple</Word>
			<Word>bool</Word>
			<Word>type</Word>
			<Word>bytearray</Word>
			<Word>float</Word>
			<Word>list</Word>
			<Word>frozenset</Word>
			<Word>classmethod</Word>
			<Word>complex</Word>
			<Word>set</Word>
			<Word>dict</Word>
			<Word>object</Word>
			<Word>slice</Word>
		</Keywords>
		<Keywords color="Keywords_file">
			<Word>basestring</Word>
			<Word>execfile</Word>
			<Word>file</Word>
			<Word>raw_input</Word>
			<Word>reduce</Word>
			<Word>unicode</Word>
			<Word>long</Word>
			<Word>xrange</Word>
			<Word>cmp</Word>
		</Keywords>
		<Keywords color="KeywordsApi">
			<Word>abs</Word>
			<Word>divmod</Word>
			<Word>input</Word>
			<Word>open</Word>
			<Word>all</Word>
			<Word>enumerate</Word>
			<Word>ord</Word>
			<Word>any</Word>
			<Word>eval</Word>
			<Word>isinstance</Word>
			<Word>pow</Word>
			<Word>sum</Word>
			<Word>issubclass</Word>
			<Word>print</Word>
			<Word>bin</Word>
			<Word>iter</Word>
			<Word>filter</Word>
			<Word>len</Word>
			<Word>range</Word>
			<Word>unichr</Word>
			<Word>callable</Word>
			<Word>format</Word>
			<Word>locals</Word>
			<Word>chr</Word>
			<Word>reload</Word>
			<Word>vars</Word>
			<Word>getattr</Word>
			<Word>map</Word>
			<Word>repr</Word>
			<Word>globals</Word>
			<Word>max</Word>
			<Word>reversed</Word>
			<Word>zip</Word>
			<Word>compile</Word>
			<Word>hasattr</Word>
			<Word>memoryview</Word>
			<Word>round</Word>
			<Word>__import__</Word>
			<Word>hash</Word>
			<Word>min</Word>
			<Word>delattr</Word>
			<Word>help</Word>
			<Word>next</Word>
			<Word>setattr</Word>
			<Word>hex</Word>
			<Word>dir</Word>
			<Word>id</Word>
			<Word>oct</Word>
			<Word>sorted</Word>
			<Word>fopen</Word>
		</Keywords>

		<!-- Digits -->
		<Rule color="KeywordsDigit">
			\b0[xX][0-9a-fA-F]+  # hex number
			|    \b
			(    \d+(\.[0-9]+)?   #number with optional floating point
			|    \.[0-9]+         #or just starting with floating point
			)
			([eE][+-]?[0-9]+)? # optional exponent
		</Rule>
	</RuleSet>
</SyntaxDefinition>

希望本文对大家有帮助,上文若有不妥之处,欢迎指正

分享决定高度,学习拉开差距

  • 17
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在 Entity Framework Core (EF Core) 中,要将属性的值更新为 NULL,你可以将属性的值设置为 null,并将实体状态标记为已修改。当你调用 `SaveChanges` 方法时,EF Core 将会将这些更改应用到数据库。 以下是一个示例,展示了如何使用 EF Core 更新属性的值为 NULL: ```csharp using Microsoft.EntityFrameworkCore; using System; // 创建 DbContext 类 public class YourDbContext : DbContext { public YourDbContext(DbContextOptions<YourDbContext> options) : base(options) { } // DbSet 和其他属性... public DbSet<IPS_Invoice> IPS_Invoices { get; set; } } public class IPS_Invoice { public int IPS_ID { get; set; } public bool BLOCK { get; set; } public DateTime? BLOCKTIME { get; set; } } public class YourRepository { private readonly YourDbContext _dbContext; public YourRepository(YourDbContext dbContext) { _dbContext = dbContext; } public string UpdateBlockTimeToNull(int ipsId) { string message = ""; try { var invoice = _dbContext.IPS_Invoices.Find(ipsId); if (invoice != null) { invoice.BLOCKTIME = null; _dbContext.Entry(invoice).State = EntityState.Modified; _dbContext.SaveChanges(); message = "Update successful"; } else { message = "Invoice not found"; } } catch (Exception e) { message = "Update failed"; // 处理异常... } return message; } } ``` 在上述代码中,我们首先创建了一个继承自 `DbContext` 的 `YourDbContext` 类,并定义了需要操作的实体类 `IPS_Invoice`。然后,我们创建了一个名为 `YourRepository` 的仓储类,在该类中使用 `Find` 方法查找要更新的实体对象。 在 `UpdateBlockTimeToNull` 方法中,我们将 `BLOCKTIME` 属性的值设置为 null,并将实体状态标记为已修改。然后,调用 `SaveChanges` 方法将更改应用到数据库。 请根据你的实际情况修改代码,并确保在使用 EF Core 时按照最佳实践进行数据库操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鲁棒最小二乘支持向量机

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值