如何获取内置MSBuild变量列表?
我需要知道如何确定当前项目的csproj名称,并认为知道我在MSBuild中可以找到的其他内容可能会有用.
我正在使用反射来获取TryParse方法信息(为第一个人提供upvote以猜测原因;).
如果我打电话:
typeof(Int32).GetMethod("Parse",
BindingFlags.Static | BindingFlags.Public,
null,
new Type[] { typeof(string) },
null);
Run Code Online (Sandbox Code Playgroud)
我得到一个方法,但稍微扩展一下:
typeof(Int32).GetMethod("TryParse",
BindingFlags.Static | BindingFlags.Public,
null,
new Type[] { typeof(string), typeof(Int32) },
null);
Run Code Online (Sandbox Code Playgroud)
我一无所获.我的spidersense告诉我这是因为第二个参数是out参数.
谁知道我在这里做错了什么?
花了一些时间学习函数式编程,我想要使用不执行任何变异的静态方法变得越来越自然.
有什么理由可以抑制这种本能吗?
我知道在f#中我可以将out参数视为结果元组的成员,当我从F#中使用它们时,例如
(success, i) = System.Int32.TryParse(myStr)
Run Code Online (Sandbox Code Playgroud)
我想知道的是我如何定义一个成员,使C#中的签名看起来像一个out参数.
是否有可能做到这一点?我可以只返回一个元组,并且当我从C#调用该方法时会发生相反的过程,例如
type Example() =
member x.TryParse(s: string, success: bool byref)
= (false, Unchecked.defaultof<Example>)
Run Code Online (Sandbox Code Playgroud) 我希望保存较小的图像尺寸.我怎样才能调整它?我使用此代码来重新映射图像:
Size size = new Size(surface.Width, surface.Height);
surface.Measure(size);
surface.Arrange(new Rect(size));
// Create a render bitmap and push the surface to it
RenderTargetBitmap renderBitmap =
new RenderTargetBitmap(
(int)size.Width,
(int)size.Height, 96d, 96d,
PixelFormats.Default);
renderBitmap.Render(surface);
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
// push the rendered bitmap to it
encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
// save the data to the stream
encoder.Save(outStream);
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用任意 字符串访问嵌套类结构的各个部分.
鉴于以下(人为)课程:
public class Person
{
public Address PersonsAddress { get; set; }
}
public class Adddress
{
public PhoneNumber HousePhone { get; set; }
}
public class PhoneNumber
{
public string Number { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我希望能够"PersonsAddress.HousePhone.Number"从对象的实例中获取Person对象.
目前我正在使用反射进行一些时髦的递归查找,但我希望有一些忍者有更好的想法.
作为参考,这是我开发的(蹩脚)方法:
private static object ObjectFromString(object basePoint, IEnumerable<string> pathToSearch)
{
var numberOfPaths = pathToSearch.Count();
if (numberOfPaths == 0)
return null;
var type = basePoint.GetType();
var properties = type.GetProperties();
var currentPath = pathToSearch.First();
var propertyInfo = …Run Code Online (Sandbox Code Playgroud) 我最近与同事讨论了推动我们的Web应用程序遵循纪律的n层结构.让我感到震惊的是,我想不出任何其他选择.
是否总是应该将Web应用程序分层?
我知道有几个问题提出了同样的问题"我为什么要使用发布模式".我对答案的问题在于,他们只是非常强烈地声明,当网站投入生产时,你应该始终使用发布模式.
为什么?
我知道代码在程序集中进行了优化,但到了什么级别?是否会优化编写良好的代码?它的表现有哪些优化?
对此有任何分析吗?无论如何我可以测试调试和发布之间的差异吗?
我真的希望有人能够理解为什么这样做至少可以提供一些明确的阅读材料,因为我还没有找到足够的东西来满足我对这个问题的好奇心.
我试图在我的yesod路由中以类似休息的方式指定查询,例如
mkYesod "HelloWorld" [parseRoutes|
/ HomeR GET
/first/?count=#Int FirstR GET
/second/?count=#Int SecondR GET
|]
Run Code Online (Sandbox Code Playgroud)
但这给了我以下错误:
The function `FirstR' is applied to one argument,
but its type `Route HelloYesod' has none
Run Code Online (Sandbox Code Playgroud)
但是,如果我把它推#Int回到路径的一部分,那一切都很好.我假设这是因为路由不是用参数生成的?
有没有办法在我的路线中指定该参数?
我需要在一个Image上执行多个操作,例如,我需要调整图像的大小,也许填充它以保持纵横比(并绘制背景颜色),并有条件地用水印标记.
我目前正在使用BitmapFrame我在所涉及的方法之间传递的类型.
任何人都可以推荐另一种我应该用于对图像执行增量更新的类型吗?
我可以创建各种图像的组合,虽然我不确定我应该使用哪种类型的图像?
c# ×5
asp.net ×2
reflection ×2
wpf ×2
.net ×1
architecture ×1
bitmap ×1
clr ×1
f# ×1
haskell ×1
image ×1
msbuild ×1
performance ×1
release-mode ×1
resize ×1
yesod ×1