INTEGRATION: CWS jl31 (1.3.26); FILE MERGED
2006/02/08 11:39:53 jl 1.3.26.3: #61436# GetCustomAttributes and IsDefined did not delegate to the base type 2006/02/08 11:29:56 jl 1.3.26.2: #61436# adapted documentation 2006/02/03 16:37:49 jl 1.3.26.1: #i61436# generated service code contained bugs, in particular when polymorphic structs are used
This commit is contained in:
@@ -4,9 +4,9 @@
|
|||||||
*
|
*
|
||||||
* $RCSfile: PolymorphicType.cs,v $
|
* $RCSfile: PolymorphicType.cs,v $
|
||||||
*
|
*
|
||||||
* $Revision: 1.3 $
|
* $Revision: 1.4 $
|
||||||
*
|
*
|
||||||
* last change: $Author: rt $ $Date: 2005-09-08 01:59:54 $
|
* last change: $Author: rt $ $Date: 2006-03-09 10:51:56 $
|
||||||
*
|
*
|
||||||
* The Contents of this file are made available subject to
|
* The Contents of this file are made available subject to
|
||||||
* the terms of GNU Lesser General Public License Version 2.1.
|
* the terms of GNU Lesser General Public License Version 2.1.
|
||||||
@@ -44,28 +44,59 @@ namespace uno {
|
|||||||
|
|
||||||
/** represents a polymorphic type.
|
/** represents a polymorphic type.
|
||||||
|
|
||||||
<p> In .NET 1.1 it is not possible to have templated types. The
|
This class is used to carry type information for polymorphic struct types
|
||||||
polymorphic struct types from uno would be easiest mapped to templates. Since
|
and arrays of polymorphic struct types. These types would be easiest represented
|
||||||
this is not possible, one needs to conserve the information (e.g. the type list)
|
with type templates, which are not available in .NET 1.1. Therefore
|
||||||
so that a lossless mapping from UNO to CLI and back is possible. To do that, this
|
the System.Type cannot contain information about template parameters. To
|
||||||
class is used. It keeps the actual type object and additionally its polymorphic
|
retain this information we use PolymorphicType which directly inherits from
|
||||||
name, for example: unoidl.com.sun.star.beans.Defaulted<System.Char>. This name
|
System.Type. The additional information about type parameters are passed
|
||||||
is an invalid Name in .NET 1.1. But it is needed by the cli-uno bridge to perform
|
as simple string when creating an instance of PolymorphicType. Usually one
|
||||||
a proper conversion</p>
|
only needs a PolymorphicType when a polymporphic type is put into an
|
||||||
|
uno.Any. For example, let's assume there is a idl type PolyStruct:
|
||||||
|
|
||||||
<p>The full polymorphic name contains a list of type names. Only type names common
|
module test {
|
||||||
|
struct PolyStruct< T >
|
||||||
|
{
|
||||||
|
T member;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
Then one would use it in C# in this way:
|
||||||
|
|
||||||
|
uno.Any myAny = new uno.Any( PolymorphicType.GetType(
|
||||||
|
typeof(PolyStruct), "unoidl.test.PolyStruct<System.Boolean>"),
|
||||||
|
new PolyStruct(true));
|
||||||
|
|
||||||
|
or if one has a sequence of polymorphic structs:
|
||||||
|
|
||||||
|
uno.Any myAny = new uno.Any( PolymorphicType.GetType(
|
||||||
|
typeof(PolyStruct), "unoidl.test.PolyStruct<System.Boolean>[]"),
|
||||||
|
new PolyStruct[] {new PolyStruct(true)} );
|
||||||
|
|
||||||
|
|
||||||
|
To get a new instance of PolymorphicType one uses the static method
|
||||||
|
PolymorphicType.GetType. The method ensures that there is only one instance
|
||||||
|
for each distinct name. For example, if GetType is called multiple times with
|
||||||
|
the name "unoidl.test.PolyStruct<System.Boolean>" then the same instance of
|
||||||
|
PolymorphicType is returned. This makes it possible to compare the instances
|
||||||
|
by reference, thas is using the operator "==".
|
||||||
|
|
||||||
|
The polymorphic name, which is passed as second argument to PolymorphicType.GetType,
|
||||||
|
contains a list of type names. Only type names common
|
||||||
to all CLI languages can be used. That is, instead of using names, such as
|
to all CLI languages can be used. That is, instead of using names, such as
|
||||||
<code>char, int, float</code>, the names <code>System.Char, System.Int32 and
|
char, int, float, the names System.Char, System.Int32 and
|
||||||
System.Single</code> are
|
System.Single are to be used. Spaces are not allowed.
|
||||||
to be used.</p>
|
The name will always start with "unoidl", when the type was generated by climaker.
|
||||||
|
Here are a couple of possible strings:
|
||||||
|
|
||||||
<p>Once the CLI supports templates we will adapt the cli-uno bridge accordingly.
|
unoidl.test.PolyStruct<System.Int32>
|
||||||
Then this class will become obsolete. </p>
|
unoidl.test.PolyStruct<System.Char[]>
|
||||||
|
unoidl.test.PolyStruct<System.Int64>[]
|
||||||
|
unoidl.test.PolyStruct<unoidl.test.PolyStruct<System.Int64>>
|
||||||
|
unoidl.test.PolyStruct<unoidl.test.PolyStruct<System.Int64[]>[]>[]
|
||||||
|
|
||||||
<p>This class derives from System::Type, so it can be used in API
|
In the future, when the CLI supports templates, we will probably adapt the cli-uno
|
||||||
calls whereever a Type is required. Of the inherited methods
|
bridge accordingly to use real template types. Then this class will become obsolete.
|
||||||
it only supplies implementations for the abstract types. These functions
|
|
||||||
simply delegate to the orignal Type object. </p>
|
|
||||||
*/
|
*/
|
||||||
public class PolymorphicType: Type
|
public class PolymorphicType: Type
|
||||||
{
|
{
|
||||||
@@ -82,11 +113,7 @@ public class PolymorphicType: Type
|
|||||||
the type of the polymorphic struct. For example, created by
|
the type of the polymorphic struct. For example, created by
|
||||||
<code>typeof(unoidl.com.sun.star.beans.Defaulted)</code>
|
<code>typeof(unoidl.com.sun.star.beans.Defaulted)</code>
|
||||||
@param name
|
@param name
|
||||||
the full name of the struct (including the type list), for example:
|
the full name of the struct (including the type list).
|
||||||
unoidl.com.sun.star.beans.Defaulted<System.Int32>
|
|
||||||
The type names must not be programming specific but rather those commen to all
|
|
||||||
languages, that is the names of the respective structures from System namespace.
|
|
||||||
They must be fully qualified.
|
|
||||||
@return
|
@return
|
||||||
null - the argument type is no valid polymorphic struct or <br>
|
null - the argument type is no valid polymorphic struct or <br>
|
||||||
an instance of this class.
|
an instance of this class.
|
||||||
@@ -98,9 +125,23 @@ public class PolymorphicType: Type
|
|||||||
if (name == null || type == null)
|
if (name == null || type == null)
|
||||||
throw new ArgumentNullException(
|
throw new ArgumentNullException(
|
||||||
"cli-uno: uno.PolymorphicType.GetType was called with a null argument");
|
"cli-uno: uno.PolymorphicType.GetType was called with a null argument");
|
||||||
if (Attribute.GetCustomAttribute(type, typeof(uno.TypeParametersAttribute))
|
//check if the type is either a array of structs or a polymorphic struct.
|
||||||
== null)
|
if (type.IsArray)
|
||||||
|
{
|
||||||
|
Type elementType = type;
|
||||||
|
while ((elementType = elementType.GetElementType()).IsArray);
|
||||||
|
//unfortunately we cannot check if it is a real polymorphic struct here.
|
||||||
|
if ( ! elementType.IsClass)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (Attribute.GetCustomAttribute(type, typeof(uno.TypeParametersAttribute))
|
||||||
|
== null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
lock (m_ht_types.SyncRoot)
|
lock (m_ht_types.SyncRoot)
|
||||||
{
|
{
|
||||||
PolymorphicType t = (PolymorphicType) m_ht_types[name];
|
PolymorphicType t = (PolymorphicType) m_ht_types[name];
|
||||||
@@ -217,27 +258,32 @@ public class PolymorphicType: Type
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override Type DeclaringType
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return m_base.DeclaringType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override object[] GetCustomAttributes(
|
public override object[] GetCustomAttributes(
|
||||||
bool inherit)
|
bool inherit)
|
||||||
{
|
{
|
||||||
//todo
|
return m_base.GetCustomAttributes(inherit);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override object[] GetCustomAttributes(
|
public override object[] GetCustomAttributes(
|
||||||
Type attributeType,
|
Type attributeType,
|
||||||
bool inherit)
|
bool inherit)
|
||||||
{
|
{
|
||||||
//todo
|
return m_base.GetCustomAttributes(attributeType, inherit);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsDefined(
|
public override bool IsDefined(
|
||||||
Type attributeType,
|
Type attributeType,
|
||||||
bool inherit)
|
bool inherit)
|
||||||
{
|
{
|
||||||
//todo
|
return IsDefined(attributeType, inherit);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override TypeAttributes GetAttributeFlagsImpl()
|
protected override TypeAttributes GetAttributeFlagsImpl()
|
||||||
|
Reference in New Issue
Block a user