LibreOffice Module cli_ure (master) 1
Any.cs
Go to the documentation of this file.
1/*
2 * This file is part of the LibreOffice project.
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * This file incorporates work covered by the following license notice:
9 *
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
17 */
18
19using System;
20using System.Text;
21
22namespace uno
23{
24
31public struct Any
32{
33 private object _value;
34 private Type _type;
35
36 public static Any VOID = new Any(typeof(void), null);
37
38 private static void checkArgs(Type type, Object value)
39 {
40 //value can only be null if type == void
41 if (type == null
42 || (value == null
43 && type != typeof(void)
44 && type != typeof(object)
45 && type.IsInterface == false))
46 throw new System.Exception(
47 "uno.Any: Constructor called with illegal arguments!");
48 //If value is a polymorphic struct then type must be
49 //uno.Polymorphic
50 if (value != null)
51 {
52 TypeParametersAttribute t = (TypeParametersAttribute) Attribute.GetCustomAttribute(
53 value.GetType(), typeof(TypeParametersAttribute));
54 if (t != null && !(type is PolymorphicType))
55 throw new System.Exception(
56 "uno.Any: The value has a polymorphic type but the type argument is not " +
57 "uno.PolymorphicType. Please use the constructor Any(Type, object) and " +
58 "supply a uno.PolymorphicType as type argument!");
59 }
60 }
61
67 public Any(Type type, object value)
68 {
69 checkArgs(type, value);
70 _type = type;
71 _value = value;
72 }
73
78 public void setValue(Type type, object value)
79 {
80 checkArgs(type, value);
81 _type = type;
82 _value = value;
83 }
84
85 public Type Type
86 {
87 get
88 {
89 if (_type == null)
90 _type = typeof(void);
91 return _type;
92 }
93 }
94
95 public Object Value
96 {
97 get
98 {
99 return _value;
100 }
101 }
102
103 public Any(char value): this(typeof(char), value)
104 {
105 }
106
107 public Any(bool value): this(typeof(bool), value)
108 {
109 }
110
111 public Any(byte value): this(typeof(byte), value)
112 {
113 }
114
115 public Any(short value): this(typeof(short), value)
116 {
117 }
118
119 public Any(ushort value): this(typeof(ushort), value)
120 {
121 }
122
123 public Any(int value): this(typeof(int), value)
124 {
125 }
126
127 public Any(uint value): this(typeof(uint), value)
128 {
129 }
130
131 public Any(long value): this(typeof(long), value)
132 {
133 }
134
135 public Any(ulong value): this(typeof(ulong), value)
136 {
137 }
138
139 public Any(float value): this(typeof(float), value)
140 {
141 }
142
143 public Any(double value): this(typeof(double), value)
144 {
145 }
146
147 public Any(Type value): this(typeof(Type), value)
148 {
149 }
150
151 public Any(string value): this(typeof(string), value)
152 {
153 }
154
155 public override string ToString()
156 {
157 StringBuilder msg = new StringBuilder("uno.Any { Type= ");
158 msg.Append(Type.ToString());
159 msg.Append(", Value=");
160 msg.Append(Value.ToString());
161 msg.Append("}");
162 return msg.ToString();
163 }
164
165 public bool hasValue()
166 {
167 if (Type == null || Type == typeof(void))
168 return false;
169 return true;
170 }
171
172 public override bool Equals(object obj)
173 {
174 if (obj != null)
175 {
176 try
177 {
178 return Equals((Any) obj);
179 }
180 catch (InvalidCastException)
181 {
182 }
183 }
184 return false;
185 }
186
187 public bool Equals(Any obj)
188 {
189 return Type.Equals(obj.Type)
190 && (Value == null ?
191 obj.Value == null :
192 Value.Equals(obj.Value));
193 }
194
195 public override int GetHashCode()
196 {
197 return Type.GetHashCode() ^ (Value != null ? Value.GetHashCode() : 0);
198 }
199}
200
201}
202
XPropertyListType t
unsigned int uint
unsigned char byte
unsigned short ushort
Type
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int