methods

Can I map a String to a method in java?

隐身守侯 提交于 2019-12-06 03:17:14
问题 I'm writing an expression evaluator in Java. I would like the ability to add more operators (I currently have only (, ), +, -, *, /, and ^). Currently, my code looks like this: case '+': return a+b; case '-': return a-b; case '*': return a*b; ... This works for my code because I have only a few operators. However, if I were to add more operators, the code would become cluttered. I am looking for a way to map an operator (represented by a String) to a method. For example, "ln" would be mapped

How to brings the Entity Framework Include extention method to a Generic IQueryable<TSource>

戏子无情 提交于 2019-12-06 03:08:28
问题 Here's the thing. I have an interface, and I would to put the Include extension method, who belongs to EntityFramework library, to my IRepository layer wich dont needs to knows about EntityFramework . public interface IRepository<TEntity> { IQueryable<TEntity> Entities { get; } TEntity GetById(long id); TEntity Insert(TEntity entity); void Update(TEntity entity); void Delete(TEntity entity); void Delete(long id); } So I have the extension method: public static class IncludeExtension { static

Validate class/method names with regex

喜夏-厌秋 提交于 2019-12-06 03:07:02
问题 I'm currently working on an MVC Style framework for a company and for security reasons I need to make sure that the controller / method that's passed via the Query String is valid chars to the RFC (which I can't find). I need to be able to validate / sanitize class names according to what's allowed by the PHP interpreter For Example: class SomEFunk__YClAssName extends Controller { } I need some kind of regex that will validate SomEFunk__YClAssName and sanitize it if need be! This is also the

Self closing tags in xsl method: xml

五迷三道 提交于 2019-12-06 02:56:44
I am working with a site that uses "xsl method:xml" to create html templates. However, I am running into an issue with the tag self-closing when the html page is rendered by the xsl engine. <div></div> transforms to => <div/> This problem is compounded by the fact that the method needs to stay xml, or the other components of the page will not render correctly. Any ideas on how tell xsl to make a special exception for the node <div> ? This question is similar to this question, except I want to keep the method:xml. XSLT self-closing tags issue It is not available by default with method=xml. You

Dynamically calling a dll and method with arguments

巧了我就是萌 提交于 2019-12-06 02:32:40
问题 Basically I'm trying to call a dll by name, instantiate an object, then call a method by name in that dll. I'm getting an "Exception has been thrown by the target of an invocation." during the Method.Invoke. I'm fairly sure my problem is with the typecasting of the arguments of the method. I was wondering if anyone had any input on this exception. Additionally, any suggestions on how to revise my approach are welcome. public void calldll(string dllName, string typeName, string methodName,

Getting a TypeError when method returns string

♀尐吖头ヾ 提交于 2019-12-06 02:25:38
What's is wrong with the code? Python returns TypeError when method returns class string. class window: def __init__(self, title='window'): self.title = title def title(self, title): if title: self.title = title else: return self.title window = window() window.title('changed') print(window.title()) Error: Traceback (most recent call last): File "C:/Users/Danilo/Desktop/pygtk.py", line 10, in <module> window.title('changed') TypeError: 'str' object is not callable Methods are attributes too. You cannot reuse the name title for both a method and an attribute. On your instance, you set self.title

Python: Are class attributes equivalent to local variables when inside a method?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 02:16:30
问题 In python, I know that looking up a locally scoped variable is significantly faster than looking up a global scoped variable. So: a = 4 def function() for x in range(10000): <do something with 'a'> Is slower than def function() a = 4 for x in range(10000): <do something with 'a'> So, when I look at a class definition, with an attribute and a method: class Classy(object): def __init__(self, attribute1): self.attribute1 = attribute1 self.attribute2 = 4 def method(self): for x in range(10000):

Calling method from another ViewController

半世苍凉 提交于 2019-12-06 01:43:14
问题 I have a ViewControllerA and a ViewControllerB. I want calling a method of ViewControllerA from ViewControllerB. In ViewControllerA is present a method: -(NSMutableArray*) loadData; In ViewControllerB.h: #import "ViewControllerA.h" ....... @property (nonatomic, strong) ViewControllerA * viewControllerA; @property (nonatomic, strong) NSMutableArray * mutableArray; In ViewControllerB.m: self.mutableArray =[viewControllerA loadData]; but the method is not calling. Why? Thanks in advance 回答1: You

Any good reason for Ruby to have == AND eql? ? (similarly with to_a and to_ary)

一曲冷凌霜 提交于 2019-12-06 01:33:04
I know eql? is used by Hashes to see if an object matches a key * , and you do def ==(rb) if you want to support the == operator, but there must be a good reason that Hashes don't use == instead. Why is that? When are you going to have definitions for == and eql? that are not equivalent (e.g. one is an alias to the other) ? Similarly, why have to_ary in addition to to_a? This question came up in response to an answer someone gave me on another question . * Of course, a Hash also assumes eql? == true implies that the hashes codes are equal. Also, is it basically a terribly idea to override

Ruby on Rails: Calling an instance method from another model

本小妞迷上赌 提交于 2019-12-06 01:32:57
I've got a Match model and a Team model. I want to run an instance method (written inside the Team model) after a Match has been saved. Here's what I've got. team.rb def goals_sum unless goal_count_cache goal_count = a_goals_sum + b_goals_sum update_attribute(:goal_count_cache, goal_count) end goal_count_cache end and it works. Now I need to run this whenever a match gets saved. So I tried this: match.rb after_save :Team.goals_sum after_destroy :Team.goals_sum And it doesn't work. I know I'm missing something basic, but I still can't go through with it. Any tips? You can just define a private