last day (14 days later) » 

1:14 PM
1
A: Static method call from generic function

Florian SchmidingerWhat you could do is instead of using static classes is use a singleton: public interface ICanLoadProject { void LoadProject(string token, string projectName); } Implementation: public class SampleProjectLoader : ICanLoadProject { private static SampleProjectLoader instance = new Samp...

 
Very interesting solution, but I'd like to avoid passing an additional parameter "ICanLoadProject loader" to the "CreateNewProject" function. Is it possible?
 
If you use an ExtensionMethod you dont.... you just call it on the instance like i did.... this will get the value of the instance you call it from... only downside is that it will have to be a static class where the method is implemented... you see the code i wrote...
it's the 'this' keyword before type and name that matters...
 
Did I understand correct, I HAVE to pass "this V" or "this ICanLoadProject" as a parameter? I can't avoid this?
 
and you could actually make another static method delegating the methodcall to LoadProject to instance.LoadProject in the ProjectLoader class... it just has to have a different name...
Nono i gave you examples of how to call it... use the last 2 implementations... then you only have one generic type to write
you dont write anything in loader ... you call the method on the instance and it gets assigned magically =)
you probably used ExtensionMethods like .Where() .Select() etc in linq
still not clear? ... parameters are (this ICanloadProject loader, string someother...) and this ICanLoadProject loader gets assinged to where you call the extension method from
 
I'm wondering is there a way NOT to pass any additional parameters to the CreateNewProject? Because if I would like to pass V param to the function I could do this in my original code above and then inside the function I could make a call like param.LoadProject()
 
1:14 PM
I fear im loosing you... you need to elaborate you mean the strings?
Hi
 
What I want to do is to make a call to static method inside some generic function. As I understand this is illigal in
C#, so I'm trying to find some
workaround
If I would like
 
Yeah i understand that
 
to move an additional parameter to the generic function
I could do this and then
I could make a call just by
 
Do the projects have a common interface?
 
param.LoadProject()
This function should be able treat two different type of "projects"
 
1:19 PM
Im not familiar with your implementation... why you have statics and all
And if you only have 2 types of projects isnt generics overkill?
 
in our project we are not using OOP, just static methods and musty-tiered architecture
but
in this specific case
I just want to avoid code duplication and using generics
 
You could have a look at the factory design pattern... now that you know the singleton pattern...
How extensive is the logic of the method?
 
I already heart about this pattern, what it do?
 
It encapsulates the creation of objects
 
hm..
 
1:24 PM
Let me give u a link
www.dofactory.com/net/design-patterns
Factory method
 
Thank you
I'll read about this pattern
 
Take also a look at the other patters... good stuff
 
yes, which patterns did you use in your work?
 
These patterns are abstract but good examples
 
yes
Thanks again
 
1:30 PM
All of them on a regular basis... i got several books too... oreilly head first is very good
Np
 

last day (14 days later) »