w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
How to use a generic type parameter as type parameter for a property declared as an interface with type constraints?
Try to add class constraint to the TItem: namespace Sample2 { public interface IInterfaceContainer<T1, T2> where T1 : T2 { } public interface IInterfaceParent { } public interface IInterfaceChild : IInterfaceParent { } public class ClassSampleDoesNotWork<TItem> where TItem : class, IInterfaceParent { IInterfaceContainer<IEnumerable<TItem>, IEnumerable<IInterfaceParent>> SomeProperty { get; set; } } } This works because variance only works for reference-types (or there is an identity conversion). It isn't known that TItem is reference type, unless you add : class. Read this article for more information. Here is a sample code to demonstrate this behavior: IEnumerable<Object> ite

Categories : C#

Argument type 'lambda expression' is not assignable to parameter type 'System.Action'
I doubt this has anything to do with mvvmcross or mvvm A quick search for this error message suggests this is more likely to be down to tooling - especially r# - eg see hits like: http://devnet.jetbrains.com/thread/292248 http://caliburn.codeplex.com/discussions/212685 http://youtrack.jetbrains.com/issue/RSRP-178647?projectKey=RSRP If you are running any extensions like r# and you remove or disable them, then this may remove the warning. If disabling them helps, then I would recommend asking the extension vendor(s) for support. If disabling them does not help, then I would recommend investigating the differences between the two projects where the problem does/doesn't occur - that will hopefully yield the answer.

Categories : C#

IntelliSense: argument of type "_TCHAR *" is incompatible with parameter of type "const char *"
Your project is configured for Unicode which means that the _TCHAR macro evaluates to wchar_t, which is a 16 bit UTF-16 data type on Windows. But the library you are calling accepts 8 bit char data. So, you will need to make both sides of the interface match. Lots of ways to do that. The obvious options are: Change your project to target ANSI (change the character set to multi byte in the VS project configuration). Convert the input argument from UTF-16 to ANSI before calling the library. It seems to me to be needlessly complex to use _TCHAR these days. That was useful when we needed to support Win9x (no Unicode support) and WinNT (supports Unicode) from a single code base. But I expect that nowadays you are targeting NT based systems and so you are safe to assume support for Unicode

Categories : Visual Studio 2010

Using a generic type argument in place of an argument of type System.Type. Is it a smell?
Methods that deal with types usually do just that: Dealing with types. IMO, Class.Method<SomeType>(); is much better than Class.Method(typeof(SomeType)); But that is a matter of opinion I guess. Consider LINQ's .OfType<T>(), for example: personlist.OfType<Employee>().Where(x => x.EmployeeStatus == "Active"); versus: personlist.OfType(typeof(Employee)).Where(x => ((Employee)x).EmployeeStatus == "Active"); which one would you prefer?

Categories : C#

Passing a class with type parameter as type parameter for generic method in Java
This is actually possible in Java, using some "tricks". Don't succumb to pressure from the C# fanatics! (j/k) The "trick" is to create a class that extends a generic type, and access the value of the type parameter of the parent class through the Type returned by .getGenericSuperclass() or .getGenericInterfaces(). This is quite cumbersome. To simplify our lives, Google has already written most of the boring part of the code for us, and made it available through Guava. Check the TypeToken class, which does exactly what you want. For example: TypeToken<List<String>> stringListTok = new TypeToken<List<String>>() {}; Then you pass around a TypeToken<T> instead of a Class<T> and that's all. It provides you with methods to do reflection on the type repre

Categories : Java

Query on Junit @parameters method's return type and the test class constructor argument type
As you suggested the values are being casted. The casting is actually done by the Java reflection API, specifically: Constructor.newInstance(Object...). If you're curious, the above method is invoked by JUnit on line 186, here (JUnit v4.11 source).

Categories : Java

Why does method type inference fail to infer a type parameter?
Your problem is caused by the fact that constraints are not considered part of the signature and are never used to make deductions during type inference. You are expecting the inference to go: TEnumerable is determined by taking the type of the first argument. TElement is determined by taking the IList<T> implementation information from TElement TProperty is determined by the type of the body of the lambda But C# never makes that second step because that requires considering information from a constraint. As you note, if you provide that information in the lambda then the compiler makes the deduction based on the formal parameter type. Fortunately your constraint is completely unnecessary. Rewrite your method to have a simpler signature that doesn't have a constraint: void Ass

Categories : C#

Generic Method Return Type as Type parameter
Is this what you are looking for? I've added an extra catch for cases where the cast isn't valid also Decimal i = stringName.ToType<Decimal>(); public static T ToType<T>(this string value) { object parsedValue = default(T); try { parsedValue = Convert.ChangeType(value, typeof(T)); } catch (InvalidCastException) { parsedValue = null; } catch (ArgumentException) { parsedValue = null; } return (T)parsedValue; } Edit a shortcut approach to fix Anton's comment if (typeof(T).IsValueType) return default(T);

Categories : C#

Comparing chars in C++ - argument of type "char" is incompatible with parameter of type "const char *
You have category as a single char and cat is an array of chars (i.e. a char *)... you probably didn't mean to compare a string with a single character

Categories : C++

Find method parameter type or parameter generic type
Please try using below code, you have to compare type and Integer.class public static void main(String[] args) throws ClassNotFoundException { Class<?> clazz = Class.forName("Test"); Class<Integer> lookingForClass = Integer.class; Method[] method = clazz.getMethods(); for (int i = 0; i < method.length; i++) { Type[] types = method[i].getParameterTypes(); for (int j = 0; j < types.length; j++) { Type type = types[j]; Class<?> result = type.getClass(); if (type instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) type; Type[] fieldArgTypes = pt.getActualTypeArgume

Categories : Java

Method with Type (x) parameter returning Type x
Assuming I've read your question correctly, all you should need is: public T GetSomething<T> { return default(T); } DateTime dt = GetSomething<DateTime>();

Categories : C#

How do I get type parameter from type with type parameter, inside scala macro?
You can use the TypeRef extractor: import reflect.runtime.universe._ // or in a macro "c.universe._" val tpe = weakTypeOf[List[Int]] // extract type parameters val TypeRef(_,_, tps) = tpe // tps has type List[Type] println(tps.head) // Int

Categories : Scala

warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘int *’
Drop the & as %d is used int Something like this:- fprintf(arq,"%d ", img->c); fprintf(arq,"%d ", img->l); and fprintf(arq,"%hhu ",img->matrizPixels[i][j]);

Categories : C

non-varargs call of varargs method with inexact argument type for last parameter;
If you want to get the constructor without parameters, you should call forName.getConstructor(new Class[]{}) instead of forName.getConstructor(null). This will get rid of your warning. So the code without warnings could look like: private final static Class[] EMPTY_PARAM = new Class[]{}; private static boolean checkImpled(Class interfaceClass, Class<?> forName) { try { if (!Modifier.isAbstract(forName.getModifiers()) && !forName.isInterface() && interfaceClass.isAssignableFrom(forName) && !interfaceClass.equals(forName) && forName.getConstructor(EMPTY_PARAM) != null) { return true; } } catch (Exception e) { // false } return false; }

Categories : Java

Get actual type of generic type argument on abstract superclass
Common way to sort this issue in a secure way is to add a constructor to store the class of the type. Example in your context: public abstract class BaseDao<T extends PersistentObject> { private Class<T> classT; BaseDao(Class<T> classT){ this.classT=classT; } protected Class<T> getClazz() { return classT; } // ... }

Categories : Java

Cant declare an instance with type parameter that is one layer off the constraint of the type parameter
Since TypedTableBase is generic, when you use it, you have to specify the actual datatype as in public class A<T> where T:DataTable { } public class B :TypedTableBase<DataRow> { } class MyClass { A<B> asdf = new A<B>(); }

Categories : C#

Invalid type argument / incompatible pointer type C
new is declared locally on the stack. It is not a pointer so you need to change userpass new; strcpy(new->user, user); strcpy(new->pass, pass); to userpass new; strcpy(new.user, user); strcpy(new.pass, pass); Depending on the implementation of List_add_tail (I can't see it in your question), this may not be the only problem. new goes out of scope after List_add_tail returns so, unless adding an item to the list takes a copy, the list will be left with a pointer to memory that is liable to be reused. If List_add_tail doesn't create a copy of the userpass* in its second argument, you should change your code to something like userpass* new = malloc(sizeof(*new)); strcpy(new->user, user); strcpy(new->pass, pass); List_add_tail(&logins, &new); (Note that in this

Categories : C

C#, instantiating a generic type - with variable type argument?
You can do it with reflection var entryType = typeof(Entry<>); Type[] typeArgs = { o.GetType() }; var genericType = entryType.MakeGenericType(typeArgs); IEntry entry = (IEntry)Activator.CreateInstance(genericType);

Categories : C#

How can I define a method with two Generic types and two type constraints?
You can define multiple where constraints on multiple generic types like: public ActionResult _Create3<T, G>(G content) where T:IMyClass, new() where G:IMyClass, new()

Categories : C#

The type 'System.Data.Spatial.DbGeography' must be a non-nullable value type in order to use it as parameter 'T'
This was the solution that I found in the end after digging a bit further in to EF6 documentation. Removing assembly references to System.Data.Entity.dll Installing the EF6 NuGet package adds the following runtime assemblies to your project: Recent builds of the EF6 NuGet package removes reference to System.Data.Entity.dll from the project. EF6 doesn’t use any code from System.Data.Entity.dll and having it referenced in your project could cause build conflicts. These conflicts can be resolved but in general you should not be using EF6 and System.Data.Entity.dll in the same application. Hope this may help anyone else who faces the same issue.

Categories : Entity Framework

Java Pass instance type of Object to generic class type parameter
No.. generic type should be known at compile time. Generics are there to catch possible runtime exceptions at compile time itself. List<Integer> list = new ArrayList<Integer>(); //..some code String s = list.get(0); // this generates compilation error because compiler knows that list is meant to store only Integer objects and assigning the value got from list to String is definitely an error. If the generic type was determined at run-time this would have been difficult.

Categories : Java

Send an html email error content type or mime type
I have tested this example in my web host and it works perfectly : <?php $from = "xxxxx@gmail.com"; $subject = "Confirm Your Email"; $message = "<html><body>"; $message .= " <center> <b>You are reiciving this email because you Signed up at Alphaladys.com</b> <br> <font color="red">Thank You, $name</font><br> <b><a href="alphaladys.com/?71860c77c6745379b0d44304d66b6a13=emailVerify&key=$key">Confirm Your Email</a></b><br> </center> <br><br>© 2013 Copyright | AlphaLadys.Com | All rights reserved. "; $message .= "</body></html>"; $headers = "From: " . $from . " "; $headers .= "Reply-To: ". $from . " "; $headers .= "MIME-Version: 1

Categories : HTML

Parameter value element [...] did not match expected type [org.hibernate.type.EnumType]
Answering my own question. So in short, what I was trying to do: Run application on WebSphere which we set up with Hibernate 3 Test application on JBOSS 7 which is strongly bound to Hibernate 4 Have the container provide the persistence Use a single Hibernate (non-JPA) construct (UserTypes) When deploying in WebSphere the UserType in the application needed to be compatible with Hibernate 3, and when testing in JBOSS it needed to be compatible with Hibernate 4. As it turns out, the UserType specification had changed just enough for it to be incompatible one way or another. (And if it hadn't it would still have been a bad idea to mix these versions, but it may have taken longer to become apparent.) This mix led to errors such as described in another question. But even with the accepted

Categories : Java

How to return correct type from generic function passed a related abstract type parameter
I am just going to reiterate my own (current) "answer" for my question, because I thought it would be interesting/instructive to allow readers to vote it up or down to generate a more direct comparison with answers provided by others. trait Context { // ... other stuff ... protected val aList: List[A] protected val bList: List[B] protected val cList: List[C] def get[R <: Referenced](ref: R#refType): Option[R] = { val result = ref match { case aRef: ARef => aList.find(_.ref == aRef) case bRef: BRef => bList.find(_.ref == bRef) case cRef: CRef => cList.find(_.ref == cRef) case _ => throw new RuntimeException("Unknown Ref type for retrieval: "+ref) } result.asInstanceOf[Option[R]] } }

Categories : Scala

Unable to cast object of type to type 'System.Data.Objects.ObjectContext
Try the link for MSDN Article below solved my problem when I was going through the same tutorial. MSDN Article! Just change SchoolContext to SchoolEntities in the method SchoolContextEntityDataSource_ContextCreating() Best regards, Adit Malik

Categories : Entity Framework

Using Many to many with ef linq expression gave me "Unable to create a constant value of type (type)"
The Entity Framework can't translate the Contains(product) to SQL code. Your problem lies here: discount.Products.Contains(product) You should search the product by it's ProductID, which should be a primitive type. This is a know issue which is documented here: Referencing Non-Scalar Variables Not Supported : Referencing a non-scalar variables, such as an entity, in a query is not supported. When such a query executes, a NotSupportedException exception is thrown with a message that states "Unable to create a constant value of type EntityType. Only primitive types ('such as Int32, String, and Guid') are supported in this context."

Categories : Entity Framework

Unable to cast object of type VB$AnonymousDelegate to type System.Func
"Function() to a Func" is not an implicit conversion precisely, but the normal assignation which Func expects (that is, a Function). You are not including the As Func(Of T, Boolean) bit in BoolFunc, what makes this function "anonymous" (you are not saying explicitly the returned type). Include this bit and it should work without any problem. That is, replace your BoolFunc with this one: Public Function BoolFunc(Of T)(ByVal bfunc As Func(Of Boolean, Boolean, Boolean), ByVal f1 As Func(Of T, Boolean), ByVal f2 As Func(Of T, Boolean)) As Func(Of T, Boolean) If f1 Is Nothing Then Return f2 If f2 Is Nothing Then Return f1 Return Function(param As T) bfunc(f1(param), f2(param)) End Function

Categories : Vb.Net

Sqlite database unable to delete objects, failing with message "Cannot store type: "
Rather than use: public int DeleteItem<T>(int id) where T : IBusinessEntity, new() { lock (locker) { #if NETFX_CORE return Delete(new T() { ID = id }); #else return Delete<T> (new T () { ID = id }); #endif } } Use this instead: public int Delete(object objectToDelete) { var map = GetMapping(objectToDelete.GetType()); var pk = map.PK; if (pk == null) { throw new NotSupportedException("Cannot delete " + map.TableName + ": it has no PK"); } var q = string.Format("delete from "{0}" where "{1}" = ?", map.TableName, pk.Name); return Execute(q, pk.GetValue(objectToDelete)); }

Categories : Sqlite

Override function parameter type with type of derived class
You can't do this directly. Think about this case: Base b; Derived d; Base& d_ref = d; d_ref.seriousMethod(b); // What happens here? At compile-time, the variable d_ref has static type Base, so according to the definition of Base, it should be able to take b as a parameter to seriousMethod. But at runtime, the dynamic type of d_ref is Derived, so it according to the definition of Derived, it can't take b as a parameter to seriousMethod. It can't convert b to Dervied since it might be a straight Base object (if Base is not abstract), or it might be some other class derived from Base that is not the same as Derived. You are correct in assuming that the only real way to go about this is the curiously-recurring template pattern, i.e. templating Base and defining Dervied as: class De

Categories : C++

Can Java infer type arguments from type parameter bounds?
Two things I've noticed: CAP#1 is not a wildcard, it is a type variable because of capture conversion. On the first step, the JLS mentions that U is the type expression while Tj is the type parameter. The JLS does not explicitly define what a type expression is, but my gut feeling is that it includes the bounds of the type parameter. If that is the case, U would be C extends Foo<A,B> and V would be CAP#1 extends Foo<CAP#2, CAP#3>. Following the type inference algorithm: V = U -> C = CAP#1 AND Foo<CAP#2, CAP#3> = Foo<A, B> You can continue to apply the type inference algorithm to the above, and you will end up with A= CAP#2 and B=CAP#3. I believe you have spotted a bug with Oracle's compiler

Categories : Java

System.ArgumentException: The table type parameter must have a valid type name
Set mapping to your type in SqlServer using TypeName property that: Gets or sets the type name for a table-valued parameter, that has to fix . p.TypeName = "dbo.MyType"; Check as well Table-Valued Parameters in .NET post

Categories : C#

What does the E2511 Type parameter 'T' must be a class type compiler error mean?
TObjectList<T> includes a generic constraint that T is a class. The type declaration is as follows: type TObjectList<T: class> = class(TList<T>) ... end; You might think that constraints are inherited, but that is not the case. And so you need to include the constraint in your class. Specify the constraint like so: type TSearchableObjectList<T: class> = class(TObjectList<T>) ... end;

Categories : Delphi

A subclass type as parameter type in superclass constructor java
Use Inheritance public interface Node{ //... } public class SimpleNode implements Node{ //... } public class ComplexNode implements Node{ //... } Then, you can add a Constructor like that: public class SimpleNode implements Node{ public SimpleNode(int numberOfNode){ //... } }

Categories : Java

C pointer "type ** name" versus "type * name[]" as argument
You are missing that the address of an array has a different type from the pointer that the plain array name becomes when used in an expression. That is: int *a1 = ...; int a2[] = { ... }; some_func(&a1); some_func(&a2); cannot be correct unless some_func() expects a void *. The first call passes an int ** — a pointer to pointer to int; the second call passes an int (*)[] — a pointer to array of int. Drop the & from the array. However, in your code, the problems are more complex. Because the function expects a nibble **, you have problems. What you should be doing is passing a nibble *: void initArr(nibble *arrLoc, unsigned int size) { for (unsigned int i = 0; i < size; i++) start[i].all = 0; } int main(void) { nibble *fourNibbles_1 = (nibble

Categories : C

%s expects type 'char *', but argument 2 has type 'int'
When you define or declare your variables in one line: char* wordHrs, wordMin, wordSec; it means what first will have type pointer to char, and others just chars. So define your variable in multiple lines, or just type asterics sign before every variable name that will be pointer: char *wordHrs, *wordMin, *wordSec; or char* wordHrs; char* wordMin; char* wordSec;

Categories : C

Generic inference of type parameter with constraint to other type parameter
You can't infer just some type parameters within a method call. Generic type inference either infers all type parameters, or none. There's no way of inferring THost from the parameters (there could be multiple classes which derive from HostBase<Config>), which means you basically can't use type inference for that method. Looking at this specific example, I think you're going to find it tricky to use type inference at all, because of the way the relationships work.

Categories : C#

Unable to cast object of type 'System.Web.Security.SqlRoleProvider' to type 'WebMatrix.WebData.SimpleRoleProvider'
That's because SqlRoleProvider does not inherit SimpleRoleProvider. However, you can try using SimpleRoleProvider Constructor (RoleProvider): var roles = new SimpleRoleProvider(Roles.Provider);

Categories : Sql Server

How to not specify the type argument in a generic method when the required argument is null?
I don't think you can. For a generic function you either have to specify the generic parameter or you have to pass something that it can infer the generic parameter from. To get around it you could write a non-generic wrapper.

Categories : C#

Using emitted type as type parameter in Reflection.Emit
You can set the parent type using SetParent: TypeBuilder tb = mb.DefineType("TestAdmin", TypeAttributes.Public); tb.SetParent(typeof(TestUserBase<>).MakeGenericType(tb)); Type theType = tb.CreateType();

Categories : C#

Java type parameter is hiding a generic type?
Try this: public abstract class BaseWidgetProcessor<COMMAND> { protected Widget<COMMAND> widget; public BaseWidgetProcessor(Widget<COMMAND> widget) { this.widget = widget; } // presumably uses widget public abstract COMMAND process(); }

Categories : Java



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.