Search Results

Search found 1919 results on 77 pages for 'typeof'.

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

  • Sorting Multidimensional Array with Javascript: Integers

    - by tkm256
    I have a 2D array called "results." Each "row" array in results contains both string and integer values. I'm using this script to sort the array by any "column" on an onclick event: function sort_array(results, column, direction) { var sorted_results = results.sort(value); function value(a,b) { a = a[column]; b = b[column]; return a == b ? 0 : (a < b ? -1*direction : 1*direction) } } This works fine for the columns with strings. But it treats the columns of integers like strings instead of numbers. For example, the values 15, 1000, 200, 97 would be sorted 1000, 15, 200, 97 if "ascending" or 97, 200, 15, 1000 "descending." I've double-checked the typeof the integer values, and the script knows they're numbers. How can I get it to treat them as such?

    Read the article

  • AppDomain assemblies not being loaded correctly.

    - by SharePoint Newbie
    Hi, We are doing the following in the Application_Start (Global.ascx.cs) for a WCF Service hosted by IIS 7.0 (integrated pipeline). var mapperConfigurations = AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => a.GetExportedTypes().Where(t => typeof (IMapperConfiguration).IsAssignableFrom(t) && t.IsClass)) .ToList(); The web-service has 8-10 assemblies in its bin folder and each of them have multiple implementations of IMapperConfiguration. After an IIS Reset, no mapper configurations are found (found this using debug.write). However, this behaviour is inconsistent and at other times all implementations of IMapperConfiguration are found. When exactly does IIS load assemblies and what is wrong with this code? Thanks

    Read the article

  • Receiving an Expectedmessage differs error

    - by Mark
    I am quite new to TDD and am going with NUnit and Moq. I have got a method where I expect an exception, so I wanted to play a little with the frameworks features. My test code looks as follows: [Test] [ExpectedException(ExpectedException = typeof(MockException), ExpectedMessage = "Actual differs from expected")] public void Write_MessageLogWithCategoryInfoFail() { string message = "Info Test Message"; Write_MessageLogWithCategory(message, "Info"); _LogTest.Verify(writeMessage => writeMessage.Info("This should fail"), "Actual differs from expected" ); } But I always receive the errormessage that the error message that the actual exception message differs from the expected message. What am I doing wrong?

    Read the article

  • Why does GetExportedValues<T>() no longer work after using the .net 4 final version of MEF?

    - by BigJason
    I have been developing a managed extensibility framework application for the last several months using the community preview. I have been using the GetExportedValues() method and the PartCreationPolicy(CreationPolicy.NonShared) to fake a class factory (since only the silverlight version supports a factory). This was working great until I upgraded the project to use .net 4.0. There is no error, it just doesn't work. So why did this code stop working? The code follows: The factory method: public static IEnumerable<DataActionBase> GetActionsFromDirectory(string PluginsFolder) { IEnumerable<DataActionBase> result = null; var catalog = new DirectoryCatalog(PluginsFolder); var container = new CompositionContainer(catalog: catalog); result = container.GetExportedValues<DataActionBase>(); return result; } Example Export Class: [Export(typeof(DataActionBase))] [PartCreationPolicy(CreationPolicy.NonShared)] public class AnAction : DataActionBase { .... }

    Read the article

  • Operator as and generic classes

    - by abatishchev
    I'm writing .NET On-the-Fly compiler for CLR scripting and want execution method make generic acceptable: object Execute() { return type.InvokeMember(..); } T Execute<T>() { return Execute() as T; /* doesn't work: The type parameter 'T' cannot be used with the 'as' operator because it does not have a class type constraint nor a 'class' constraint */ // also neither typeof(T) not T.GetType(), so on are possible return (T) Execute(); // ok } But I think operator as will be very useful: if result type isn't T method will return null, instead of an exception! Is it possible to do?

    Read the article

  • Define a method in base class that returns the name of itself (using reflection) - subclasses inheri

    - by Khnle
    In C#, using reflection, is it possible to define method in the base class that returns its own name (in the form of a string) and have subclasses inherit this behavior in a polymorphic way? For example: public class Base { public string getClassName() { //using reflection, but I don't want to have to type the word "Base" here. //in other words, DO NOT WANT get { return typeof(Base).FullName; } return className; //which is the string "Base" } } public class Subclass : Base { //inherits getClassName(), do not want to override } Subclass subclass = new Subclass(); string className = subclass.getClassName(); //className should be assigned "Subclass"

    Read the article

  • Why not System.Void?

    - by Stewart
    I have no practical reason for knowing this answer, but I'm curious anyway... In C#, trying to use System.Void will produce a compilation error: error CS0673: System.Void cannot be used from C# -- use typeof(void) to get the void type object As I understood it, void is simply an alias of System.Void. So, I don't understand why 'System.Void' can't be used directly as you might with 'string' for 'System.String' for example. I would love to read an explanation for this! Incidentally, System.Void can be successfully used with the Mono compiler, instead of Microsoft's .Net, and there it appears equivalent to using the void keyword. This must therefore be a compiler-enforced restriction rather than a CLR restriction, right?

    Read the article

  • Javascript looping only through defined properties of array. How?

    - by Beck
    For example if i'm keeping array of references via id like that: if(typeof channel_boards[misc.channel_id] == 'undefined') { channel_boards[misc.channel_id] = $('<div class="channel" channel_id="'+misc.channel_id+'"></div>').appendTo('#board'); } And then i'm looping through array to find required reference. I'm looping through undefined properties as well. Is it possible to loop only through defined properties? for(i=0;i<channel_boards.length;i++) { if(channel_boards[i] != undefined) { if(channel_boards[i].attr('channel_id') != visible) {channel_boards[i].addClass('hidden_board');} else {channel_boards[i].removeClass('hidden_board');} } } Maybe i should change the way i'm storing references? Via object for example, but how i'll be able to find proper reference via id number.

    Read the article

  • How to parse JSON string that can be one of two different strongly typed objects?

    - by user852194
    Background: I'm invoking a web service method which returns a JSON string. This string can be of type ASConInfo or ASErrorResponse. Question: Using the DataContractJsonSerializer, how can I convert the returned JSON string to one of those objects? Thanks in advance I have tried the following technique, but it does not work: public static object test(string inputString) { object obj = null; using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(inputString))) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(object)); obj = ser.ReadObject(ms) as object; } return obj; } [WebMethod] public string TypeChecker() { string str = "{\"Error\":191,\"ID\":\"112345678921212\",\"Length\":15}"; //string strErro = ""; object a = test(str); if (a is ASResponse) { return "ASResponse"; } if (a is ASErrorResponse) { return "ASErrorResponse"; } return "Nothing"; }

    Read the article

  • How to format complex chained Linq statements for readibility?

    - by Joan Venge
    I have some code like this: var effects = xElement.Elements ( "Effects" ).Elements ( "Effect" ).Select ( e => new Effect ( ( EffectType ) Enum.Parse ( typeof ( EffectType ), ( string ) e.Elements ( "Type" ).FirstOrDefault ( ) ), e.Elements ( "Options" ).Any ( ) ? e.Elements ( "Options" ).Select ( o => ( object ) o.Elements ( "Option" ).Select ( n => n.Value ).First ( ) ) : null ) ) .ToList ( ); But currently this doesn't look as readable and I am not sure where I should add a new line and/or indent for readability. Any suggestions I could use to make consistent, readable linq blocks?

    Read the article

  • In C#: How to declare a generic Dictionary whose key and value types have a common constraint type?

    - by Marcel
    Hi all, I want to declare a dictionary that stores typed IEnumerable's of a specific type, with that exact type as key, like so: private IDictionary<T, IEnumerable<T>> _dataOfType where T: BaseClass; //does not compile! The concrete classes I want to store, all derive from BaseClass, therefore the idea to use it as constraint. The compiler complains that it expects a semicolon after the member name. If it would work, I would expect this would make the later retrieval from the dictionary simple like: IEnumerable<ConcreteData> concreteData; _sitesOfType.TryGetValue(typeof(ConcreteType), out concreteData); How to define such a dictionary?

    Read the article

  • C# Using Reflection to Get a Generic Object's (and its Nested Objects) Properties

    - by Jimbo
    This is a scenario created to help understand what Im trying to achieve. I am trying to create a method that returns the specified property of a generic object e.g. public object getValue<TModel>(TModel item, string propertyName) where TModel : class{ PropertyInfo p = typeof(TModel).GetProperty(propertyName); return p.GetValue(item, null); } The code above works fine if you're looking for a property on the TModel item e.g. string customerName = getValue<Customer>(customer, "name"); However, if you want to find out what the customer's group's name is, it becomes a problem: e.g. string customerGroupName = getValue<Customer>(customer, "Group.name"); Hoping someone can give me some insight on this way out scenario - thanks.

    Read the article

  • Invalid parameter used when trying to save a graphic image of mms.

    - by Sheery
    Hi, I have an application build in C# using PC Suite API, when i am trying to copy mms image to my PC it gives me an error of invalid parameters, can any one help me in this matter ...my code is dataVersit = (CAContentAccess.CADataDefinitions.CA_DATA_VERSIT)Marshal.PtrToStructure(bufData, typeof(CAContentAccess.CADataDefinitions.CA_DATA_VERSIT)); byte[] bVersitObject = new byte[dataVersit.iDataLength]; Marshal.Copy(dataVersit.pbVersitObject, bVersitObject, 0 , dataVersit.iDataLength); System.IO.Stream ios = System.IO.File.Open(fileDlg.FileName, System.IO.FileMode.Create); ios.Write(bVersitObject, bVersitObject.GetLowerBound(0), dataVersit.iDataLength); ios.Flush(); ios.Close();

    Read the article

  • How to choose programaticaly the column to be querried by Linq using PropertyInfo???

    - by Richard77
    Hello, I would like to control how linq querries my database programaticaly. For instance, I'd like to querry the column X, column Y, or column Z, depending on some conditions. First of all, I've created an array of all the properties inside my class called myPropertyInfo. Type MyType = (typeOf(MyClass)); PropertyInfo[] myPropertyInfo = myType.GetProperties( BindingFlags.Public|BindingFlags.Instance); the myPropertyInfo array allows me to access each property details (Name, propertyType, etc) through the index*[i]* Now, how can I use the above information to control how linq querries my DB? Here's a sample of a querry I'd like to exploit. var myVar = from tp in db.MyClass select tp.{expression}; Expression using myPropertyInfo[i] to choose which property(column) to querry. I'm not sure if that's the way of doing it, but if there's another way to do so, I'll be glad to learn. Thanks for helping.

    Read the article

  • NHibernate: References still being eagerly selected after specifying AddJoin

    - by cbp
    I have a query which is something like this: Session.CreateSQLQuery( @"SELECT f.*, b.*, z.* FROM Foo f LEFT OUTER JOIN Bar b ON b.Id = f.BarId LEFT OUTER JOIN Zar z ON z.Id = b.ZarId" ) .AddEntity("f", typeof(Foo)) .AddJoin("b", "f.BarId") .AddJoin("z", "f.ZarId") .List<Foo>(); The problem is that I am still getting hundreds of SELECT requests made to the Zar table, even though I have specified that Zar should be joined. As far as I am aware the only relationship is Foo-Bar-Zar, i.e. the reference to Zar is not occurring anywhere else. Is my understanding of AddJoin correct? What could be going wrong? List item

    Read the article

  • Get name of property as a string

    - by Jim C
    I'm trying to improve the maintainability of some code involving reflection. The app has a .NET Remoting interface exposing (among other things) a method called Execute for accessing parts of the app not included in its published remote interface. Here is how the app designates properties (a static one in this example) which are meant to be accessible via Execute: RemoteMgr.ExposeProperty("SomeSecret", typeof(SomeClass), "SomeProperty"); So a remote user could call: string response = remoteObject.Execute("SomeSecret"); and the app would use reflection to find SomeClass.SomeProperty and return its value as a string. Unfortunately, if someone renames SomeProperty and forgets to change the 3rd parm of ExposeProperty(), it breaks this mechanism. I need to the equivalent of: SomeClass.SomeProperty.GetTheNameOfThisPropertyAsAString() to use as the 3rd parm in ExposeProperty so refactoring tools would take care of renames. Is there a way to do this? Thanks in advance.

    Read the article

  • Problem with access to file

    - by phenevo
    Hi, I have winforms application and it has reference to library MyLibrary. MyLibrary has method: string[] GiveMeNamesOfAirports() { string[] lines= File.ReadLines("airports.txt"); foreach(string line in lines) ... } And when I run my Winforms application: I get error: file couldn't be find. I was trying other function: string[] lines = File.ReadAllLines(Path.Combine(System.Environment.CurrentDirectory, "airports.txt")); string[] lines = File.ReadAllLines(Path.Combine(Assembly.GetExecutingAssembly().Location, "airports.txt")); string[] lines = File.ReadAllLines(Path.Combine(Assembly.GetAssembly(typeof(Airport)).Location, "airports.txt"));

    Read the article

  • Class decorator to declare static member (e.g., for log4net)?

    - by Ken
    I'm using log4net, and we have a lot of this in our code: public class Foo { private static readonly ILog log = LogManager.GetLogger(typeof(Foo)); .... } One downside is that it means we're pasting this 10-word section all over, and every now and then somebody forgets to change the class name. The log4net FAQ also mentions this alternative possibility, which is even more verbose: public class Foo { private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); ... } Is it possible to write a decorator to define this? I'd really like to say simply: [LogMe] // or perhaps: [LogMe("log")] public class Foo { ... } I've done similar things in other languages, but never a statically-compiled language like C#. Can I define class members from a decorator?

    Read the article

  • Checking if cookies are enabled doesn't work in IE8

    - by the_V
    Hi, I'm trying to create a script that would determine if cookies are enabled and do some work if not. This is the code I use: var cookieEnabled = (window.navigator.cookieEnabled) ? true : false; if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) { document.cookie = "testcookie" cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false } if (cookieEnabled == false) { // do some work } The problem is that in IE8 it causes nothing to happen when I set cookies to be blocked in browser options. So, navigator.cookieEnabled is always true. This stuff works perfectly in Chrome and FireFox. Am I doing anything wrong?

    Read the article

  • How do I get a Type[] with arguments from a MethodCallExpression?

    - by Tomas Lycken
    I'm reflecting over a class (in a unit test of said class) to make sure its members have all the required attributes. To do so, I've constructed a couple of helpers, that take an Expression as an argument. I do some checks for it, and take slightly different actions depending on what type of Expression it is, but it's basically the same. Now, my problem is that I have several methods with the same name (but different signatures), and the following code throws an AmbiguousMatchException: // TOnType is a type argument for the type where the method is declared // mce is the MethodCallExpression var m = typeof(TOnType).GetMethod(mce.Method.Name); Now, if I could add an array of Type[] with the types of the arguments to this method as a second parameter to .GetMethod(), the problem would be solved. But how do I find this Type[] array that I need? I have cast the Expression<Func<...>> to an Expression, and then to a MethodCallExpression, and in this method the contents of <...> is not known.

    Read the article

  • Factory Method Using Is/As Operator

    - by Swim
    I have factory that looks something like the following snippet. Foo is a wrapper class for Bar and in most cases (but not all), there is a 1:1 mapping. As a rule, Bar cannot know anything about Foo, yet Foo takes an instance of Bar. Is there a better/cleaner approach to doing this? public Foo Make( Bar obj ) { if( obj is Bar1 ) return new Foo1( obj as Bar1 ); if( obj is Bar2 ) return new Foo2( obj as Bar2 ); if( obj is Bar3 ) return new Foo3( obj as Bar3 ); if( obj is Bar4 ) return new Foo3( obj as Bar4 ); // same wrapper as Bar3 throw new ArgumentException(); } At first glance, this question might look like a duplicate (maybe it is), but I haven't seen one exactly like it. Here is one that is close, but not quite: http://stackoverflow.com/questions/242097/factory-based-on-typeof-or-is-a

    Read the article

  • Odd toString behavior in javascript

    - by George
    I have this small function that's behaving oddly to me. Easy enough to work around, but enough to pique my curiosity. function formatNumber(number,style) { if (typeof style == 'number') { style = style.toString(); } return (number).format(style); } The return format part is based on another function that requires the style variable to be a string to work properly, so I'm just checking if style is a number and if it is to convert it to a string. When the function above is written as is, the format function format doesn't work properly. However when I write it as simply: return (number).format(style.toString()); Everything works. Is there a difference between putting the .toString function inside the format call vs performing it before hand and setting it as the variable style?

    Read the article

  • Determine if FieldInfo is compiler generated backingfield

    - by Steffen
    The title pretty much says it all, how do I know if I'm getting a compiler generated backingfield for a {get; set;} property ? I'm running this code to get my FieldInfos: Class MyType { private int foo; public int bar {get; private set; } } Type type = TypeOf(MyType); foreach (FieldInfo fi in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.NonPublic)) { // Gets both foo and bar, however bar is called <bar>k__backingfield. } so the question is, can I somehow detect that the FieldInfo is a backingfield, without relying on checking its name ? (Which is pretty undocumented, and could be broken in next version of the framework)

    Read the article

  • Why can't I register a custom model binder for a List<int>?

    - by quarksoup
    I have an action that looks like public ActionResult GetUsers(List<int> userIds) {//do stuff} The list of userIds can become quite long, so I want to use Json.Net to deserialize it. To do so I created an IModelBinder implementation, which works fine for other objects, but never gets called for a List. The IModelBind looks like this public class JsonBinder : System.Web.Mvc.IModelBinder { public object BindModel(System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ModelBindingContext bindingContext) { //Do model binding stuff using Json.Net } } And I register this model binder with this line ModelBinders.Binders.Add(typeof(List<int>), new JsonBinder()); However the JsonBinder is never called. Why is this? Should I be using a ValueProvider?

    Read the article

  • WCF service code in window application

    - by Mariya
    Hello, I am using C#.net application code. I require to call service for Window Application and i am using below code to open service Host, using (ServiceHost host = new ServiceHost( typeof(class1), new Uri[] { new Uri("net.pipe://localhost") }) ) { } & Then we have clinet Console application to connect to serviceHost. Problem is, When i create service/Client application Using Conslole Application both are working fine. But if i call servide code form Window application to connect to console client it gives Error for Binding Error like("No End Point/Address found to test") Can any one help me to run service from C# window application ? Thanks

    Read the article

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