Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Forgall
Oct 16, 2012

by Azathoth

GrumpyDoctor posted:

It's fine. Everyone else does it, so you won't be any more hosed than the rest of us if there's a problem.
I've looked some more and had this line in Object.GetHashCode documentation pointed out to me: "For classes derived from Object, the GetHashCode method can delegate to the base class Object.GetHashCode() implementation only if the derived class defines equality to be reference equality.". Should have noticed it before. So base GetHashCode for objects which are only compared by reference should be fine. Implementation-wise, hash code seems to be calculated once when it's requested for the first time and stored in part of the object called SyncBlock. It should reliably stay the same for object's lifetime. That's interesting detail, didn't know that. My mind is put to rest on this issue then.

Unrelated to that: it's really annoying that .net exceptions, compiler errors and warnings etc are all forcibly localized to my system's language, and there doesn't seem to be a way to get rid of that.

Forgall fucked around with this message at 19:00 on Dec 11, 2014

Adbot
ADBOT LOVES YOU

bpower
Feb 19, 2011
Please help!
When I run an MVC .net web app VS 2013 instantly freezes and the sites takes ages bur it does run. VS remains frozen even when I shut down the site in the browser.

I have the following error in event viewer. It mentions something about TestProjectHelper but it has the problem with the boilerplate mvc app with no test project. Simple console apps run as expected.


I have vs 2013 Ultimate Update 4

quote:

The description for Event ID 0 from source VSTTExecution cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event:

(devenv.exe, PID 10716, Thread 1) TestProjectHelper.AreReferencesEqual: failed to parse assembly name from msbuild: System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
at System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
at System.Reflection.AssemblyName..ctor(String assemblyName)
at Microsoft.VisualStudio.TestTools.Vsip.TestProjectHelper.TryGetProjectToAssemblyReference(ProjectItem msbuildReference)

the message resource is present but the message is not found in the string/message table


followed by this warning

quote:

The directory specified for caching compressed content C:\Users\Brian\AppData\Local\Temp\iisexpress\IIS Temporary Compressed Files\Clr4IntegratedAppPool is invalid. Static compression is being disabled.


I've repaired and reinstalled vs 2013 already. I've googled to the best of my ability but found nothing.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

This is pretty old but when I used to get that error in the past I'd follow some of it:
http://blogs.msdn.com/b/dougste/archive/2006/09/05/741329.aspx

The use of FUSELOG and FILEMON especially.

Maybe someone will contradict me but I've seen the second warning all the time and generally ignore it, if it occurs in development.

Eggnogium
Jun 1, 2010

Never give an inch! Hnnnghhhhhh!
I have a bunch of parameters I need to throw in a query string to a REST API. Is there a function in .NET that will take in the final URI string and replace all the spaces with %20 and the backslashes with %5c and such?

Having trouble googling for this for some reason.


http://msdn.microsoft.com/en-us/library/4fkewx0t

I always find what I'm looking for immediately after I post, so thanks, thread.

Eggnogium fucked around with this message at 22:21 on Dec 11, 2014

Mr Shiny Pants
Nov 12, 2012

wwb posted:

If you are deploying applications this way you are probably retarded. Use a build server.

Harsh much? I was just wondering about the way it does the actual copying and the convoluted way of setting extra permissions.

bpower
Feb 19, 2011

Scaramouche posted:

This is pretty old but when I used to get that error in the past I'd follow some of it:
http://blogs.msdn.com/b/dougste/archive/2006/09/05/741329.aspx

The use of FUSELOG and FILEMON especially.

Maybe someone will contradict me but I've seen the second warning all the time and generally ignore it, if it occurs in development.


Fuslog has loads of entries every time i run vs.

quote:

*** Assembly Binder Log Entry (11/12/2014 @ 23:35:27) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Data.Tools.Schema.Utilities.Sql, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = devenv.exe
Calling assembly : Microsoft.VisualStudio.Data.Tools.Package, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Users\Brian\AppData\Local\Microsoft\VisualStudio\12.0\devenv.exe.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.Data.Tools.Schema.Utilities.Sql, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/Microsoft.Data.Tools.Schema.Utilities.Sql.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/Microsoft.Data.Tools.Schema.Utilities.Sql/Microsoft.Data.Tools.Schema.Utilities.Sql.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PublicAssemblies/Microsoft.Data.Tools.Schema.Utilities.Sql.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PublicAssemblies/Microsoft.Data.Tools.Schema.Utilities.Sql/Microsoft.Data.Tools.Schema.Utilities.Sql.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies/Microsoft.Data.Tools.Schema.Utilities.Sql.DLL.
.
.
A load more
.
LOG: All probing URLs attempted and failed.

That sql dll is actually here...

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\120\Microsoft.Data.Tools.Schema.Utilities.Sql.dll

Help!

bpower
Feb 19, 2011
I uninstalled an old version of c# express. I think thats what hosed it all up. Anyway, all the problems were fixed by deleting

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files

http://stackoverflow.com/questions/3394106/gac-assembly-is-in-the-gac-but-could-not-load-file-or-assembly

RICHUNCLEPENNYBAGS
Dec 21, 2010

Ithaqua posted:

It's because (IMO) the IDE-based deployment stuff is targeted at solo developers who just push software to an arbitrary environment on an arbitrary schedule with no formal build/CI process, not actual businesses. There are some more enterprisey offerings for release management these days, but they're not a great fit for solo developers.

Hopefully Microsoft is working on getting the two to meet in the middle.

So, speaking as the only full-time dev at my workplace, I definitely do not want something with a complex formal build/CI process. What's the benefit for such small-time shops, really?

We have a private nuget server for in-house dependencies so I'll just keep a canonical git branch for any actual production release and it'll be referencing the right versions of dependencies.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

Dromio posted:

We’ve had an issue where we changed our deployment to support testing an upcoming release in development and QA, but then had to re-deploy the older Production build and couldn’t without a good deal of work.
I think Octo will keep track of the config and steps for a deployment so if you have a previous actual deployment to prod you should be able to find it and repeat it with the the same process. Creating a new release will use the new settings though.

If you run into similar again one way of mitigating a bit is to just add new tags to your servers and target the new steps to them. If there's no servers matching those tags in production those steps can be skipped. You might be able to target config transforms to tags as well but I'm not 100% on that.

Mr Shiny Pants
Nov 12, 2012

RICHUNCLEPENNYBAGS posted:

So, speaking as the only full-time dev at my workplace, I definitely do not want something with a complex formal build/CI process. What's the benefit for such small-time shops, really?

We have a private nuget server for in-house dependencies so I'll just keep a canonical git branch for any actual production release and it'll be referencing the right versions of dependencies.

Exactly, and IIS express is not IIS.

crashdome
Jun 28, 2011

GrumpyDoctor posted:

.NET Megathread 3.5: you won't be any more hosed than the rest of us if there's a problem.

crashdome
Jun 28, 2011
Beep bop boop double post

Space Whale
Nov 6, 2014
I want to find an object in a collection by a property, but return another property of that found object, with LINQ. This is trickier than I'd have anticipated.

code:
//vendorId arrives from the DB
//collectionOfFoo does too

gimmeAString = collectionOfFoo.Where(foo => foo.LookupId == vendorId).Select(foo => foo.LookupDescription).ToString(); 
"gimmeAString" isn't the value of LookupDescription, but is instead a bunch of type information about the collectionOfFoo.

Wardende
Apr 27, 2013
Select() returns an IEnumerable, even if it only has one item. So you're calling ToString on IEnumerable<string> which just returns the type info. What you probably want is this:

gimmeAString = collectionOfFoo.First(foo => foo.LookupId == vendorId).LookupDescription

This will throw an exception if collectionOfFoo doesn't have a foo where the LookupId matches the vendorId, though, so you could call FirstOrDefault, do a null check, then assign the LookupDescription if it has been found - if you can't rely on a matching value always being present in the collection.

Space Whale
Nov 6, 2014

Wardende posted:

Select() returns an IEnumerable, even if it only has one item. So you're calling ToString on IEnumerable<string> which just returns the type info. What you probably want is this:

gimmeAString = collectionOfFoo.First(foo => foo.LookupId == vendorId).LookupDescription

This will throw an exception if collectionOfFoo doesn't have a foo where the LookupId matches the vendorId, though, so you could call FirstOrDefault, do a null check, then assign the LookupDescription if it has been found - if you can't rely on a matching value always being present in the collection.

That's what I ended up doing.

Know of a good LINQ book for santa to order on amazon for me? I really need to do more than just cargo cult it.

brap
Aug 23, 2004

Grimey Drawer
Honestly there's not that much to it. Select to apply a function to the elements of a sequence, Where to filter down to elements that satisfy a predicate, First to get the first element that satisfies the predicate, FirstOrDefault to keep your program from blowing up if one isn't found, Last similarly gets the last item matching a predicate, OrderBy and ThenBy to sort a list, Any to see if any elements in the list satisfy a predicate, All to see if all items in a list match a predicate. Those are what you'll use like 90% of the time.

There is some interesting SQL-like stuff you can do with GroupBy but I've found it pretty confusing in the context of C#.

wwb
Aug 17, 2004

RICHUNCLEPENNYBAGS posted:

So, speaking as the only full-time dev at my workplace, I definitely do not want something with a complex formal build/CI process. What's the benefit for such small-time shops, really?

We have a private nuget server for in-house dependencies so I'll just keep a canonical git branch for any actual production release and it'll be referencing the right versions of dependencies.

Automated CI / build is vastly more important in a one man shop than a big shop for a few reasons:

* It keeps you honest and makes sure you don't skip a step. Which is really easy when nobody is even capable of looking over your shoulder.
* Keeps the bus factor a bit under control -- the best source control in the world is worthless if nobody can build / deploy the app effectively.
* As the only full-time dev do you want to spend your time babysitting deployments or writing features / quashing bugs?
* All the normal advantages apply beyond this.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Space Whale posted:

That's what I ended up doing.

Know of a good LINQ book for santa to order on amazon for me? I really need to do more than just cargo cult it.

I'd recommend C# in Depth by Jon Skeet. It's got a chapter on LINQ, but it also has tons of other useful information if you're getting started with C#. Read it cover to cover if you have the time.

bpower
Feb 19, 2011
Im learning linq at the moment. This is a good quick reference..
https://code.msdn.microsoft.com/101-linq-samples-3fb9811b


Automapper/ view model question. I want to add a calculated field to a view model.


Lets say I have a viewmodel like
code:
class PersonViewModel
{
string name 
date DOB
string SpouseName

}
My mapconfig looks like
code:
configuration.CreateMap<Person, PersonViewModel>()
                            .ForMember(dest => dest.SpouceName,
                                        src => src.MapFrom(
                                            i => i.Partner.UserName))

I map with
code:
var personViewModel = db.People.Project().To<PersonViewModel>();
That works fine.

Now I want to add a calculated field "int NumberOfDogs" to the view model
code:
class PersonViewModel
{
string name 
date DOB
string SpouseName
int NumberOfDogs
}
I want to do something like the following sql and put it in my new updated PersonViewModel

code:
select p.* ,
(select count(*) from pets  pt where pt.personId = p.personId and pt.breed = 'DOG') as NumberOfDog
from people
left join pets  pt on p.personId = pt.personId
I'm stuck because I can't write that in Linq and even if i did I wouldn't know how to map it. I have no Source class to map from.

RICHUNCLEPENNYBAGS
Dec 21, 2010

wwb posted:

Automated CI / build is vastly more important in a one man shop than a big shop for a few reasons:

* It keeps you honest and makes sure you don't skip a step. Which is really easy when nobody is even capable of looking over your shoulder.
* Keeps the bus factor a bit under control -- the best source control in the world is worthless if nobody can build / deploy the app effectively.
* As the only full-time dev do you want to spend your time babysitting deployments or writing features / quashing bugs?
* All the normal advantages apply beyond this.

I mean... there aren't really that many steps or babysitting. I branch, commit, right-click my project and click "publish to Azure," and it's live. We do releases roughly quarterly (although obviously bug fixes or whatever can happen sooner); maybe I'd feel differently if I were pushing out changes more regularly.

InfernoJack
Dec 13, 2014

bpower posted:

I want to do something like the following sql and put it in my new updated PersonViewModel

code:
select p.* ,
(select count(*) from pets  pt where pt.personId = p.personId and pt.breed = 'DOG') as NumberOfDog
from people
left join pets  pt on p.personId = pt.personId
I'm stuck because I can't write that in Linq and even if i did I wouldn't know how to map it. I have no Source class to map from.

You can nest linq expressions inside linq expressions. See http://stackoverflow.com/questions/9334919/linq-nested-query

bpower
Feb 19, 2011
Nice.

So, is there a way to AutoMapper to help with the following? Pretend the subquery is on tables not so closely related to People.

code:
var q  = from p in db.people 
join pets  on p.personId = pt.personId
select new personViewModel {
 name = p.UserName,
 DOB  = p.DOB,
 SpouseName = p.Partner.UserName,
 NumberOfDogs = db.pets.count(pcnt => pcnt.Breed == 'DOG' and pcnt.PersonId == p.PersonId)
}

RICHUNCLEPENNYBAGS
Dec 21, 2010
You know you can use blocks as Func arguments, right?

Wardende
Apr 27, 2013

Space Whale posted:

That's what I ended up doing.

Know of a good LINQ book for santa to order on amazon for me? I really need to do more than just cargo cult it.

C# In Depth by Jon Skeet is the canonical reference. Once you understand anonymous functions, the LINQ extension methods are a cinch.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Wardende posted:

C# In Depth by Jon Skeet is the canonical reference. Once you understand anonymous functions, the LINQ extension methods are a cinch.

Well, the lazily evaluated thing bites people too. But yeah, it's not magic.

InfernoJack
Dec 13, 2014

RICHUNCLEPENNYBAGS posted:

Well, the lazily evaluated thing bites people too. But yeah, it's not magic.

I dunno man. I looked at the Entity source once.

Pretty sure Black Magic.

RICHUNCLEPENNYBAGS
Dec 21, 2010

InfernoJack posted:

I dunno man. I looked at the Entity source once.

Pretty sure Black Magic.

I'd love to do runtime-generated classes like EF does but you gotta gently caress with Reflection.Emit and basically write assembly. Maybe Roslyn will make it easier to do that kinda thing.

Mr Shiny Pants
Nov 12, 2012

InfernoJack posted:

I dunno man. I looked at the Entity source once.

Pretty sure Black Magic.

Take a look at F# type providers, that will cook your noodle.

xgalaxy
Jan 27, 2004
i write code
I've got a question / concern about HttpWebRequest.
Keep in mind I'm working in Unity3d so I only have access to .Net 3.5 features, so no async/await or HttpClient.

I want to use HttpWebRequest BeginGetResponse but there is a note on it saying that this call can block for various reasons and that I shouldn't call it from a UI thread. May I ask what is the loving point of this call then? How should I deal with this? It seems kind of stupid to spin up a thread just so I can call what is supposed to be an asynchronous call in the first place. If I have to spin up a thread to make this call I might as well save the hassle of working in callbacks and just make my own thread and use the synchronous version GetResponse instead.

xgalaxy fucked around with this message at 17:25 on Dec 13, 2014

Funking Giblet
Jun 28, 2004

Jiglightful!

bpower posted:

Im learning linq at the moment. This is a good quick reference..
https://code.msdn.microsoft.com/101-linq-samples-3fb9811b


Automapper/ view model question. I want to add a calculated field to a view model.


Lets say I have a viewmodel like
code:
class PersonViewModel
{
string name 
date DOB
string SpouseName

}
My mapconfig looks like
code:
configuration.CreateMap<Person, PersonViewModel>()
                            .ForMember(dest => dest.SpouceName,
                                        src => src.MapFrom(
                                            i => i.Partner.UserName))

I map with
code:
var personViewModel = db.People.Project().To<PersonViewModel>();
That works fine.

Now I want to add a calculated field "int NumberOfDogs" to the view model
code:
class PersonViewModel
{
string name 
date DOB
string SpouseName
int NumberOfDogs
}
I want to do something like the following sql and put it in my new updated PersonViewModel

code:
select p.* ,
(select count(*) from pets  pt where pt.personId = p.personId and pt.breed = 'DOG') as NumberOfDog
from people
left join pets  pt on p.personId = pt.personId
I'm stuck because I can't write that in Linq and even if i did I wouldn't know how to map it. I have no Source class to map from.

Look at writing a ValueResolver.

xgalaxy
Jan 27, 2004
i write code
Kind of a dumb bikeshedding-ish question but what is more idiomatic C#?
code:
public delegate void ScheduleCallback(int id, object state);

public interface IScheduler
{
    int Schedule(TimeSpan delay, bool repeating, ScheduleCallback callback, object state);
}
vs
code:
public interface IScheduler
{
    // let them capture their own state if they need it
    int Schedule(TimeSpan delay, bool repeating, Action<int> callback);
}
Thinking about it some more I guess they both have their uses. For instance if the Scheduler, in this case, needed to do something with the state object in the implementation. But if that were the case maybe an Action<int, object> would still be preferable? I dunno. It seemed like the trend was towards using Action and Func over bare delegates these days but I wasn't certain. Thoughts?

xgalaxy fucked around with this message at 23:05 on Dec 14, 2014

Okita
Aug 31, 2004
King of toilets.
/\/\/\
I'd go for the second one. Less code, easier to understand. Someone looking over the code won't have to refer back to the ScheduleCallback delegate to figure out what it is.
---

Kind of unrelated, but I thought I'd share some cool stuff I found out about System.Linq.Expressions. If anyone has used a javascript graphics/game library(such as Phaser or EaselJS) in the past, they know how tweening is done there.
Tweening or in-betweening, is taking an initial value and a target value, and coming up with intermediate values so it looks like a smooth transition over time instead of a jump. It's typically used for animation stuff but it doesn't have to be.

I wanted to see if this was possible to do in C# in a generic way and it turns out the answer is yes.

I started out with the goal of having code that looks something like this:
code:
Tween.Create(() => label.Layout.Bounds.Y, 350, 5000);
What this statement should do is take the property label.Layout.Bounds.Y, and over the course of 5000 milliseconds smoothly nudge it from it's initial value over to the target value of 350. Keep in mind that this needs to be as generic as possible so it can be used on any property on any type.

How can this be done you ask? With System.Linq.Expressions.
Here's some very gutted sample code showing the mechanism of how I did it:
code:
public static void ExpressionTest<T>(Expression<Func<T>> expression)
{
	MemberExpression memberExpression;

	// This is required because Expression does some wierd thing with the "object" type where it adds a Convert call in the expression
	switch (expression.Body.NodeType)
	{
		case ExpressionType.Convert:
			memberExpression = (MemberExpression) ((UnaryExpression) expression.Body).Operand;
			break;
		case ExpressionType.MemberAccess:
			memberExpression = (MemberExpression) expression.Body;
			break;
		default:
			throw new Exception("Unable to parse expression for tween target");
	}
	
	// This gives us a setter lamdba that we can use to assign values to the property
	var setter = value =>
                        Expression.Lambda(Expression.Assign(memberExpression, Expression.Constant(value)))
                            .Compile()
                            .DynamicInvoke();
	
	// This gives us the initial value contained in the property
	var initialValue = expression.Compile()();
	
	// Now we can do things with the initial value/setter, but we still have to be mindful of the expression's actual type
	if(memberExpression.Type == typeof(int))
	{
		setter(2000);
	}
	
	// Or what I ended up doing was allowing the registration of different handler classes for different types, 
	// so the Tween class itself can detect which handler it needs to use for which type
}
I hooked up the actual timer code with Monogame/XNA game timers, but it could theoretically use any kind of timing.
I also stole this guy's easing functions. An easing function gives the path for the transition to occur. The simplest case of a linear easing function just takes a linear path from the initial value to the target value. If you want to get more fancy, there's sine wave based functions and other stuff that you can also steal from the site linked above.

E:
If it's not immediately obvious why I shouldn't just convert everything to double and go from there, this technique can be used for non-numeric types as well(any type really).

For example, you could create a handler for string that takes an initial string and target string and adds letters smoothly over the duration:

code:
something.Title = "Yes";
Tween.Create(() => something.Title, " it is awesome", 5000);
This could produce something like this:

code:
0 ms: "Yes"
360 ms: "Yes "
720 ms: "Yes i"
1080 ms: "Yes it"
...
5000 ms: "Yes it is awesome"

Okita fucked around with this message at 03:04 on Dec 15, 2014

Forgall
Oct 16, 2012

by Azathoth

Okita posted:

code:
var setter = value =>
                        Expression.Lambda(Expression.Assign(memberExpression, Expression.Constant(value)))
                            .Compile()
                            .DynamicInvoke();
Looks like expression is being compiled every time you call setter. I think you can make an expression that takes parameter and compile it just once.

Gul Banana
Nov 28, 2003

Does anyone know whether it is possible to do an upgrade install from windows 7 to 8 while preserving an installed copy of Visual Studio?

EssOEss
Oct 23, 2006
128-bit approved
Yes, an upgrade install of Windows will leave any existing Visual Studio installation in an operational state, barring exceptional circumstances.

Mr. Crow
May 22, 2008

Snap City mayor for life

xgalaxy posted:

Kind of a dumb bikeshedding-ish question but what is more idiomatic C#?
code:
public delegate void ScheduleCallback(int id, object state);

public interface IScheduler
{
    int Schedule(TimeSpan delay, bool repeating, ScheduleCallback callback, object state);
}
vs
code:
public interface IScheduler
{
    // let them capture their own state if they need it
    int Schedule(TimeSpan delay, bool repeating, Action<int> callback);
}
Thinking about it some more I guess they both have their uses. For instance if the Scheduler, in this case, needed to do something with the state object in the implementation. But if that were the case maybe an Action<int, object> would still be preferable? I dunno. It seemed like the trend was towards using Action and Func over bare delegates these days but I wasn't certain. Thoughts?

2nd one x1000.

I can't think of a compelling reason to use the delegate signature over Action or Func, it might as well be deprecated. Action<int,object> would be preferable to answer your first question.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Mr. Crow posted:

2nd one x1000.

I can't think of a compelling reason to use the delegate signature over Action or Func, it might as well be deprecated. Action<int,object> would be preferable to answer your first question.

If you were exposing an API and the usage wasn't clear, being able to put XML docs on the delegate signature could be beneficial. That's the only reason I can think of.

Okita
Aug 31, 2004
King of toilets.

Forgall posted:

Looks like expression is being compiled every time you call setter. I think you can make an expression that takes parameter and compile it just once.

That's a good point. For anyone interested, here's how to do this:
code:
var valueParameterExpression = Expression.Parameter(memberExpression.Type);
var compiledSetter = Expression.Lambda(Expression.Assign(memberExpression, valueParameterExpression), valueParameterExpression).Compile();
var setter = value => compiledSetter.DynamicInvoke(value);

mastersord
Feb 15, 2001

Gold Card Putty Fan Club
Member Since 2017!
Soiled Meat
I have a simple question I think.

What is the control used to do user field mapping (like in a mail merge) in a word document? I tried to google it but I keep getting stuff for word document automation.

My project is mapping excel columns to a SQL Server database, where the excel columns can vary from sheet to sheet. That control is exactly what I'm looking for.

Adbot
ADBOT LOVES YOU

aBagorn
Aug 26, 2004
So when you guys (in the last thread, or maybe it was somewhere else) said that at some point unit testing would just "click" and all of a sudden completely make sense and you will never want to code a different way again...


You guys were right. Holy poo poo. TDD is like crack. Every time another test goes green I get a little buzz.


Thanks again goons :glomp:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply