Extending svcutil.exe and wsdl.exe with custom methods - wsdl.exe

I really need to add some of my own convenience methods into the auto-generated proxy files that are output by wsdl.exe and svcutil.exe. What I am doing is adding another type of ***Operation***Async method for each service method. I would like to be able to invoke a tool from a command line like this:
superwsdl.exe [wsdl command-line arguments here]
supersvcutil.exe [svcutil command-line arguments here]
And have the outputted file include my extra methods. Does anyone know a way of doing this? If it has to be another format of command line, that is OK too.

I'm not sure about svcutil.exe, but wsdl.exe generates C# partial classes.
You can make another partial class with the same name and put the extra methods there.

It should be your consol application written in for eg. C#, which will take some arguments and do something like this:
...
Process svcUtil = new Process();
svcUtil.StartInfo.FileName = "svcutil.exe";
svcUtil.StartInfo.Arguments = "... some arguments here: args[0], args[1], ...";
svcUtil.Start();
...
Vedran

Related

It's correct to make a run method inside the class to start the flow of the 'program'?

I wrote this scraper script to extract the job list from a website. And then to in order to practice I decide to try to transform this script into a class object.
The correct approach is to just call the methods you need as it is below.
teste = InfoJobs.new
teste.build_url
teste.get_page_values
teste.scraping
teste.writing
but I want to know if is ok to have a run method inside of my class and use self. to make the flow of the scrape program.
def run
self.build_url
self.parsing(#url)
self.get_page_values
self.scraping
self.writing
end
teste.run
If you're asking "should I create an abstraction layer around the numerous steps required to perform the operation so that the caller doesn't need to care about the particulars" then the answer is that's fine.
I'd prefer to write code that says scraper.run than five lines of confusing boilerplate which doesn't afford me any more control than the equivalent run method does.

Is it possible to to only stub a call with specific parameters with minitest?

I have multiple calls to ::Foo.bar. I would like to stub only the call that includes a very specific parameter.
Is it possible to do : ::Foo.stubs(:bar).with(1).returns(something) and still allow ::Foo.bar(2) to call the actual method?
You can use instance_of in the parameter, if the value will be an instance of the same class.
::Foo.stubs(:bar).with(instance_of(Integer)).returns(something)
Please refer the source code of with, a block can also be passed to match your requirements.

Passing command line arguments to classes

When developing large scale command line applications that are composed of multiple classes, which need to use options passed from the command line, how do you construct the code such that you can use those options?
I write code like this:
class DatabaseHandler
def initialize(cmd_options = {})
#cmd_options = cmd_options
end
def some_method
puts #cmd_options[:cmd_parameter]
end
end
which, seems tedious and unnecessary to me. What is the Ruby best practice for using command line option parameters in your project's classes? Help appreciated.
Ruby classes are simply that: classes. Good OOD applies, even if it's a command line application. If you need custom behaviour, use dependency injection or configure it using arguments. You may share the command line options using global variables, but as always, that comes at a price: shadowing, increasing complexity to understand the collaborators of a class, difficulty finding the source of a data, etc.
I'd suggest using factory methods to parse the input and return the correct configuration to be passed to a class. If you want nice examples of dependency injection, watch some Sandi Metz talks, she really knows her stuff.
Command-line options are no different from any other kind of configuration; configuration is configuration, no matter where it came from. So, you deal with them the same way you deal with other configuration, e.g. using
a global singleton
Dependency Injection (which is what you are doing in your example)
the Reader Monad
…
For example, for request parameters (which is probably the closest analog to command-line arguments in a Web context), Rails uses a global method named params which returns a Hash-like object mapping parameter names to arguments. So, that would be an example of a global singleton.

LLDB Type Summary with properties (NSManagedObject)

After viewing the WWDC2013 LLDB Debug session, I want to add a custom type formatter for one my NSManagedObject subclasses. You can do this by typing in the debugger
type summary -add MyClass --summary-string "${var._name}"
This works but only on variables, not on methods, hence properties. I've also tried using a python script via valobj.GetChildMemberWithName without success.
How can I display a property on an NSManagedObject subclass on LLDB ?
More Info:
http://lldb.llvm.org/varformats.html
Long story short, as you realized the ${var.foo} syntax only works for ivars. Not for methods. Not for properties (which are methods, give or take syntactic sugar).
I have been thinking about a syntax to run expressions in the string summary format. It would look something like ${expr:[$var selector]} or ${expr:3+$var}
Lacking that, for now your workaround is to go to Python, and use the SBFrame.EvaluateExpression command. There are examples of Python formatters in the LLDB source code, and on the website that you can use as a starting point.

Ruby Style: should initialize take a file with data or just the raw data as parameters

I was curious if anyone had insight on what is the best way for an object to load data from a file in Ruby. Is there a convention? There are two ways I can think of accomplishing this:
Have the initialize method accept a path or file and parse the data within the initialize method, setting the object variables as well.
Have the main "runner" code open the file and parse it, then pass the correct arguments to your constructor.
I am also aware that I could support both methods through an options hash or *args and looking at its size, but I do not have any need to implement both.
I would use the second option combined with providing the path info as an argument to the main code. This makes it more portable and keeps the object de-coupled from the source of the data

Resources