Click here to Skip to main content
15,889,651 members
Home / Discussions / C#
   

C#

 
GeneralRe: server DB Pin
om_metab22-Dec-10 3:11
om_metab22-Dec-10 3:11 
QuestionNetwork Sqlserver ConnectionString Pin
navidsoft27-Nov-10 18:16
professionalnavidsoft27-Nov-10 18:16 
AnswerRe: Network Sqlserver ConnectionString Pin
Roger Wright27-Nov-10 18:41
professionalRoger Wright27-Nov-10 18:41 
AnswerRe: Network Sqlserver ConnectionString Pin
Luc Pattyn27-Nov-10 21:46
sitebuilderLuc Pattyn27-Nov-10 21:46 
GeneralRe: Network Sqlserver ConnectionString Pin
navidsoft28-Nov-10 2:19
professionalnavidsoft28-Nov-10 2:19 
AnswerRe: Network Sqlserver ConnectionString Pin
PIEBALDconsult28-Nov-10 4:01
mvePIEBALDconsult28-Nov-10 4:01 
AnswerRe: Network Sqlserver ConnectionString Pin
Dave Kreskowiak28-Nov-10 11:42
mveDave Kreskowiak28-Nov-10 11:42 
QuestionAssigning a value to an array property via reflection Pin
Lutosław27-Nov-10 12:21
Lutosław27-Nov-10 12:21 
Hello,

I have an untyped parameter _target and the following code:
Type T; // type of a property of _target. The type itself is T[]
//, but here I have a type of elements of an array.
List<object> olist; // list where am I going to store array's elements.
IEnumerable<PropertyInfo> subProps; // properties of T

// GetO creates an instance of T and assigns all it's properties.
olist.AddRange(resultSet.Select(result => GetO(T, subProps, result)));
                                
// Here I got ArgumentException
// Object of type 'System.Object[]' cannot be converted to type 'GameEditor.Model.SceneExit[]'.
// In a debugger I can see that all elements of olist are of type T. It is understandable.
// But the list itsefs is still List<object> and therefore SetValue fails
prop.Info.SetValue(_target, olist.ToArray(), new object[0]); 


I would have to write a lot of words, but I hope you understand what is the point after reading comments.

Before I posted this, I had came up with another idea:
Type t = ...;
dynamic olist =
    typeof (List<object>).GetGenericTypeDefinition().MakeGenericType(new Type[] {t})
        .GetConstructor(new Type[] {typeof(int)}).Invoke(new object[] {resultSet.Count});
IEnumerable<PropertyInfo> subProps = ...;

foreach (SparqlResult result in resultSet)
    olist.Add(GetO(t, subProps, result)); // fails here this time (parameter doesnt match)
// Although GetO returns an object of correct type, but formally it's still an 'object'
// (dynamic thing is 'too good'...)
                                
prop.Info.SetValue(_target, olist.ToArray(), new object[0]);


I tried also using Convert.ChangeType but with no success.

What would be a working solution? An "anymous" cast would be good, like (type)object, but there is no such thing.

Thanks in advance,
Greetings - Jacek

AnswerRe: Assigning a value to an array property via reflection Pin
Lutosław27-Nov-10 13:01
Lutosław27-Nov-10 13:01 
GeneralRe: Assigning a value to an array property via reflection Pin
RaviRanjanKr18-Dec-10 21:27
professionalRaviRanjanKr18-Dec-10 21:27 
Questiontabcontrol with contextMenu Pin
Erdinc2727-Nov-10 1:12
Erdinc2727-Nov-10 1:12 
AnswerRe: tabcontrol with contextMenu Pin
Erdinc2727-Nov-10 2:36
Erdinc2727-Nov-10 2:36 
GeneralRe: tabcontrol with contextMenu Pin
OriginalGriff27-Nov-10 4:24
mveOriginalGriff27-Nov-10 4:24 
Questiontransfer arithmetical operation to executable ascii code Pin
igalep13227-Nov-10 0:16
igalep13227-Nov-10 0:16 
AnswerRe: transfer arithmetical operation to executable ascii code Pin
JF201527-Nov-10 0:21
JF201527-Nov-10 0:21 
QuestionHow to use image from button1 and use it in button2 Pin
pancakeleh27-Nov-10 0:01
pancakeleh27-Nov-10 0:01 
AnswerRe: How to use image from button1 and use it in button2 Pin
nitin bhoyate27-Nov-10 1:51
nitin bhoyate27-Nov-10 1:51 
GeneralRe: How to use image from button1 and use it in button2 Pin
pancakeleh27-Nov-10 3:18
pancakeleh27-Nov-10 3:18 
GeneralRe: How to use image from button1 and use it in button2 Pin
Dave Kreskowiak27-Nov-10 3:27
mveDave Kreskowiak27-Nov-10 3:27 
GeneralRe: How to use image from button1 and use it in button2 Pin
pancakeleh27-Nov-10 4:22
pancakeleh27-Nov-10 4:22 
GeneralRe: How to use image from button1 and use it in button2 Pin
nitin bhoyate28-Nov-10 17:39
nitin bhoyate28-Nov-10 17:39 
Questioncontrol webcam for another application Pin
Zvi Balas26-Nov-10 20:45
Zvi Balas26-Nov-10 20:45 
AnswerRe: control webcam for another application Pin
Dave Kreskowiak27-Nov-10 3:25
mveDave Kreskowiak27-Nov-10 3:25 
AnswerRe: control webcam for another application Pin
Not Active27-Nov-10 3:48
mentorNot Active27-Nov-10 3:48 
AnswerRe: control webcam for another application Pin
RaviRanjanKr28-Nov-10 5:12
professionalRaviRanjanKr28-Nov-10 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.