0

This is the code which i am using..

using PWServiceProxy

PortfolioQueryOptions Query = new PortfolioQueryOptions();
Query.PortfolioTypes = "Funded";

I am receiving an error such as

Cannot implicitly convert type string to PWServiceProxy.PortfolioTypes.

2 Answers 2

9

Seems that Query.PortfolioTypes is type of PWServiceProxy.PortfolioTypes i.e. enum.

So you need to

Query.PortfolioTypes = PortfolioTypes.Funded;

or

string str = "Funded"; // or something else
PortfolioTypes pt;
if (Enum.TryParse(str, out pt))
    Query.PortfolioTypes = pt;
else
    throw new Exception("Can't parse input as PortfolioTypes");
Sign up to request clarification or add additional context in comments.

7 Comments

+1 that's of course better in the scenario described - parsing should only be done if you are stuck using a string you got from somewhere
thats not going to work. because i need to pass string to the Query.PortfolioTypes
@Peddireddy: PortfolioTypes is clearly not of type string - please share the type with us if it's not enum
Portfolio Type is an object Coming out from PWServiceProxy.
@Peddireddy: What is it's type? Try value.GetType().ToString(). Or it is object?
|
1

Assuming PortfolioTypes is an enum with the name YourEnumType try this :

Query.PortfolioTypes = (YourEnumType) Enum.Parse(typeof(YourEnumType), "Funded", true);

1 Comment

TrParse() is faster and type-safe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.