private StateStructure(Type type)
        {
            if (!type.Name.StartsWith("I", StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("The interface for the component state needs to start with I");
            }

            _interfaceName = type.Name;
            _namespaceName = type.Namespace;
            _interfaceType = type;

            PropertyInfo[] properties = type.GetProperties();

            foreach (PropertyInfo pi in properties)
            {
                if (pi.PropertyType.IsGenericType)
                {
                    Type baseGenericType = pi.PropertyType.GetGenericTypeDefinition();
                    if (baseGenericType == typeof(Esmf.IVariable1Dimensional<,>))
                    {
                        Type[] dimensionTypes = pi.PropertyType.GetGenericArguments();

                        StateFieldStructure field = new StateFieldStructure();
                        field.Name = pi.Name;
                        field.CanWrite = true;
                        field.Type = dimensionTypes[1];

                        StateFieldDimensionStructure d1 = new StateFieldDimensionStructure();
                        d1.Type = dimensionTypes[0];
                        d1.Name = d1.Type.Name;
                        field.Dimensions.Add(d1);

                        _fields.Add(field);
                    }
                    else if (baseGenericType == typeof(Esmf.IVariable2Dimensional<,,>))
                    {
                        Type[] dimensionTypes = pi.PropertyType.GetGenericArguments();

                        StateFieldStructure field = new StateFieldStructure();
                        field.Name = pi.Name;
                        field.CanWrite = true;
                        field.Type = dimensionTypes[2];

                        StateFieldDimensionStructure d1 = new StateFieldDimensionStructure();
                        d1.Type = dimensionTypes[0];
                        d1.Name = d1.Type.Name;
                        field.Dimensions.Add(d1);

                        StateFieldDimensionStructure d2 = new StateFieldDimensionStructure();
                        d2.Type = dimensionTypes[1];
                        d2.Name = d1.Type.Name;
                        field.Dimensions.Add(d2);

                        _fields.Add(field);
                    }
                    else if (baseGenericType == typeof(Esmf.IParameter1Dimensional<,>))
                    {
                        Type[] dimensionTypes = pi.PropertyType.GetGenericArguments();

                        StateFieldStructure field = new StateFieldStructure();
                        field.Name = pi.Name;
                        field.CanWrite = false;
                        field.Type = dimensionTypes[1];

                        StateFieldDimensionStructure d1 = new StateFieldDimensionStructure();
                        d1.Type = dimensionTypes[0];
                        d1.Name = d1.Type.Name;
                        field.Dimensions.Add(d1);

                        _fields.Add(field);
                    }
                    else if (baseGenericType == typeof(Esmf.IParameter2Dimensional<,,>))
                    {
                        Type[] dimensionTypes = pi.PropertyType.GetGenericArguments();

                        StateFieldStructure field = new StateFieldStructure();
                        field.Name = pi.Name;
                        field.CanWrite = false;
                        field.Type = dimensionTypes[2];

                        StateFieldDimensionStructure d1 = new StateFieldDimensionStructure();
                        d1.Type = dimensionTypes[0];
                        d1.Name = d1.Type.Name;
                        field.Dimensions.Add(d1);

                        StateFieldDimensionStructure d2 = new StateFieldDimensionStructure();
                        d2.Type = dimensionTypes[1];
                        d2.Name = d1.Type.Name;
                        field.Dimensions.Add(d2);

                        _fields.Add(field);
                    }
                }
                else
                {
                    StateFieldStructure field = new StateFieldStructure();
                    field.Name = pi.Name;
                    field.CanWrite = pi.CanWrite;
                    field.Type = pi.PropertyType;

                    _fields.Add(field);
                }
            }
        }
Beispiel #2
0
        private StateStructure(Type type)
        {
            if (!type.Name.StartsWith("I", StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException("The interface for the component state needs to start with I");
            }

            _interfaceName = type.Name;
            _namespaceName = type.Namespace;
            _interfaceType = type;

            PropertyInfo[] properties = type.GetProperties();

            foreach (PropertyInfo pi in properties)
            {
                if (pi.PropertyType.IsGenericType)
                {
                    Type baseGenericType = pi.PropertyType.GetGenericTypeDefinition();
                    if (baseGenericType == typeof(Esmf.IVariable1Dimensional <,>))
                    {
                        Type[] dimensionTypes = pi.PropertyType.GetGenericArguments();

                        StateFieldStructure field = new StateFieldStructure();
                        field.Name     = pi.Name;
                        field.CanWrite = true;
                        field.Type     = dimensionTypes[1];

                        StateFieldDimensionStructure d1 = new StateFieldDimensionStructure();
                        d1.Type = dimensionTypes[0];
                        d1.Name = d1.Type.Name;
                        field.Dimensions.Add(d1);

                        _fields.Add(field);
                    }
                    else if (baseGenericType == typeof(Esmf.IVariable2Dimensional <, ,>))
                    {
                        Type[] dimensionTypes = pi.PropertyType.GetGenericArguments();

                        StateFieldStructure field = new StateFieldStructure();
                        field.Name     = pi.Name;
                        field.CanWrite = true;
                        field.Type     = dimensionTypes[2];

                        StateFieldDimensionStructure d1 = new StateFieldDimensionStructure();
                        d1.Type = dimensionTypes[0];
                        d1.Name = d1.Type.Name;
                        field.Dimensions.Add(d1);

                        StateFieldDimensionStructure d2 = new StateFieldDimensionStructure();
                        d2.Type = dimensionTypes[1];
                        d2.Name = d1.Type.Name;
                        field.Dimensions.Add(d2);

                        _fields.Add(field);
                    }
                    else if (baseGenericType == typeof(Esmf.IParameter1Dimensional <,>))
                    {
                        Type[] dimensionTypes = pi.PropertyType.GetGenericArguments();

                        StateFieldStructure field = new StateFieldStructure();
                        field.Name     = pi.Name;
                        field.CanWrite = false;
                        field.Type     = dimensionTypes[1];

                        StateFieldDimensionStructure d1 = new StateFieldDimensionStructure();
                        d1.Type = dimensionTypes[0];
                        d1.Name = d1.Type.Name;
                        field.Dimensions.Add(d1);

                        _fields.Add(field);
                    }
                    else if (baseGenericType == typeof(Esmf.IParameter2Dimensional <, ,>))
                    {
                        Type[] dimensionTypes = pi.PropertyType.GetGenericArguments();

                        StateFieldStructure field = new StateFieldStructure();
                        field.Name     = pi.Name;
                        field.CanWrite = false;
                        field.Type     = dimensionTypes[2];

                        StateFieldDimensionStructure d1 = new StateFieldDimensionStructure();
                        d1.Type = dimensionTypes[0];
                        d1.Name = d1.Type.Name;
                        field.Dimensions.Add(d1);

                        StateFieldDimensionStructure d2 = new StateFieldDimensionStructure();
                        d2.Type = dimensionTypes[1];
                        d2.Name = d1.Type.Name;
                        field.Dimensions.Add(d2);

                        _fields.Add(field);
                    }
                }
                else
                {
                    StateFieldStructure field = new StateFieldStructure();
                    field.Name     = pi.Name;
                    field.CanWrite = pi.CanWrite;
                    field.Type     = pi.PropertyType;

                    _fields.Add(field);
                }
            }
        }