I got the following code that generate a DLL (sample exemple) :
public class PluginClass
{
private string _MyString;
public string MyString
{
get { return _MyString; }
set
{
_MyString = value;
RaisePropertyChanged("MyString");
}
}
public int MyInt;
public SpeedGenerator SpeedGenerator1 = new SpeedGenerator();
public GaugeValueGenerator GaugeValueGenerator1
{
get;
set;
}
public PluginClass()
{
GaugeValueGenerator1 = new GaugeValueGenerator();
}
}
As you can see I got 4 fields/properties.
1 primitive field (primitive is int/string/bool/etcetc…) : MyInt
1 primitive property : MyString
1 object field : SpeedGenerator1
1 object property : GaugeValueGenerator1
When Im parsing my DLL I got to do some code that is in the function : WriteProperty
var fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
var props = type.GetProperties();
foreach (FieldInfo field in fields)
{
WriteProperty(field.FieldType, field.Name, XXX);
}
foreach (PropertyInfo prop in props)
{
WriteProperty(prop.PropertyType, prop.Name, XXX);
}
My question is on XXX that is a boolean that indicate if my field/property is “primitive”. So it must be set to false if it is an object.
I fell like I tried quite everything but I can’t resolve it…
Any help will be very appreciate !
(My idea was to call
var props = propertyType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
and consider that it should be empty for simple/primitive types ! But no… for example on String, this return the properties Chars (char[]) and Length (int)…)
(nb : Of course I don’t wanna do a string operation on field/property.Name/FullName… something like
if ((propertyType.FullName).Contains("System."))
would be very very sucky… and inaccurate)
Why not use
IsPrimitiveof theTypeclass?EDIT: You will have to treat
stringas a special case asIsPrimitivewill not returntrue.EDIT 2: The problem you are having is that you are trying to marry two primitve definitions wich don’t match. Being that the case I can only see two options:
Make both definitions match which obviously you can’t do changing the CLR type system and probably can’t do either changing the framework you are using.
Make some hack that “marries” both definitions. I see no other way around hardcoding the specific exceptions that don’t match one of the two definitions of primitve types.