Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3347224
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:23:46+00:00 2026-05-18T01:23:46+00:00

Below is a simple method I wrote (extremely simplified down so I hope it

  • 0

Below is a simple method I wrote (extremely simplified down so I hope it still gets the jist across) for taking a string representation of an array’s elements in a string, and converting them into an actual array of those values. t is the type of the array.

DeserializeArray(string sArrayElements, out Array aValues, Type t)
{
    string[] sValues = ProcessArrayElements(sArrayAsString);
    ArrayList alValues = new ArrayList(sValues.Length);
    for(int i = 0; i < sValues.Length; ++i)
        alValues.Add(ProcessValue(sValues[ i ] ));
    aValues = alValues.ToArray(t.GetElementType());
    return true;
}

I would then use this method with the code below. propertyInfo is the property of an object that in this case .IsArray() == true. sArrayElements is just the string that contains the string representation of the array (“val1,val2,…,valN”)

Array aValues;
if (DeserializeArray(sArrayElements, out aValues, propertyInfo.PropertyType))
    propertyInfo.SetValue(oObject, aValues, null);
else
    throw new FormatException("Unable to parse Array Elements: " + sArrayElements);

This works beautifully in .NET, but not in Silverlight because the ArrayList object is marked as Internal or something (can not use type because access level blah blah blah).

So I am looking for an alternative to the ArrayList.ToArray(Type). I can not just use a List<object>.ToArray() because the PropertyInfo.SetValue() call will bawk at trying to make an object[] into an Int32[] or the like.

I have tried in the DeserializeArray() method to do something like aValues = Array.CreateInstance(t.GetElementType()) but I can not use [] to assign the values and you can not assign values to the foreach(obj in objects).

I then tried changing the aValues parameter to a generic object[] array but i get the same conversion (boxing/unboxing) errors at run time when calling the Array.CreateInstance().

So yeah; I am trying to find a solution to this problem for Silverlight 4. Any help would be greatly appreciated 🙂

  • James
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:23:47+00:00Added an answer on May 18, 2026 at 1:23 am

    Not tested, but I think this should do what you want:

    DeserializeArray(string sArrayElements, out Array aValues, Type t) 
    { 
        string[] sValues = ProcessArrayElements(sArrayAsString); 
        aValues = new Array[sValues.Length];
        for(int i = 0; i < sValues.Length; ++i) 
            aValues.SetValue(Activator.CreateInstance(t,ProcessValue(sValues[i])),i); 
    
        return true; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below are two simple Cython methods I wrote. In g_cython() method I used additional
How can i shorter below codes than before? i need short and simple method:
Consider the simple example below of implementing a method in an Enum. One problem
The code below generates a warning CS3006 Overloaded method MyNamespace.Sample.MyMethod(int[])' differing only in ref
Below just a simple race between 2 button in 2 threads, and this will
For a simple plot below, is there a way to make matplotlib populate the
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
The code pasted below is a simple JSF program, with an idea of having
I am testing this simple code below and it works... $(document).ready( function() { $('.show-modal').click(
I am having trouble with some javascript. The code snippet below creates a simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.