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 $
|
||||
*
|
||||
* $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 terms of GNU Lesser General Public License Version 2.1.
|
||||
@@ -44,28 +44,59 @@ namespace uno {
|
||||
|
||||
/** represents a polymorphic type.
|
||||
|
||||
<p> In .NET 1.1 it is not possible to have templated types. The
|
||||
polymorphic struct types from uno would be easiest mapped to templates. Since
|
||||
this is not possible, one needs to conserve the information (e.g. the type list)
|
||||
so that a lossless mapping from UNO to CLI and back is possible. To do that, this
|
||||
class is used. It keeps the actual type object and additionally its polymorphic
|
||||
name, for example: unoidl.com.sun.star.beans.Defaulted<System.Char>. This name
|
||||
is an invalid Name in .NET 1.1. But it is needed by the cli-uno bridge to perform
|
||||
a proper conversion</p>
|
||||
|
||||
<p>The full polymorphic name 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
|
||||
<code>char, int, float</code>, the names <code>System.Char, System.Int32 and
|
||||
System.Single</code> are
|
||||
to be used.</p>
|
||||
|
||||
<p>Once the CLI supports templates we will adapt the cli-uno bridge accordingly.
|
||||
Then this class will become obsolete. </p>
|
||||
This class is used to carry type information for polymorphic struct types
|
||||
and arrays of polymorphic struct types. These types would be easiest represented
|
||||
with type templates, which are not available in .NET 1.1. Therefore
|
||||
the System.Type cannot contain information about template parameters. To
|
||||
retain this information we use PolymorphicType which directly inherits from
|
||||
System.Type. The additional information about type parameters are passed
|
||||
as simple string when creating an instance of PolymorphicType. Usually one
|
||||
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>This class derives from System::Type, so it can be used in API
|
||||
calls whereever a Type is required. Of the inherited methods
|
||||
it only supplies implementations for the abstract types. These functions
|
||||
simply delegate to the orignal Type object. </p>
|
||||
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
|
||||
char, int, float, the names System.Char, System.Int32 and
|
||||
System.Single are to be used. Spaces are not allowed.
|
||||
The name will always start with "unoidl", when the type was generated by climaker.
|
||||
Here are a couple of possible strings:
|
||||
|
||||
unoidl.test.PolyStruct<System.Int32>
|
||||
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[]>[]>[]
|
||||
|
||||
In the future, when the CLI supports templates, we will probably adapt the cli-uno
|
||||
bridge accordingly to use real template types. Then this class will become obsolete.
|
||||
*/
|
||||
public class PolymorphicType: Type
|
||||
{
|
||||
@@ -82,11 +113,7 @@ public class PolymorphicType: Type
|
||||
the type of the polymorphic struct. For example, created by
|
||||
<code>typeof(unoidl.com.sun.star.beans.Defaulted)</code>
|
||||
@param name
|
||||
the full name of the struct (including the type list), for example:
|
||||
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.
|
||||
the full name of the struct (including the type list).
|
||||
@return
|
||||
null - the argument type is no valid polymorphic struct or <br>
|
||||
an instance of this class.
|
||||
@@ -98,9 +125,23 @@ public class PolymorphicType: Type
|
||||
if (name == null || type == null)
|
||||
throw new ArgumentNullException(
|
||||
"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.
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
else if (Attribute.GetCustomAttribute(type, typeof(uno.TypeParametersAttribute))
|
||||
== null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
lock (m_ht_types.SyncRoot)
|
||||
{
|
||||
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(
|
||||
bool inherit)
|
||||
{
|
||||
//todo
|
||||
return null;
|
||||
return m_base.GetCustomAttributes(inherit);
|
||||
}
|
||||
|
||||
public override object[] GetCustomAttributes(
|
||||
Type attributeType,
|
||||
bool inherit)
|
||||
{
|
||||
//todo
|
||||
return null;
|
||||
return m_base.GetCustomAttributes(attributeType, inherit);
|
||||
}
|
||||
|
||||
public override bool IsDefined(
|
||||
Type attributeType,
|
||||
bool inherit)
|
||||
{
|
||||
//todo
|
||||
return false;
|
||||
return IsDefined(attributeType, inherit);
|
||||
}
|
||||
|
||||
protected override TypeAttributes GetAttributeFlagsImpl()
|
||||
|
Reference in New Issue
Block a user