w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
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

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#

Function to accept nullable type and return nullable type or string
static string MyFunction<T>(Nullable<T> arg) where T : struct { String strNULL = "NULL"; if (arg.HasValue) return arg.Value.ToString(); else return strNULL; }

Categories : C#

Reflection check parameter value type and set value
I'm not sure if I understood correctly your question, however: var valueType = value.GetType() var fileNameProperty = valueType.GetProperty("FileName"); if(fileNameProperty != null) value = fileNameProperty.GetValue(value);

Categories : C#

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32'
You are expecting an id parameter in your URL but you aren't supplying one. Such as: http://yoursite.com/controller/edit/12 ^^ missing

Categories : C#

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#

Java Reflection: getting the type of the return parameter of a method
Your IDVariant class is of course instantiated, thats what you do with toParse.newInstance() method, but since you do not cast the instantiated object to its original class type and then initialize it, there is a big probability of exception, for example NullPointerEx.

Categories : Java

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

How to convert nullable type to its underlying type?
But it supports nullable types, AllowDbNull is true by default: var table = new DataTable(); table.Columns.Add("NullableInt", typeof(int)); table.Rows.Add(1); table.Rows.Add(2); table.Rows.Add(3); table.Rows.Add((int?)null); Use the DataRow extension methods which support nullable types, for example: foreach(DataRow row in table.Rows) { int? value = row.Field<Int32?>("NullableInt"); // modify the value with SetField: row.SetField<Int32?>("NullableInt", null); // or: row.SetField("NullableInt", (int?)null); }

Categories : Dotnet

Object of type 'System.Reflection.MdFieldInfo' cannot be converted to type 'MyEnum'
I think you need a Field.GetValue here type.GetProperty("St").SetValue(student, type3.GetField("Good").GetValue(instance), null); Type.GetField returns FieldInfo but what you actually need to pass as a parameter is enum value. Note: I assume Good is a field on type3 which is of type Enum StudentType

Categories : C#

How do I resolve the actual type for a generic return type using reflection?
At runtime, it returns Object because of type-erasure which replaces all generic types with Object. There is no way to determine at runtime what generic type was provided at compile-time. type-erasure

Categories : Java

If strings are nullable by default, why do i get Unable to cast object of type 'System.DBNull' to type 'System.String'.?
Because null != DBNull.Value. But you can check if it the value in the DataReader is null with the IsDbNull method: DestributionGroup = dr.IsDbNull("Destribution Group") ? "" : dr.GetString("Destribution Group");

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

the built-in type bool in C++ or the stdbool.h type in C defines TRUE and FALSE as not the size of the machine word?
On SOME machines, int may be easier to handle than a byte-sized object. But for many processors, an int is no easier to deal with than a byte-sized integer. Since a byte takes less space (at least if you don't stick it next to an int so that the compiler needs to pad it), then you benefit in doing so in some situations. I don't think the standard says anything about what size it actually MUST be. Edit: As the comment says, the C++ standard specifically says that the size is implementation defined, and is not required to be 1 (but it also doesn't say it CAN'T be 1). The standard also says that the value of a bool is true or false, but that if you "use" an uninitialized variable of type bool, it is undefined behaviour, and it can be something that is neither of those values. There are a

Categories : C++

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#

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

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#

Record type reflection / populating a record variable of an unknown type (PL/SQL)
You can try to use table user_identifiers or all_identifiers if you have the access, as this other SO post shows. You may need to recompile your packages: alter package my_types compile plscope_settings='IDENTIFIERS:ALL' reuse settings; Unfortunately this is only available from 11gR1.

Categories : Oracle

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#

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

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

Can I create a member variable that is a type parameter of a generic?
This is the code corresponding to my first comment. As i said this involves unchecked casts. public static class MyProxy<S extends Service, P extends BindingProvider> { private static final MyProxy<? extends Service, ? extends BindingProvider> instance = new Proxy<Service, BindingProvider>(); private S service; public static <S extends Service, P extends BindingProvider> MyProxy<S, P> getInstance() { return (MyProxy<S, P>) instance; } }

Categories : Java

Create a Service instance with reference type parameter?
I would like to pass a List to this service to save locations You can use putStringArrayListExtra() to put an ArrayList<String> as an extra on an Intent.

Categories : Android

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

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

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#

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

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++

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#

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

How to create a new object from type parameter in generic class in typescript?
Because the compiled JavaScript has all the type information erased, you can't use T to new up an object. You can do this in a non-generic way by passing the type into the constructor. class TestOne { hi() { alert('Hi'); } } class TestTwo { constructor(private testType) { } getNew() { return new this.testType(); } } var test = new TestTwo(TestOne); var example = test.getNew(); example.hi(); You could extend this example using generics to tighten up the types: class TestBase { hi() { alert('Hi from base'); } } class TestSub extends TestBase { hi() { alert('Hi from sub'); } } class TestTwo<T extends TestBase> { constructor(private testType) { } getNew() : T { return new this.testType

Categories : Typescript

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#

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

Obtain the Type of a Nullable Property that has a Nothing value
When a Nullable(Of T) becomes an Object, the type data is lost: it either becomes a plain old Nothing, or the type it represents, e.g. Integer. You might be able to change your method to do this: Public Sub Asign(Of T As Structure)(ByRef container As Nullable(Of T), value As String) ' T is Integer or Date, in your examples container = System.Convert.ChangeType(value, GetType(T)) End Sub If not, you'll have to record the type elsewhere, and pass that into your method. For some info on why the boxing/unboxing was set up to work this way, see Boxing / Unboxing Nullable Types - Why this implementation?. In short, it's the most sensible way to work with a nullable type as an Object.

Categories : Dotnet

Linq.Expression with a Nullable<'T> type
Typically the functions associated with the member variable needs to be mapped in the Sql builder(for Expressions); for example string's ToUpper() function is mapped internally to sql's UPPER() function. Since the Sql Builder does not know what is GetValueOrDefault (as this function is not mapped to any SQL function) , it is erroring out. I'm not sure what SQL statement can be used for this, if you have a valid case for it, please create a ticket in the Github.

Categories : Linq

MethodInfo.GetParameter() with Nullable type
you can check Nullable types as below var parms = method.GetParameters(); foreach (ParameterInfo p in parms) { var IsNullable = Nullable.GetUnderlyingType(p.ParameterType) !=null; } Nullable.GetUnderlyingType will return null in case of not Nullable type. normally we can check for nullable types as below System.Type type = typeof(int?); Console.WriteLine(type.FullName); // System.Nullable`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] but when we use reflection at run time it will give the underline type not the nullbale type. int? i = 5; Type t = i.GetType(); Console.WriteLine(t.FullName); //"System.Int32" Reason explained in MSDN as below Calling GetType on a Nullable type causes a boxing operation to be performed

Categories : C#

How can I see the type deduced for a template type parameter?
To get the compiler to show you the type of a variable (perhaps in a round about way); T parameter; .... void f(int x); ... f(parameter); compiler should complain that "T" cannot be converted to int, assuming that it actually can't.

Categories : C++

Constrain type parameter to a base type
Declare both generic types and the generic constraint at class(interface) level: public interface IMapping<T1, T2> where T2 : T1 { void IncludeMapping(IMapping<T1, T2> otherMapping); }

Categories : C#

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#



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