How to Casting Object(by Type.InvokeMember) to ObservableCollection<ReflectionType>? - observablecollection

When I got the object by calling Type.InvokeMember(), the Object Type is
Object{ObervableCollection<SomeType>
How can I Casting this object to original type? or how to casting the object to DataTable or List<OriginalType>?

Related

The instance relation between type and object in python?

Show class relation between type and object:
issubclass(type,object)
True
issubclass(object,type)
False
It is clear that type derived from object,object is the father class of type,type is the son class of object.
isinstance(type,object)
True
isinstance(object,type)
True
How to understand that type is the instance of object and vice versa ?
Useful Definition
isinstance(object, classinfo)
Return True if the object argument is an instance of the classinfo argument, or of a (direct, indirect or virtual) subclass thereof.
https://docs.python.org/3.9/library/functions.html?highlight=isinstance#isinstance
1) type is an instance of object
All data is represented by objects and object is a base for all classes
Objects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects.
https://docs.python.org/3.9/reference/datamodel.html#types
object is a base for all classes.
https://docs.python.org/3.9/library/functions.html?highlight=object#object
type inherits from object (https://docs.python.org/3.9/library/functions.html?highlight=object#type) so type is both a subclass and also an instance of object using the isinstance description.
2) object is an instance of type
object is a type object. In other words, object is of type, type
Type Objects
Type objects represent the various object types. An object’s type is accessed by the built-in function type()
https://docs.python.org/3.9/library/stdtypes.html?highlight=subclass#type-objects
type(object) # returns type
type(type) # returns type
object.__class__ # returns type
type.__class__ # returns type
Which helps us understand how isInstance(object, type) will return True.
An intuitive way to think about this is that the object object is of type type but object is not a subclass of type because it doesn't inherit from type

Java instance creation with object as parameter

When i create an object of a class which accepts object as a parameter
for Example
GarbageCollected gc= new GarbageCollected();
WeakReference<GarbageCollected> reference = new WeakReference<GarbageCollected>()(gc);
So here how does the reference 'gc' works internally while one creates the object of 'WeakReference' class with "gc' as the argument.

object cannot be cast from DBNULL to ther types

I'am using GetOrdinal in my code. the code
mastxtDateEnded_Edit.Text =
Convert.ToDateTime(cursor.GetValue(cursor.GetOrdinal("DateEnded")))
.ToString("MM/dd/yyyy"));
Error: object cannot be cast from DBNULL to ther types.
You can use the IsDBNull method to check for the null value:
int index = cursor.GetOrdinal("DateEnded")
mastxtDateEnded_Edit.Text =
cursor.IsDBNull(index) ?
String.Empty :
((DateTime)(cursor.GetValue(index))).ToString("MM/dd/yyyy");

Casting a Generic EntitySet returned by Reflection as an EntitySet with a BaseClass Type

I am having an issue when casting a Generic EntitySet returned by Reflection as an EntitySet with a BaseClass Type.
All of my Linq2Sql classes inherit from a base class named LinqClassBase like this:
public partial class MyTable1 : LinqClassBase
I am writing a method in that base class that needs to iterate through all child EntitySets.
I can retrieve the PropertyInfo OK as matchingEntitySetProperty.
// The GetMatchingProperty method (not shown)
// simply gets all the properties with Type EntitySet
var matchingProperty = entitySetProperty.GetMatchingProperty(this.GetType());
I can also get it's value OK.
// This returns EntitySet<MyTable1>
var matchingSet = matchingProperty.GetValue(this);
The problem here is that I can't call the ToList method because the object isn't strongly typed.
var newList = matchingSet.ToList().ConvertAll(
x => x.MyLinqBaseClassMethod()
);
I tried casting it as EntitySet but it returns null:
// This returns null
var matchingSet = matchingProperty.GetValue(this) as EntitySet<LinqClassBase>;
Why does this cast return null? I'm guessing because C# can't cast EntitySet to EntitySet.
Ff this cast isn't possible, is there another way to Cast it?
Note: I thought about using another layer of Reflection to call the ToList method, but then I would run into the same problem for the ConvertAll method and again for the MyLinqBaseClassMethod.
I figured it out. Casting it to IEnumerable gives me access to the ToList method and doesn't cause it to return a null.
var matchingSet = matchingProperty.GetValue(this) as IEnumerable<LinqClassBase>;
I still don't know why casting it has EntitySet fails. But at least I have my solution.

Convert CBitmap object to CxImage object MFC

I have a CBitmap object "m_bmp". I need to convert this to a CxImage Object. Any ideas? Is there any direct conversion from bitmap object to other types available from CxImage?
m_Img.CreateFromHBITMAP((HBITMAP)m_bmp.m_hObject);
m_Img is a CxImage Object. After initializing the device context to draw to "m_bmp", the CreateFromHBITMAP function is called.

Resources