Why doesn't strings.Cast<object> cast List<string> to List<object>?
Tag : chash , By : baylisscg
Date : March 29 2020, 07:55 AM
I hope this helps . You're misusing Cast. First, here: IEnumerable<string> items = strings.Cast<object>();
// Cast to IEnumerabe<object> then convert to List<object>
ProcessCollectionDynamicallyWithReflection(strings.Cast<object>().ToList());
|
Query List of Dictionary<string, object>, can't cast from object to original type
Tag : linq , By : Killercode
Date : March 29 2020, 07:55 AM
will be helpful for those in need You can simply write a helper method that ensures the type of the value prior to executing the predicate. Something like: public static bool CompareToObject<TSource>(TSource left, object right, Func<TSource, TSource, bool> predicate)
{
if (right is TSource)
return predicate(left, (TSource)right);
else
return false;
}
entityProps.Where(p => CompareToObject(p[propName], value, (x, y) => x == y));
|
Can I cast a string object passed on command line argument to the actual object?
Date : March 29 2020, 07:55 AM
To fix the issue you can do You probably can't, because it's a string. It's not a cProduct (whatever that is - consider following .NET naming conventions and naming it Product instead). Now you could do this if you had a explicit conversion operator in cProduct to create an instance from a string. Product product = new Product(objPro.CommandArgument);
Product product = Product.Parse(objPro.CommandArgument);
|
Can not fetch hibernate object attribute within ObjectList - java.lang.String cannot be cast to Object
Tag : java , By : Adam May
Date : March 29 2020, 07:55 AM
will help you I have the following Hibernate Object implemented: , My picklist component: <p:pickList id="pickList"
value="# {reportConfiguratorBean.dualListVars}"
var="cRVariable"
itemValue="#{cRVariable}"
itemLabel="#{cRVariable.varName}"
converter="cRVariableConverter"
Ajax="false" >
<f:facet name="sourceCaption">Available Variables</f:facet>
<f:facet name="targetCaption">Associated Variables</f:facet>
</p:pickList>
public Object getAsObject(FacesContext context, UIComponent component, String value) {
Long varId = Long.parseLong(value.trim());
List<CRVariable> cRVariables = mybean.getCRVariables();
for (CRVariable cRVariable:cRVariables) {
if(cRVariable.getVarId().compareTo(varId)==0){
return cRVariable;
}
}
return null;
}
|
trying to cast an object to javascript []{}- C# Key Value Collection OR Dictionary<string,object> or<string, st
Tag : chash , By : antonio
Date : March 29 2020, 07:55 AM
This might help you I gave your sample a try and noticed that the startPrt parameter is actually being received as an Array of Dictionary(string, object). Hence, if you make the AJAX call like this: var hDate = [];
hDate.push({ key: "Name", value: Name });
hDate.push({ key: "City", value: City });
hDate.push({ key: "Country", value: Country });
hDate.push({ key: "SelctedClass", value: selectedRC });
$.ajax({
contentType: 'application/json; charset=utf-8',
url: 'MyPage.aspx/AddNewRecord',
type: 'POST',
data: JSON.stringify({ startPrt: hDate }),
success: success, // success callback
error: error // error callback
});
[WebMethod]
public static void AddNewRecord(object startPrt)
{
var dict = new Dictionary<string, object>();
foreach (Dictionary<string, object> pair in (Array)startPrt)
dict.Add((string)pair["key"], pair["value"]);
}
|