Search Results

Search found 8286 results on 332 pages for 'defined'.

Page 49/332 | < Previous Page | 45 46 47 48 49 50 51 52 53 54 55 56  | Next Page >

  • Define a class dynamically?

    - by Pekka
    Is there a way to dynamically and conditionally create a class definition in PHP, i.e. if (condition matches) include file containing class definition else class myclass extends ancestor_class { .................... } without eval()? My background is the accepted answer to this question. I am looking for the best way to build a untouchable core library, with user-defined empty classes extending the core library if necessary. I want to create the final class definition "on the fly" if there is no user-defined empty class for a certain ancestor class.

    Read the article

  • Collectable<T> serialization, Root Namespaces on T in .xml files.

    - by Stacey
    I have a Repository Class with the following method... public T Single<T>(Predicate<T> expression) { using (var list = (Models.Collectable<T>)System.Xml.Serializer.Deserialize(typeof(Models.Collectable<T>), FileName)) { return list.Find(expression); } } Where Collectable is defined.. [Serializable] public class Collectable<T> : List<T>, IDisposable { public Collectable() { } public void Dispose() { } } And an Item that uses it is defined.. [Serializable] [System.Xml.Serialization.XmlRoot("Titles")] public partial class Titles : Collectable<Title> { } The problem is when I call the method, it expects "Collectable" to be the XmlRoot, but the XmlRoot is "Titles" (all of object Title). I have several classes that are collected in .xml files like this, but it seems pointless to rewrite the basic methods for loading each up when the generic accessors do it - but how can I enforce the proper root name for each file without hard coding methods for each one? The [System.Xml.Serialization.XmlRoot] seems to be ignored.

    Read the article

  • Creating controls in ASP with dynamic IDs

    - by mattdell
    Hi, I'm creating a chat widget that will be dropped into CommunityServer. The widget works great, but I just discovered that if I drop two of these widgets onto the same page, only one of them works! And I'm quite certain the reason is because the chat window is defined in ASP, and now there are two instances of the chat window, with the same ID, on the same page. I am doing this with straight ASP & Javascript (not by choice), so my chat window is defined as: <telerik:RadListBox ID="rlbMessages" runat="server" > (don't mind that it's a telerik control). So I was hoping I could do something like this: <telerik:RadListBox ID="<%= 'rlbMessages' + chatRoomID %>" runat="server" > But from what I've gathered, apparently you can't assign ID's this way? What is the alternative?

    Read the article

  • ZF-Autoloader not working in UnitTests on Ubuntu

    - by Sam
    i got a problem regarding Unit-testing a Zend-Framework application under Ubuntu 12.04. The project-structure is a default zend application whereas the models are defined as the following ./application ./models ./DbTable ./ProjectStatus.php (Application_Model_DbTable_ProjectStatus) ./Mappers ./ProjectStatus.php (Application_Model_Mapper_ProjectStatus) ./ProjectStatus.php (Application_Model_ProjectStatus) The Problem here is with the Zend-specific autoloading. The naming convention here appears that the folder Mappers loads all classes with _Mapper but not _Mappers. This is some internal Zend behavior which is fine so far. On my windows machine the phpunit runs without any Problems, trying to initiate all those classes. On my Ubuntu machine however with jenkins running on it, phpunit fails to find the appropriate classes giving me the following error Fatal error: Class 'Application_Model_Mapper_ProjectStatus' not found in /var/lib/jenkins/jobs/PAM/workspace/tests/application/models/Mapper/ProjectStatusTest.php on line 39 The error appears to really be that the Zend-Autoloader doesn't load from the ubuntu machine, but i can't figure out how or why this works. The question remains of why this is. I think i've double checked every point of contact with the zend autoloading stuff, but i just can't figure this out. I'll paste the - from my point of view relevant snippets - and hope someone of you has any insight to this. Jenkins Snippet for PHPUnit <target name="phpunit" description="Run unit tests with PHPUnit"> <exec executable="phpunit" failonerror="true"> <arg line="--configuration '${basedir}/tests/phpunit.xml' --coverage-clover '${basedir}/build/logs/clover.xml' --coverage-html '${basedir}/build/coverage/.' --log-junit '${basedir}/build/logs/junit.xml'" /> </exec> </target> ./tests/phpunit.xml <phpunit bootstrap="./bootstrap.php"> ... this shouldn't be of relevance ... </phpunit> ./tests/bootstrap.php <?php // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path(), ))); require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); Any help will be appreciated.

    Read the article

  • Named keywords in decorators?

    - by wheaties
    I've been playing around in depth with attempting to write my own version of a memoizing decorator before I go looking at other people's code. It's more of an exercise in fun, honestly. However, in the course of playing around I've found I can't do something I want with decorators. def addValue( func, val ): def add( x ): return func( x ) + val return add @addValue( val=4 ) def computeSomething( x ): #function gets defined If I want to do that I have to do this: def addTwo( func ): return addValue( func, 2 ) @addTwo def computeSomething( x ): #function gets defined Why can't I use keyword arguments with decorators in this manner? What am I doing wrong and can you show me how I should be doing it?

    Read the article

  • Question about variable definitions in functions.

    - by Kaan Tekelioglu
    Hi. #include <stdio.h> main() { int a; for(a=1; a<=4 && printf("%d ",a); a++) { int a; static int b=a; printf("%d ",(a++)-b); } getchar(); getchar(); } In this code, the printout is 1 0 2 1 3 2 4 3. I understand why the int a; part works differently then the int a which was defined outside the for function, and why static int b; is only defined once with the primary value of a ; but why does the (a++) part in printf affect proceeding values of a? Don't we redefine int a; each time the for function runs? Thanks in advance.

    Read the article

  • MooTools Problem in IE with Request

    - by trobrock
    I have this class method in a mootools class: getData : function(){ var r = new Request.JSON({ url : this.container.getAttribute('data-url'), method : 'post', onSuccess : function(j){ this.cards = j; this.prepareQuiz(); }.bind(this) }).send(); }, In any browser aside from IE this works fine, but in IE I get a this.cards is not defined in a method that occurs after the this.prepareQuiz method does it's stuff. I narrowed the problem to this section by adding an if ($defined(this.cards)) before the this.prepareQuiz call and if I just keep refreshing the page 1 out of every 5 or so times it will work. So the this.cards variable is not being set some of the time for some reason. Why would this happen?

    Read the article

  • How to setup Expression Blend 3 add-in window at certain position ?

    - by j23tom..pl
    For example in Sketchflow add-in there is ApplicationFlowPane (derrived from PrototypingPane) which registers itself using IWindowService like this: service.RegisterPalette(this.PaletteRegistryName, this, this.Caption, this.KeyBinding); But i can't see where it is defined that it is docked on bottom pane. Before someone replies that it's at: %AppData%\Microsoft\Expression\Blend3\Workspaces No it's not there because those files do not exists at first run. The question is how can i put my window at certain position with Expression Blend 3 plug-in api ? update 1: It seems that to achive what i want i have to change design.xaml (where workspaces are defined) which is loaded from satellite assembly Microsoft.Expression.Blend.resources.dll (method load in class FrameworkPackage in Microsoft.Expression.Blend.dll). But since this dll is strongly named i can't change it. So now the question is. Is there any other way I can change Design Workspace at runtime ?

    Read the article

  • Nagios plugin script not working as expected

    - by Linker3000
    I have modified an off-the-shelf Nagios plugin perl script to (in theory) return a one or zero according to the existence, or not, of a file on a remote linux server. The script runs a remote ssh session and logs in as the nagios user. The remote linux servers have private keys setup for that user, and on the bash command line the script works as expected, but when run as a plugin it always returns '1' (true) even if the file does not exist. Some help with the logic or a comment on why things are not working as expected within Nagios would be appreciated. I'd prefer to use this ssh login method rather than having to install nrpe on all the linux servers. To run from a command line (assuming remote server has a user called nagios with a valid private key): ./check_reboot_required -e ssh -H remote-servers-ip-addr -p 'filename-to-check' -v Ta. #! /usr/bin/perl -w # # # License Information: # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ############################################################################ use POSIX; use strict; use Getopt::Long; use lib "/usr/lib/nagios/plugins" ; use vars qw($host $opt_V $opt_h $opt_v $verbose $PROGNAME $pattern $opt_p $mmin $opt_e $opt_t $opt_H $status $state $msg $msg_q $MAILQ $SHELL $device $used $avail $percent $fs $blocks $CMD $RMTOS); use utils qw(%ERRORS &print_revision &support &usage ); sub print_help (); sub print_usage (); sub process_arguments (); $ENV{'PATH'}=''; $ENV{'BASH_ENV'}=''; $ENV{'ENV'}=''; $PROGNAME = "check_reboot_required"; Getopt::Long::Configure('bundling'); $status = process_arguments(); if ($status){ print "ERROR: processing arguments\n"; exit $ERRORS{'UNKNOWN'}; } $SIG{'ALRM'} = sub { print ("ERROR: timed out waiting for $CMD on $host\n"); exit $ERRORS{'WARNING'}; }; $host = $opt_H; $pattern = $opt_p; print "Pattern >" . $pattern . "< " if $verbose; alarm($opt_t); #$CMD = "/usr/bin/find " . $pattern . " -type f 2>/dev/null| /usr/bin/wc -l"; $CMD = "[ -f " . $pattern . " ] && echo 1 || echo 0"; alarm($opt_t); ## get cmd output from remote system if (! open (OUTPUT, "$SHELL $host $CMD|" ) ) { print "ERROR: could not open $CMD on $host\n"; exit $ERRORS{'UNKNOWN'}; } my $perfdata = ""; my $state = "3"; my $msg = "Indeterminate result"; # only first line is relevant in this iteration. while (<OUTPUT>) { my $result = chomp($_); $msg = $result; print "Shell returned >" . $result . "< length is " . length($result) . " " if $verbose; if ( $result == 1 ) { $msg = "Reboot required (NB: Result still not accurate)" . $result ; $state = $ERRORS{'WARNING'}; last; } elsif ( $result == 0 ) { $msg = "No reboot required (NB: Result still not accurate) " . $result ; $state = $ERRORS{'OK'}; last; } else { $msg = "Output received, but it was neither a 1 nor a 0" ; last; } } close (OUTPUT); print "$msg | $perfdata\n"; exit $state; ##################################### #### subs sub process_arguments(){ GetOptions ("V" => \$opt_V, "version" => \$opt_V, "v" => \$opt_v, "verbose" => \$opt_v, "h" => \$opt_h, "help" => \$opt_h, "e=s" => \$opt_e, "shell=s" => \$opt_e, "p=s" => \$opt_p, "pattern=s" => \$opt_p, "t=i" => \$opt_t, "timeout=i" => \$opt_t, "H=s" => \$opt_H, "hostname=s" => \$opt_H ); if ($opt_V) { print_revision($PROGNAME,'$Revision: 1.0 $ '); exit $ERRORS{'OK'}; } if ($opt_h) { print_help(); exit $ERRORS{'OK'}; } if (defined $opt_v ){ $verbose = $opt_v; } if (defined $opt_e ){ if ( $opt_e eq "ssh" ) { if (-x "/usr/local/bin/ssh") { $SHELL = "/usr/local/bin/ssh"; } elsif ( -x "/usr/bin/ssh" ) { $SHELL = "/usr/bin/ssh"; } else { print_usage(); exit $ERRORS{'UNKNOWN'}; } } elsif ( $opt_e eq "rsh" ) { $SHELL = "/usr/bin/rsh"; } else { print_usage(); exit $ERRORS{'UNKNOWN'}; } } else { print_usage(); exit $ERRORS{'UNKNOWN'}; } unless (defined $opt_t) { $opt_t = $utils::TIMEOUT ; # default timeout } unless (defined $opt_H) { print_usage(); exit $ERRORS{'UNKNOWN'}; } return $ERRORS{'OK'}; } sub print_usage () { print "Usage: $PROGNAME -e <shell> -H <hostname> -p <directory/file pattern> [-t <timeout>] [-v verbose]\n"; } sub print_help () { print_revision($PROGNAME,'$Revision: 0.1 $'); print "\n"; print_usage(); print "\n"; print " Checks for the presence of a 'reboot-required' file on a remote host via SSH or RSH\n"; print "-e (--shell) = ssh or rsh (required)\n"; print "-H (--hostname) = remote server name (required)"; print "-p (--pattern) = File pattern for find command (default = /var/run/reboot-required)\n"; print "-t (--timeout) = Plugin timeout in seconds (default = $utils::TIMEOUT)\n"; print "-h (--help)\n"; print "-V (--version)\n"; print "-v (--verbose) = debugging output\n"; print "\n\n"; support(); }

    Read the article

  • Fastest/One-liner way to list attr_accessors in Ruby?

    - by viatropos
    What's the shortest, one-liner way to list all methods defined with attr_accessor? I would like to make it so, if I have a class MyBaseClass, anything that extends that, I can get the attr_accessor's defined in the subclasses. Something like this: class MyBaseClass < Hash def attributes # ?? end end class SubClass < MyBaseClass attr_accessor :id, :title, :body end puts SubClass.new.attributes.inspect #=> [id, title, body] What about to display just the attr_reader and attr_writer definitions?

    Read the article

  • Best way to map/join two autogenerated enums

    - by tomlip
    What is the best C++ (not C++11) way of joining two enums from autogenerated class similar to one presented below: namespace A { namespace B { ... class CarInfo { enum State { // basically same enums defined in different classes Running, Stopped, Broken } } class BikeInfo { enum State { // basically same enums defined in different classes Running, Stopped, Broken } } } } What is needed is unified enum State for both classes that is seen to outside world alongside with safe type conversion. The best and probably most straightforward way I came up with is to create external enum: enum State { Running, Stopped, Broken } together with conversion functions State stateEnumConv(A::B::CarInfo::State aState); State stateEnumConv(A::B::BikeInfo::State aState); A::B::CarInfo::State stateEnumConv(State aState); A::B::BikeInfo::State stateEnumConv(State aState); Direction into right approach is needed. Gosh coming from C I hate those long namespaces everywhere an I wish it could be only A::B level like in presented example. Four conversion functions seem redundant note that CarInfo::State and BikeInfo::State has same enum "members".

    Read the article

  • With javascript, is it possible to define a variable's name with another string value?

    - by Joren
    Example, I have an array called 'categories' with the value ['4','9']. I'm trying to use that value with the name of a previously defined array. I have several arrays defined earlier called row1, row2, row3 etc. I'm also using jQuery. Trying to do something like this: for (i=0; i<categories.length; i++) { row+categories[i].push($(this).attr('id')); console.log(row+categories[i]); } Obviously row+categories[i] doesn't work, but maybe gives you an idea of what I'm trying to do? In this case to push that id value onto the array 'row4' the first time it loops through and then 'row9' the second time. Thanks for your help!!

    Read the article

  • Abstract Classes and ReadOnly Properties

    - by serhio
    Let's have three classes; Line PoliLine SuperPoliLine for all that three classes a Distance is defined. But only for the Line a Distance can be Set. Is there a possibility to build a common abstract (MustInherit) class Segment, having a Distance as (abstract +? ReadOnly) member? Question for VB.NET, but C# answers welcomed too. Business Background Imagine a Bus. It has a lot of Stations, MainStations, and 2 TerminalStations. So Line is between 2 Stations, PoliLine is between 2 MainStations, and SuperPoliLine is between 2 TerminalStations. All "lines" are "Segments", but only the distance A-B between 2 stations - Line can be defined.

    Read the article

  • A basic animation not showing up

    - by Rilakkuma
    I still try different basics with android, and now I'm stuck with animation. I'm trying to implement a simple animation. I've defined animation in xml file like this: alpha android:interpolator="@android:anim/accelerate_interpolator" android:fromAlpha="0.0" android:toAlpha="1.0" duration="3000" repeatCount="infinite" In my main view group I have an ImageView defined like this: <ImageView android:id="@+id/someb" android:src="@drawable/earth_normal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dip"/> And this is from my starting activity class: public class Ohayou extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView earth = (ImageView)findViewById(R.id.someb); Animation earthFadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_in); earth.startAnimation(earthFadeInAnimation); } It finds ImageView successfuly and creates animation. but when I start emulator ImageView just shows the original src image, not an animation. What am I doing wrong? Thanks

    Read the article

  • Is it possible to override a property and return a derived type in VB.NET?

    - by Casey
    Consider the following classes representing an Ordering system: Public Class OrderBase Public MustOverride Property OrderItem() as OrderItemBase End Class Public Class OrderItemBase End Class Now, suppose we want to extend these classes to a more specific set of order classes, keeping the aggregate nature of OrderBase: Public Class WebOrder Inherits OrderBase Public Overrides Property OrderItem() as WebOrderItem End Property End Class Public Class WebOrderItem Inherits OrderItemBase End Class The Overriden property in the WebOrder class will cause an error stating that the return type is different from that defined in OrderBase... however, the return type is a subclass of the type defined in OrderBase. Why won't VB allow this?

    Read the article

  • maven: multi module HAR dependencies

    - by QuanNH
    I have a multiple module project The first module contains my hibernate xml files and data java beans and packages as har. The second module defines my DAO classes. This module has a dependancy on data java beans with in the har and is defined in pom.xml. <dependency> <groupId>myproject</groupId> <artifactId>myhar</artifactId> <version>1.0</version> <type>har</type> </dependency> The first module compiles, packages and installs fine into my local repository. The problem is when the second modules compiles it has a problem finding the packages and class defined in my har module. I get the following output from running mvn install package myproject.myhar does not exist and build fails.

    Read the article

  • How can my application submit salesforce case with custom fields?

    - by Aaron
    I have an application that submits bugs for multiple customers to multiple destinations. I would like this application to include salesforce as a destination. I have web reference to the Enterprise WSDL and I am able to create cases for salesforce. This works great until I want to include user defined custom fields as part of the case. The custom fields are strongly typed with a __c prefix for my instance of salseforce. But I will not have the liberty of updating my web service with my customers instance of salesforce. How can I submit a salesforce case with custom fields that are not defined in the WSDL? Should I not be using the Enterprise WSDL?

    Read the article

  • string s; &s+1; Legal? UB?

    - by John Dibling
    Consider the following code: #include <cstdlib> #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { string myAry[] = { "Mary", "had", "a", "Little", "Lamb" }; const size_t numStrs = sizeof(myStr)/sizeof(myAry[0]); vector<string> myVec(&myAry[0], &myAry[numStrs]); copy( myVec.begin(), myVec.end(), ostream_iterator<string>(cout, " ")); return 0; } Of interest here is &myAry[numStrs]: numStrs is equal to 5, so &myAry[numStrs] points to something that doesn't exist; the sixth element in the array. There is another example of this in the above code: myVec.end(), which points to one-past-the-end of the vector myVec. It's perfecly legal to take the address of this element that doesn't exist. We know the size of string, so we know where the address of the 6th element of a C-style array of strings must point to. So long as we only evaluate this pointer and never dereference it, we're fine. We can even compare it to other pointers for equality. The STL does this all the time in algorithms that act on a range of iterators. The end() iterator points past the end, and the loops keep looping while a counter != end(). So now consider this: #include <cstdlib> #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { string myStr = "Mary"; string* myPtr = &myStr; vector<string> myVec2(myPtr, &myPtr[1]); copy( myVec2.begin(), myVec2.end(), ostream_iterator<string>(cout, " ")); return 0; } Is this code legal and well-defined? It is legal and well-defined to take the address of an array element past the end, as in &myAry[numStrs], so should it be legal and well-defined to pretend that myPtr is also an array?

    Read the article

  • WiX - How do I prevent ComPlusAssembly being unregistered during uninstall?

    - by Duncan Watts
    As part of my Installer, I am adding files to an existing COM+ package. I have defined a ComPlusApplication underneath my Product element, which has the name set to a property - I then have a custom action which looks up that property - all good so far. When the installer adds the files, within the same component I have added a ComPlusAssembly which adds the assembly to the ComPlusApplication I defined above - this is also working correctly. When uninstalled however, I am receiving an error related to being unable to find the COM+ application, this is because I am not running my custom action to look up the name of the COM+ package. Basically I do not want to remove my files or unregister the component package as part of the uninstallation process - How do I achieve this? I am using WiX 3.0 with VS2008. Thanks

    Read the article

  • Matlab - Propagate unit vectors on to the edge of shape boundaries

    - by Graham
    Hi I have a set of unit vectors which I want to propagate on to the edge of shape boundary defined by a binary image. The shape boundary is defined by a 1px wide white edge. I also have the coordinates of these points stored in a 2 row by n column matrix. The shape forms a concave boundary with no holes within itself made of around 2500 points. What would be the best method to do this? Are there some sort of ray tracing algorithms that could be used? Or would it be a case of taking the unit vector and multiplying it by a scalar and testing after multiplication if the end point of the vector is outside the shape boundary. When the end point of the unit vector is outside the shape, just find the point of intersection? Thank you very much in advance for any help!

    Read the article

  • How do I scope variables properly in jQuery?

    - by safetycopy
    I'm working on a jQuery plugin, but am having some trouble getting my variables properly scoped. Here's an example from my code: (function($) { $.fn.ksana = function(userOptions) { var o = $.extend({}, $.fn.ksana.defaultOptions, userOptions); return this.each(function() { alert(rotate()); // o is not defined }); }; function rotate() { return Math.round(o.negRot + (Math.random() * (o.posRot - o.negRot))); }; $.fn.ksana.defaultOptions = { negRot: -20, posRot: 20 }; })(jQuery); I'm trying to get the private function rotate to be able to see the o variable, but it just keeps alerting 'o is not defined'. I'm not sure what I'm doing wrong.

    Read the article

  • app.config and 64-bit machines

    - by Dale Lutes
    I have an app that works fine on 32-bit systems, but fails on XP 64 bit systems. I've tracked it down to the connection string defined in my app.config thus: <connectionStrings> <clear/> <add name="IFDSConnectionString" connectionString="Data Source=fdsdata;Initial Catalog=IFDS; Trusted_Connection=true;Connect Timeout=0" providerName="System.Data.SqlClient" /> </connectionStrings> When I try to reference it in code, I find that the ConfigurationManager.ConnectionStrings collection only contains the LocalSqlServer connection string from the machine.config file and not my custom string. Another oddity is that it works fine when I run the app out of Visual Studio. It is only when I run out of the release folder that the connection string does not get defined. The application's .exe.config file is there in the release folder along with the .exe file and is up to date.

    Read the article

  • Grails - Need to restrict fetched rows based on condition on join table

    - by sector7
    Hi guys, I have these two domains Car and Driver which have many-to-many relationship. This association is defined in table tblCarsDrivers which has, not surprisingly, primary keys of both the tables BUT additionally also has a new boolean field deleted. Herein lies the problem. When I find/get query on domain Car, I am fetched all related drivers irrespective of their deleted status in tblCarsDrivers, which is expected. I need to put a clause/constraint to exclude the deleted drivers from the list of fetched records. PS: I tried using an association domain CarDriver in joinTable name but that seems not to work. Apparently it expects only table names, not maps. PPS: I know its unnatural to have any other fields besides the mapping keys in mapping table but this is how I got it and it cant be changed. Car domain is defined as such - class Car { Integer id String name static hasMany = [drivers:Driver] static mapping = { table 'tblCars' version false drivers joinTable:[name: 'tblCarsDrivers',column:'driverid',key:'carid'] } } Thanks!

    Read the article

  • Scala :: operator, how it works?

    - by Felix
    Hello Guys, in Scala, I can make a caseclass case class Foo(x:Int) and then put it in a list like so: List(Foo(42)) Now, nothing strange here. The following is strange to me. The operator :: is a function on a list, right? With any function with 1 argument in Scala, I can call it with infix notation. An example is 1 + 2 is a function (+) on the object Int. The class Foo I just defined does not have the :: operator, so how is the following possible: Foo(40) :: List(Foo(2)) ? In scala 2.8 rc1, I get the following output from the interactive prompt: scala> case class Foo(x:Int) defined class Foo scala> Foo(40) :: List(Foo(2)) res2: List[Foo] = List(Foo(40), Foo(2)) scala> I can go on and use it, but if someone can explain it I will be glad :)

    Read the article

  • Type casting Collections using Conversion Operators

    - by Vyas Bharghava
    The below code gives me User-defined conversion must convert to or from enclosing type, while snippet #2 doesn't... It seems that a user-defined conversion routine must convert to or from the class that contains the routine. What are my alternatives? Explicit operator as extension method? Anything else? public static explicit operator ObservableCollection<ViewModel>(ObservableCollection<Model> modelCollection) { var viewModelCollection = new ObservableCollection<ViewModel>(); foreach (var model in modelCollection) { viewModelCollection.Add(new ViewModel() { Model = model }); } return viewModelCollection; } Snippet #2 public static explicit operator ViewModel(Model model) { return new ViewModel() {Model = model}; } Thanks in advance!

    Read the article

< Previous Page | 45 46 47 48 49 50 51 52 53 54 55 56  | Next Page >