Search Results

Search found 2521 results on 101 pages for 'typed constants'.

Page 9/101 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Spark view engine and ASP.NET MVC 2 strongly Typed Html Helpers

    - by dekko
    Hi. I try to use HtmlHelper.TextBoxFor with spark view engine but view crashed with exception "Dynamic view compilation failed. 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'TextBoxFor' and no extension method 'TextBoxFor' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)". It is my _global.spark: <use namespace="System"/> <use namespace="System.Linq"/> <use namespace="System.Text" /> <use namespace="System.Web.Mvc"/> <use namespace="System.Web.Mvc.Html"/> <use namespace="System.Web.Routing"/> <use namespace="System.Linq.Expressions" /> <use namespace="MyModels" /> In spark-view using: ${Html.TextBoxFor(m = m.UserName)}

    Read the article

  • WPF RichTextBox - Formatting of typed text

    - by Alan Spark
    I am applying formatting to selected tokens in a WPF RichTextBox. To do this I get a TextRange that encompasses the token that I would like to highlight. I will then change the color of the text like this: textRange.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Blue); This is happening on the TextChanged event of my RichTextBox. The formatting is applied as expected, but continuing to type text will result in the new text inheriting the formatting that has already been applied to the adjacent word. I would like the formatting of any new text to use the default formatting options defined in the RichTextBox properties. Is this possible? Alternatively I could highlight all tokens that I don't want be blue with the default formatting options but this feels awkward to me.

    Read the article

  • Getting template metaprogramming compile-time constants at runtime

    - by GMan - Save the Unicorns
    Background Consider the following: template <unsigned N> struct Fibonacci { enum { value = Fibonacci<N-1>::value + Fibonacci<N-2>::value }; }; template <> struct Fibonacci<1> { enum { value = 1 }; }; template <> struct Fibonacci<0> { enum { value = 0 }; }; This is a common example and we can get the value of a Fibonacci number as a compile-time constant: int main(void) { std::cout << "Fibonacci(15) = "; std::cout << Fibonacci<15>::value; std::cout << std::endl; } But you obviously cannot get the value at runtime: int main(void) { std::srand(static_cast<unsigned>(std::time(0))); // ensure the table exists up to a certain size // (even though the rest of the code won't work) static const unsigned fibbMax = 20; Fibonacci<fibbMax>::value; // get index into sequence unsigned fibb = std::rand() % fibbMax; std::cout << "Fibonacci(" << fibb << ") = "; std::cout << Fibonacci<fibb>::value; std::cout << std::endl; } Because fibb is not a compile-time constant. Question So my question is: What is the best way to peek into this table at run-time? The most obvious solution (and "solution" should be taken lightly), is to have a large switch statement: unsigned fibonacci(unsigned index) { switch (index) { case 0: return Fibonacci<0>::value; case 1: return Fibonacci<1>::value; case 2: return Fibonacci<2>::value; . . . case 20: return Fibonacci<20>::value; default: return fibonacci(index - 1) + fibonacci(index - 2); } } int main(void) { std::srand(static_cast<unsigned>(std::time(0))); static const unsigned fibbMax = 20; // get index into sequence unsigned fibb = std::rand() % fibbMax; std::cout << "Fibonacci(" << fibb << ") = "; std::cout << fibonacci(fibb); std::cout << std::endl; } But now the size of the table is very hard coded and it wouldn't be easy to expand it to say, 40. The only one I came up with that has a similiar method of query is this: template <int TableSize = 40> class FibonacciTable { public: enum { max = TableSize }; static unsigned get(unsigned index) { if (index == TableSize) { return Fibonacci<TableSize>::value; } else { // too far, pass downwards return FibonacciTable<TableSize - 1>::get(index); } } }; template <> class FibonacciTable<0> { public: enum { max = 0 }; static unsigned get(unsigned) { // doesn't matter, no where else to go. // must be 0, or the original value was // not in table return 0; } }; int main(void) { std::srand(static_cast<unsigned>(std::time(0))); // get index into sequence unsigned fibb = std::rand() % FibonacciTable<>::max; std::cout << "Fibonacci(" << fibb << ") = "; std::cout << FibonacciTable<>::get(fibb); std::cout << std::endl; } Which seems to work great. The only two problems I see are: Potentially large call stack, since calculating Fibonacci<2 requires we go through TableMax all the way to 2, and: If the value is outside of the table, it returns zero as opposed to calculating it. So is there something I am missing? It seems there should be a better way to pick out these values at runtime. A template metaprogramming version of a switch statement perhaps, that generates a switch statement up to a certain number? Thanks in advance.

    Read the article

  • Using string constants in implicit conversion

    - by kornelijepetak
    Consider the following code: public class TextType { public TextType(String text) { underlyingString = text; } public static implicit operator String(TextType text) { return text.underlyingString; } private String underlyingString; } TextType text = new TextType("Something"); String str = text; // This is OK. But I want to be able do the following, if possible. TextType textFromStringConstant = "SomeOtherText"; I can't extend the String class with the TextType implicit operator overload, but is there any way to assign a literal string to another class (which is handled by a method or something)? String is a reference type so when they developed C# they obviously had to use some way to get a string literal to the class. I just hope it's not hardcoded into the language.

    Read the article

  • How to declare NSString constants for passing to NSNotificationCenter

    - by synic
    I've got the following in my .h file: #ifndef _BALANCE_NOTIFICATION #define _BALANCE NOTIFICATION const NSString *BalanceUpdateNotification #endif and the following in my .m file: const NSString *BalanceUpdateNotification = @"BalanceUpdateNotification"; I'm using this with the following codes: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateBalance:) name:BalanceUpdateNotification object:nil]; and [[NSNotificatoinCenter defaultCenter] postNotificationName:BalanceUpdateNotificatoin object:self userInfo:nil]; Which works, but it gives me a warning: Passing argument 1 of 'postNotificationName:object:userInfo' discards qualifiers from pointer target type So, I can cast it to (NSString *), but I'm wondering what the proper way to do this is.

    Read the article

  • Using ViewModel Pattern with MVC 2 Strongly Typed HTML Helpers

    - by Brettski
    I am working with ASP.NET MVC2 RC and can't figure out how to get the HTML helper, TextBoxfor to work with a ViewModel pattern. When used on an edit page the data is not saved when UpdateModel() is called in the controller. I have taken the following code examples from the NerdDinner application. Edit.aspx <%@ Language="C#" Inherits="System.Web.Mvc.ViewUserControl<NerdDinner.Models.DinnerFormViewModel>" %> ... <p> // This works when saving in controller (MVC 1) <label for="Title">Dinner Title:</label> <%= Html.TextBox("Title", Model.Dinner.Title) %> <%= Html.ValidationMessage("Title", "*") %> </p> <p> // This does not work when saving in the controller (MVC 2) <label for="Title">Dinner Title:</label> <%= Html.TextBoxFor(model => model.Dinner.Title) %> <%= Html.ValidationMessageFor(model=> model.Dinner.Title) %> </p> DinnerController // POST: /Dinners/Edit/5 [HttpPost, Authorize] public ActionResult Edit(int id, FormCollection collection) { Dinner dinner = dinnerRepository.GetDinner(id); if (!dinner.IsHostedBy(User.Identity.Name)) return View("InvalidOwner"); try { UpdateModel(dinner); dinnerRepository.Save(); return RedirectToAction("Details", new { id=dinner.DinnerID }); } catch { ModelState.AddModelErrors(dinner.GetRuleViolations()); return View(new DinnerFormViewModel(dinner)); } } When the original helper style is used (Http.TextBox) the UpdateModel(dinner) call works as expected and the new values are saved. When the new (MVC2) helper style is used (Http.TextBoxFor) the UpdateModel(dinner) call does not update the values. Yes, the current values are loaded into the edit page on load. Is there something else which I need to add to the controller code for it to work? The new helper works fine if I am just using a model and not a ViewModel pattern. Thank you.

    Read the article

  • How do I create a strongly typed BeginForm?

    - by itchi
    I've seen a few examples of people using this syntax for HTML.BeginForm: (Html.BeginForm<Type>(action => action.ActionName(id))) But when I try this syntax all I get is a: The non-generic method System.Web.Mvc.Html.FormExtensions.BeginForm(System.Web.Mvc.HtmlHelper)' cannot be used with type arguments What am I missing?

    Read the article

  • Dynamic Typed Table/Model in J2EE?

    - by Viele
    Hi, Usually with J2EE when we create Model, we define the fields and types of fields through XML or annotation before compilation time. Is there a way to change those in runtime? or better, is it possible to create a new Model based on the user's input during the runtime? such that the number of columns and types of fields are dynamic (determined at runtime)? Help is much appreciated. Thank you.

    Read the article

  • Static variable for communication among like-typed objects

    - by Dan Ray
    I have a method that asynchronously downloads images. If the images are related to an array of objects (a common use-case in the app I'm building), I want to cache them. The idea is, I pass in an index number (based on the indexPath.row of the table I'm making by way through), and I stash the image in a static NSMutableArray, keyed on the row of the table I'm dealing with. Thusly: @implementation ImageDownloader ... @synthesize cacheIndex; static NSMutableArray *imageCache; -(void)startDownloadWithImageView:(UIImageView *)imageView andImageURL:(NSURL *)url withCacheIndex:(NSInteger)index { self.theImageView = imageView; self.cacheIndex = index; NSLog(@"Called to download %@ for imageview %@", url, self.theImageView); if ([imageCache objectAtIndex:index]) { NSLog(@"We have this image cached--using that instead"); self.theImageView.image = [imageCache objectAtIndex:index]; return; } self.activeDownload = [NSMutableData data]; NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:url] delegate:self]; self.imageConnection = conn; [conn release]; } //build up the incoming data in self.activeDownload with calls to didReceiveData... - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"Finished downloading."); UIImage *image = [[UIImage alloc] initWithData:self.activeDownload]; self.theImageView.image = image; NSLog(@"Caching %@ for %d", self.theImageView.image, self.cacheIndex); [imageCache insertObject:image atIndex:self.cacheIndex]; NSLog(@"Cache now has %d items", [imageCache count]); [image release]; } My index is getting through okay, I can see that by my NSLog output. But even after my insertObject: atIndex: call, [imageCache count] never leaves zero. This is my first foray into static variables, so I presume I'm doing something wrong. (The above code is heavily pruned to show only the main thing of what's going on, so bear that in mind as you look at it.)

    Read the article

  • Avoiding circular project/assembly references in Visual Studio with statically typed dependency conf

    - by svnpttrssn
    First, I want to say that I am not interested in debating about any non-helpful "answers" to my question, with suggestions to putting everything in one assembly, i.e. there is no need for anyone to provide webpages such as the page titled with "Separate Assemblies != Loose Coupling". Now, my question is if it somehow (maybe with some Visual Studio configuration to allow for circular project dependencies?) is possible to use one project/assembly (I am here calling it the "ServiceLocator" assembly) for retrieving concrete implementation classes, (e.g. with StructureMap) which can be referred to from other projects, while it of course is also necessary for the the ServiceLocator itself to refer to other projects with the interfaces and the implementations ? Visual Studio project example, illustrating the kind of dependency structure I am talking about: http://img10.imageshack.us/img10/8838/testingdependencyinject.png Please note in the above picture, the problem is how to let the classes in "ApplicationLayerServiceImplementations" retrieve and instantiate classes that implement the interfaces in "DomainLayerServiceInterfaces". The goal is here to not refer directly to the classes in "DomainLayerServiceImplementations", but rather to try using the project "ServiceLocator" to retrieve such classes, but then the circular dependency problem occurrs... For example, a "UserInterfaceLayer" project/assembly might contain this kind of code: ContainerBootstrapper.BootstrapStructureMap(); // located in "ServiceLocator" project/assembly MyDomainLayerInterface myDomainLayerInterface = ObjectFactory.GetInstance<MyDomainLayerInterface>(); // refering to project/assembly "DomainLayerServiceInterfaces" myDomainLayerInterface.MyDomainLayerMethod(); MyApplicationLayerInterface myApplicationLayerInterface = ObjectFactory.GetInstance<MyApplicationLayerInterface>(); // refering to project/assembly "ApplicationLayerServiceInterfaces" myApplicationLayerInterface.MyApplicationLayerMethod(); The above code do not refer to the implementation projects/assemblies ApplicationLayerServiceImplementations and DomainLayerServiceImplementations, which contain this kind of code: public class MyApplicationLayerImplementation : MyApplicationLayerInterface and public class MyDomainLayerImplementation : MyDomainLayerInterface The "ServiceLocator" project/assembly might contain this code: using ApplicationLayerServiceImplementations; using ApplicationLayerServiceInterfaces; using DomainLayerServiceImplementations; using DomainLayerServiceInterfaces; using StructureMap; namespace ServiceLocator { public static class ContainerBootstrapper { public static void BootstrapStructureMap() { ObjectFactory.Initialize(x => { // The two interfaces and the two implementations below are located in four different Visual Studio projects x.ForRequestedType<MyDomainLayerInterface>().TheDefaultIsConcreteType<MyDomainLayerImplementation>(); x.ForRequestedType<MyApplicationLayerInterface>().TheDefaultIsConcreteType<MyApplicationLayerImplementation>(); }); } } } So far, no problem, but the problem occurs when I want to let the class "MyApplicationLayerImplementation" in the project/assembly "ApplicationLayerServiceImplementations" use the "ServiceLocator" project/assembly for retrieving an implementation of "MyDomainLayerInterface". When I try to do that, i.e. add a reference from "MyApplicationLayerImplementation" to "ServiceLocator", then Visual Studio complains about circular dependencies between projects. Is there any nice solution to this problem, which does not imply using refactoring-unfriendly string based xml-configuration which breaks whenever an interface or class or its namespace is renamed ? / Sven

    Read the article

  • Precompile Lambda Expression Tree conversions as constants?

    - by Nathan
    It is fairly common to take an Expression tree, and convert it to some other form, such as a string representation (for example this question and this question, and I suspect Linq2Sql does something similar). In many cases, perhaps even most cases, the Expression tree conversion will always be the same, i.e. if I have a function public string GenerateSomeSql(Expression<Func<TResult, TProperty>> expression) then any call with the same argument will always return the same result for example: GenerateSomeSql(x => x.Age) //suppose this will always return "select Age from Person" GenerateSomeSql(x => x.Ssn) //suppose this will always return "select Ssn from Person" So, in essence, the function call with a particular argument is really just a constant, except time is wasted at runtime re-computing it continuously. Assuming, for the sake of argument, that the conversion was sufficiently complex to cause a noticeable performance hit, is there any way to pre-compile the function call into an actual constant?

    Read the article

  • arbitrary typed data in django model

    - by Dmitry Shevchenko
    I have a model, say, Item. I want to store arbitrary amount of attributes on it, like title, description, release_date. And i want them to be not just strings but have python type, so string, boolean, datetime etc. What are my options here? EAV pattern with separate name-value table won't work because of the same DB type across all values. JSONField can probably help, but it doesn't know about datetime, for example. Also i was looking at PickeField, it fits perfectly, but i'm a bit concerned about performance.

    Read the article

  • *Best* way to forward/redirect a commonly mis-typed domain name

    - by m1755
    You own thecheesecakefactory.com and your site lives there. You know that many of your visitors will simply type cheesecakefactory.com into their browser, so you purchase that domain as well. What is the cleanest way of handling the redirection. I know GoDaddy offers a "domain forwarding" service but I am not sure if this is the "proper" way of handling it, and I don't necessarily like the idea of GoDaddy handling my DNS. My other option would be sending the domain to my DNS servers and possibly my actual server. Is it possible to do this without setting up a new vhost and a 301 redirect on my server (using DNS only)? If not, how does the GoDaddy forwarding service work?

    Read the article

  • tchar safe functions -- count parameter for UTF-8 constants

    - by Dustin Getz
    I'm porting a library from char to TCHAR. the count parameter of this fragment, according to MSDN, is the number of multibyte characters, not the number of bytes. so, did I get this right? _tcsncmp(access, TEXT("ftp"), 3); //or do i want _tcsnccmp? "Supported on Windows platforms only, _mbsncmp and _mbsnbcmp are multibyte versions of strncmp. _mbsncmp will compare at most count multibyte characters and _mbsnbcmp will compare at most count bytes. They both use the current multibyte code page. _tcsnccmp and _tcsncmp are the corresponding Generic functions for _mbsncmp and _mbsnbcmp, respectively. _tccmp is equivalent to _tcsnccmp."

    Read the article

  • Strongly Typed Controls in .NET

    - by Tigraine
    I am working on a Windows Forms app for quite some time now, and I really find myself doing more typecasts in the GUI code than I ever did in my underlying business code. What I mean becomes apparent if you watch the ComboBox control that accepts some vague "object" as it's item. Then you go off and may display some DisplayMember and a ValueMember and so on. If I want to retrieve that value later I need to typecast my object back to what it was. Like with strings getting the value takes string value = (string)combobox1.SelectedItem; Since there are generics in the Framework for quite some time now, I still wonder why in the Hell not one control from the standard toolbox is generic. I also find myself using the .Tag property on ListViewItems all the time to keep the displayed domain object. But everytime I need to access that object I then need another typecast. Why cant I just create a ComboBox or ListView with items of type ListViewItem Am I missing something here or is this just another example of not perfectly well thought through controls?

    Read the article

  • Spring - using static final fields (constants) for bean initialization

    - by lisak
    Hey, is it possible to define a bean with the use of static final fields of CoreProtocolPNames class like this: <bean id="httpParamBean" class="org.apache.http.params.HttpProtocolParamBean"> <constructor-arg ref="httpParams"/> <property name="httpElementCharset" value="CoreProtocolPNames.HTTP_ELEMENT_CHARSET" /> <property name="version" value="CoreProtocolPNames.PROTOCOL_VERSION"> </bean> public interface CoreProtocolPNames { public static final String PROTOCOL_VERSION = "http.protocol.version"; public static final String HTTP_ELEMENT_CHARSET = "http.protocol.element-charset"; } If it is possible, what is the best way of doing this ?

    Read the article

  • PHP functions wont work with String object, but works with it typed manually

    - by heldrida
    Hi, I'm trying to strip tags from a text output coming from an object. The problem is, that I can't. If I type it manually like "<p>http://www.mylink.com</p>", it works fine! When doing echo $item->text; it gives me the same string "<p>http://www.mylink.com</p>"; Doing var_dump or even gettype, gives me a string(). So, I'm sure its a string, but it's not acting like it, I tried several functions preg_replace, preg_match, strip_Tags, none worked. How can I solve this situation, how to debug it ? $search = array("<p>", "</p>"); $switch = array("foo", "baa"); //works just fine, when used $text = "<p>http://www.mylink.com</p>"; //it's a string for sure! var_dump($item->introtext); $text = $item->introtext; //doesn't work $text = str_replace($search, $switch, $text); $text = strip_tags($text, "<p>"); //doesn't work either. $matches = array(); $pattern = '/<p>(.*)<\/p>/'; preg_match($pattern, $text, $matches); //gives me the following output: <p>http://www.omeulink.com</p> echo $text;

    Read the article

  • Groovy: stub typed reference

    - by Don
    Hi, I have a Groovy class similar to class MyClass { Foo foo } Under certain circumstances I don't want to initialize foo and want to stub out all the calls to it. Any methods that return a value should do nothing. I could do it like this: Foo.metaClass.method1 = {param -> } Foo.metaClass.method2 = { -> } Foo.metaClass.method3 = {param1, param2 -> } While this will work, it has a couple of problems Tedious and long-winded, particularly if Foo has a lot of methods This will stub out calls to any instance of Foo (not just foo) Although Groovy provides a StubFor class, if I do this: this.foo = new groovy.mock.interceptor.StubFor(Foo) I get a ClassCastException at runtime. Although this would work if I could redefine foo as: def foo But for reasons I won't go into here, I can't do that. Thanks, Don

    Read the article

  • Coldfusion returning typed objects / AMF remoting

    - by Chin
    Is the same possible in ColdFusion? Currently I am using .Net/Fluorine to return objects to the client. Whilst in testing I like to pass strings representing the select statement and the custom object I wish to have returned from my service. Fluorine has a class ASObject to which you can set the var 'typeName'; which works great. I am hoping that this is possible in Coldfusion. Does anyone know whether you can set the type of the returned object in a similar way. This is especially helpful with large collections as the flash player will convert them to a local object of the same name thus saving interating over the collection to convert the objects to a particular custom object. foreach (DataRow row in ds.Tables[0].Rows) { ASObject obj = new ASObject(); foreach (DataColumn col in ds.Tables[0].Columns) { obj.Add(col.ColumnName, row[col.ColumnName]); } obj.TypeName = pObjType; al.Add(obj); } Many thanks,

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >