<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C# &#8211; Other Things</title>
	<atom:link href="https://blog.adamzolo.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.adamzolo.com</link>
	<description>Blog about Things by Adam Zolotarev</description>
	<lastBuildDate>Tue, 28 Jun 2016 01:36:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>MSBuild with C# 6 and UpgradeTemplate.xaml</title>
		<link>https://blog.adamzolo.com/msbuild-csharp-6-upgradetemplate/</link>
					<comments>https://blog.adamzolo.com/msbuild-csharp-6-upgradetemplate/#respond</comments>
		
		<dc:creator><![CDATA[Adam Zolo]]></dc:creator>
		<pubDate>Tue, 28 Jun 2016 01:36:13 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<guid isPermaLink="false">http://www.eazolo.com/blog/?p=309</guid>

					<description><![CDATA[If you use UpgradeTemplate for your MSBuild, getting it to work with C# 6 can be a little tricky. First, we need to set the tools version by passing these parameters to MSBuild: /tv:14.0 /p:VisualStudioVersion=14.0 This, however, may not change the MSBuild version used to run your build. TFS Build server may still use the&#8230;<p><a class="more-link" href="https://blog.adamzolo.com/msbuild-csharp-6-upgradetemplate/" title="Continue reading &#8216;MSBuild with C# 6 and UpgradeTemplate.xaml&#8217;">Continue reading <span class="meta-nav">&#8594;</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>If you use UpgradeTemplate for your MSBuild, getting it to work with C# 6 can be a little tricky.<br />
First, we need to set the tools version by passing these parameters to MSBuild:<br />
/tv:14.0 /p:VisualStudioVersion=14.0</p>
<p>This, however, may not change the MSBuild version used to run your build. TFS Build server may still use the MSBuild from your .Net framework folder (C:\Windows\Microsoft.NET\Framework64\v4.0.30319). To verify the location of your MSBuild, used by the TFS, open one of your completed builds, and check the Diagnostics tab. It should show the MSBuild.exe forlder in the &#8220;Run TfsBuild for Configuration Folder&#8221; step.</p>
<p>To fix this, we need to explicitly set the ToolPath for the MSBuild template.<br />
Open the UpgradeTemplate.xaml in Visual Studio<br />
Right click on &#8220;Run TfsBuild for Configuration&#8221; -> Properties<br />
Set the ToolPath property to point to your msbuild: &#8220;C:\Program Files (x86)\MSBuild\14.0\Bin\&#8221;<br />
Don&#8217;t forget the quotation marks.</p>
<p>While you&#8217;re at it, check out <a href="https://visualstudiogallery.msdn.microsoft.com/47bded90-80d8-42af-bc35-4736fdd8cd13" target="_blank">Target Framework Migrator</a> &#8211; it&#8217;s a Visual Studio extension, which helps update all of your projects to target a specific .Net version. Can be quite helpful when you have a lot of projects.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.adamzolo.com/msbuild-csharp-6-upgradetemplate/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Functional Extensions for C#</title>
		<link>https://blog.adamzolo.com/functional-extensions-csharp/</link>
					<comments>https://blog.adamzolo.com/functional-extensions-csharp/#respond</comments>
		
		<dc:creator><![CDATA[Adam Zolo]]></dc:creator>
		<pubDate>Sat, 20 Feb 2016 16:00:49 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<guid isPermaLink="false">http://www.eazolo.com/blog/?p=203</guid>

					<description><![CDATA[Map Tee Partial Function Application More stuff like this in Dave Fancher PluralSight course Functional Programming with C#]]></description>
										<content:encoded><![CDATA[<p><strong>Map</strong></p>
<pre class="brush: csharp; title: ; notranslate">
public static TResult Map&lt;TSource, TResult&gt;(
	this TSource @this,
	Func&lt;TSource, TResult&gt; fn) =&gt; fn(@this);
);
</pre>
<p><strong>Tee</strong></p>
<pre class="brush: csharp; title: ; notranslate">
public static TResult Tee&lt;t&gt;(
	this T @this,
	Action&lt;T&gt; fn) =&gt; fn(@this)
    {
		act(@this);
		return @this;
	}
);
</pre>
<p><strong>Partial Function Application</strong></p>
<pre class="brush: csharp; title: ; notranslate">
public static Func&lt;int, int&gt; Add(int x) =&gt; y =&gt; x + y;
new&#x5B;] {1, 2, 3}.Select(Add(1))
</pre>
<p>More stuff like this in Dave Fancher PluralSight course <a href="https://app.pluralsight.com/library/courses/functional-programming-csharp" target="_blank">Functional Programming with C#</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.adamzolo.com/functional-extensions-csharp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Short Summary of Delegation in C#</title>
		<link>https://blog.adamzolo.com/short-summary-delegation-c/</link>
					<comments>https://blog.adamzolo.com/short-summary-delegation-c/#respond</comments>
		
		<dc:creator><![CDATA[Adam Zolo]]></dc:creator>
		<pubDate>Sat, 20 Feb 2016 15:29:22 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<guid isPermaLink="false">http://www.eazolo.com/blog/?p=199</guid>

					<description><![CDATA[Classic public delegate decimal MathOp(decimal left, decimal right) public static decimal Add(decimal left, decimal right) { return left + right; } private static MathOp GetOp(char op) { switch (op) { case '+': return Add; } } Interfaces public interface IMathOp { decimal Compute(decimal left, decimal right); } public class AddOp : IMathOp { decimal Compute(decimal&#8230;<p><a class="more-link" href="https://blog.adamzolo.com/short-summary-delegation-c/" title="Continue reading &#8216;Short Summary of Delegation in C#&#8217;">Continue reading <span class="meta-nav">&#8594;</span></a></p>]]></description>
										<content:encoded><![CDATA[<p><strong>Classic</strong></p>
<pre class="brush: csharp; title: ; notranslate">
public delegate decimal MathOp(decimal left, decimal right)

public static decimal Add(decimal left, decimal right)
{
	return left + right;
}
private static MathOp GetOp(char op)
{
	switch (op)
	{
		case '+': return Add;
	}
}
</pre>
<p><strong>Interfaces</strong></p>
<pre class="brush: csharp; title: ; notranslate">
public interface IMathOp
{
	decimal Compute(decimal left, decimal right);
}

public class AddOp : IMathOp
{

	decimal Compute(decimal l, decimal r)
	{
		return l + r;
	}
}

private static MathOp GetOp(char op)
{
	switch (op)
	{
		case '+': return new AddOp();
	}
}
</pre>
<p><strong>Anonymous Methods</strong></p>
<pre class="brush: csharp; title: ; notranslate">
public delegate decimal MathOp(decimal left, decimal right)

private static MathOp GetOp(char op)
{
	switch (op)
	{
		case '+': return delegate (decimal l, decimal r) { return l + r};
	}
}
</pre>
<p><strong>Generic Delegates and Lambda Expressions</strong></p>
<pre class="brush: csharp; title: ; notranslate">
public static Func&lt;decimal, decimal, decimal&gt; GetOp(char op)
{
	switch (op)
	{
		case '+': return (l, r) =&gt; l + r;
	}
}
</pre>
<p>For complete details, see Dave Fancher PluralSight course <a href="https://app.pluralsight.com/library/courses/functional-programming-csharp" target="_blank">Functional Programming with C#</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.adamzolo.com/short-summary-delegation-c/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>C# 6 Summary</title>
		<link>https://blog.adamzolo.com/c-sharp-6-summary/</link>
					<comments>https://blog.adamzolo.com/c-sharp-6-summary/#respond</comments>
		
		<dc:creator><![CDATA[Adam Zolo]]></dc:creator>
		<pubDate>Mon, 07 Dec 2015 00:25:02 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<guid isPermaLink="false">http://www.eazolo.com/blog/?p=172</guid>

					<description><![CDATA[Short and incomplete notes on Rob Conery Pluralsight course &#8220;Exploring C# 6 with Jon Skeet&#8221; Auto-properties Immutability Old way (still can set anywhere within the class) public string Name {get; private set;} New way (can be set only in a constructor or initializer) public string Name{get;} &#160; Initializers public string Name{get;} = &#34;J&#34;; &#160; Expression-bodied&#8230;<p><a class="more-link" href="https://blog.adamzolo.com/c-sharp-6-summary/" title="Continue reading &#8216;C# 6 Summary&#8217;">Continue reading <span class="meta-nav">&#8594;</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>Short and incomplete notes on Rob Conery Pluralsight course &#8220;Exploring C# 6 with Jon Skeet&#8221;</p>
<ul>
<li><strong>Auto-properties</strong><br />
<em>Immutability</em><br />
Old way (still can set anywhere within the class)</p>
<pre class="brush: csharp; title: ; notranslate">
public string Name {get; private set;}
</pre>
<p>New way (can be set only in a constructor or initializer)</p>
<pre class="brush: csharp; title: ; notranslate">
public string Name{get;}
</pre>
<p>&nbsp;<br />
<em>Initializers</em></p>
<pre class="brush: csharp; title: ; notranslate">
public string Name{get;} = &quot;J&quot;;
</pre>
</li>
<p>&nbsp;</p>
<li><strong>Expression-bodied members</strong><br />
<em>For Properties</em><br />
Old way</p>
<pre class="brush: csharp; title: ; notranslate">
public Timespan Age{ get {return DateTime.UtcNow - DateOfBirth;}
</pre>
<p>New way</p>
<pre class="brush: csharp; title: ; notranslate">
public Timespan Age =&gt; return DateTime.UtcNow - DateOfBirth;
</pre>
<p>&nbsp;<br />
<em>For Methods</em><br />
Old way</p>
<pre class="brush: csharp; title: ; notranslate">
public int GetName() {return &quot;Joe&quot;;}
</pre>
<p>New way</p>
<pre class="brush: csharp; title: ; notranslate">
public int GetName() =&gt; &quot;Joe&quot;;
</pre>
</li>
<p>&nbsp;</p>
<li><strong>nameof</strong><br />
Old way<br />
Use string literal; expression tree, or [CallerMemberName] attribute<br />
New way<br />
nameof(propertyName)</li>
<p>&nbsp;</p>
<li><strong>Using Static</strong><br />
Old way</p>
<pre class="brush: csharp; title: ; notranslate">
Math.Sin(x)
SomeEnum.EnumName
</pre>
<p>New way</p>
<pre class="brush: csharp; title: ; notranslate">
using static System.Math;
using static SomeEnum
...
Sin(x)
EnumName
</pre>
</li>
<p>&nbsp;</p>
<li><strong>String Interpolation</strong><br />
$&#8221;{SomePropertyOrExpression} &#8230;&#8221;</li>
<p>&nbsp;</p>
<li><strong>Nullability</strong><br />
<em>Null Conditional Operator</em><br />
Old way</p>
<pre class="brush: csharp; title: ; notranslate">
return a!=null &amp;&amp; a.b!=null &amp;&amp; a.b.c==&quot;abc&quot;;
</pre>
<p>New way</p>
<pre class="brush: csharp; title: ; notranslate">
return a!.b!.c==&quot;abc&quot;;
</pre>
<p>&nbsp;<br />
<em>Event Handlers</em><br />
Old way</p>
<pre class="brush: csharp; title: ; notranslate">
var handler = eventHandler;
if (handler !=null) {handler...}
</pre>
<p>New way</p>
<pre class="brush: csharp; title: ; notranslate">
eventHandler?.Invoke...
</pre>
</li>
<p>&nbsp;</p>
<li><strong>Exception Filters</strong>
<pre class="brush: csharp; title: ; notranslate">
catch(WebException e) when(e.Status == ...)
</pre>
</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.adamzolo.com/c-sharp-6-summary/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Custom MVC Model Binder</title>
		<link>https://blog.adamzolo.com/custom-mvc-model-binder/</link>
					<comments>https://blog.adamzolo.com/custom-mvc-model-binder/#respond</comments>
		
		<dc:creator><![CDATA[Adam Zolo]]></dc:creator>
		<pubDate>Wed, 02 Dec 2015 18:19:39 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web]]></category>
		<guid isPermaLink="false">http://www.eazolo.com/blog/?p=164</guid>

					<description><![CDATA[When you expect data in non-standard way and you want it to magically bind to your model, custom model binders could be a way to go. Let&#8217;s say we want to post xml data to our controller method and we have a model for it. public class XmlModel { public int Number { get; set;&#8230;<p><a class="more-link" href="https://blog.adamzolo.com/custom-mvc-model-binder/" title="Continue reading &#8216;Custom MVC Model Binder&#8217;">Continue reading <span class="meta-nav">&#8594;</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>When you expect data in non-standard way and you want it to magically bind to your model, custom model binders could be a way to go.</p>
<p>Let&#8217;s say we want to post xml data to our controller method and we have a model for it.</p>
<pre class="brush: csharp; title: ; notranslate">
public class XmlModel
        {
            public int Number { get; set; }
        }
</pre>
<p>Which we want to accept in our controller method:</p>
<pre class="brush: csharp; title: ; notranslate">
public ActionResult Xml(XmlModel xmlModel)
        {
            return Content(xmlModel.Number.ToString());
        }

</pre>
<p>Now, let&#8217;s add our xml binder:</p>
<pre class="brush: csharp; title: ; notranslate">
public class XmlModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var modelType = bindingContext.ModelType;
            return new XmlSerializer(modelType).Deserialize(controllerContext.HttpContext.Request.InputStream);
        }
    }
</pre>
<p>And XMLModelBinderProvider:</p>
<pre class="brush: csharp; title: ; notranslate">
public class XMLModelBinderProvider : IModelBinderProvider
    {      
        public IModelBinder GetBinder(Type modelType)
        {
            var contentType = HttpContext.Current.Request.ContentType;
            if (string.Compare(contentType, @&quot;text/xml&quot;, StringComparison.OrdinalIgnoreCase) != 0)
            {
                return null;
            }

            return new XmlModelBinder();
        }
    }
</pre>
<p>Add the provider to our Application_Start method in the Global.asax:</p>
<pre class="brush: csharp; title: ; notranslate">
ModelBinderProviders.BinderProviders.Insert(0, new XMLModelBinderProvider()); 
</pre>
<p>To test this we can use Composer from Fiddler:<br />
http://localhost/home/xml<br />
User-Agent: Fiddler<br />
Content-Type: text/xml</p>
<p>Request Body:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;XmlModel&gt;
&lt;Number&gt;42&lt;/Number&gt;
&lt;/XmlModel&gt;
</pre>
<p>If we add breakpoint in our controller, we should see 42 coming through in our model.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.adamzolo.com/custom-mvc-model-binder/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to generate WCF Proxy</title>
		<link>https://blog.adamzolo.com/generate-wcf-proxy/</link>
					<comments>https://blog.adamzolo.com/generate-wcf-proxy/#respond</comments>
		
		<dc:creator><![CDATA[Adam Zolo]]></dc:creator>
		<pubDate>Sat, 12 Sep 2015 20:53:47 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<guid isPermaLink="false">http://eazolo.com/blog/?p=145</guid>

					<description><![CDATA[svcutil.exe http://WCF-service.svc?wsdl /namespace:*,MyCustomNamespace svcutil.exe location: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools]]></description>
										<content:encoded><![CDATA[<p>svcutil.exe http://WCF-service.svc?wsdl /namespace:*,MyCustomNamespace</p>
<p>svcutil.exe location: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.adamzolo.com/generate-wcf-proxy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Find Column Causing &#8220;String or binary data would be truncated&#8221; Exception in Entity Framework 5.0.</title>
		<link>https://blog.adamzolo.com/entity-framework-5-string-or-binary-data-would-be-truncated/</link>
					<comments>https://blog.adamzolo.com/entity-framework-5-string-or-binary-data-would-be-truncated/#comments</comments>
		
		<dc:creator><![CDATA[Adam Zolo]]></dc:creator>
		<pubDate>Mon, 09 Sep 2013 20:59:48 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<guid isPermaLink="false">http://eazolo.com/blog/?p=18</guid>

					<description><![CDATA[I recently encountered an issue with Entity Framework when it would throw &#8220;String or binary data would be truncated. The statement has been terminated.&#8221; Since the query contained close to 80 fields, I needed an easy way to determine the culprit. Since I already had a class which inherits from DbContext, I added suggested try-catch&#8230;<p><a class="more-link" href="https://blog.adamzolo.com/entity-framework-5-string-or-binary-data-would-be-truncated/" title="Continue reading &#8216;How to Find Column Causing &#8220;String or binary data would be truncated&#8221; Exception in Entity Framework 5.0.&#8217;">Continue reading <span class="meta-nav">&#8594;</span></a></p>]]></description>
										<content:encoded><![CDATA[<p>I recently encountered an issue with Entity Framework when it would throw &#8220;String or binary data would be truncated. The statement has been terminated.&#8221; Since the query contained close to 80 fields, I needed an easy way to determine the culprit. Since I already had a class which inherits from DbContext, I added <a title="EF Exception: String or binary data would be truncated" href="http://stackoverflow.com/questions/13380972/ef-exception-string-or-binary-data-would-be-truncated-the-statement-has-been-t" target="_blank">suggested</a> try-catch block in my SaveChanges() override method:</p>
<pre class="brush: csharp; title: ; notranslate">
public partial class MyContext : DbContext
	{
		public override int SaveChanges()
		{
			try
			{
				return base.SaveChanges();
			}
			catch (DbEntityValidationException ex)
			{
				foreach (var error in ex.EntityValidationErrors)
				{
					Console.WriteLine(&quot;====================&quot;);
					Console.WriteLine(
						&quot;Entity {0} in state {1} has validation errors:&quot;,
						error.Entry.Entity.GetType().Name,
						error.Entry.State);
					foreach (var ve in error.ValidationErrors)
					{
						Console.WriteLine(&quot;\tProperty: {0}, Error: {1}&quot;, ve.PropertyName, ve.ErrorMessage);
					}
					Console.WriteLine();
				}
				throw;
			}
		}
	}
</pre>
<p>You have to make sure that you don&#8217;t set ValidateOnSaveEnabled to false. It is set to true by default, but sometimes it is useful to disable it to improve performance.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.adamzolo.com/entity-framework-5-string-or-binary-data-would-be-truncated/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
