当前位置: 首页>>代码示例>>C#>>正文


C# Mono.Value类代码示例

本文整理汇总了C#中Mono.Value的典型用法代码示例。如果您正苦于以下问题:C# Value类的具体用法?C# Value怎么用?C# Value使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Value类属于Mono命名空间,在下文中一共展示了Value类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetMethodForAttachedProperty

		private unsafe MethodInfo GetMethodForAttachedProperty (Value *top_level, string xmlns, string type_name, string full_type_name, string prop_name, string method_prefix, Type [] arg_types)
		{
			string assembly_name = AssemblyNameFromXmlns (xmlns);
			string ns = ClrNamespaceFromXmlns (xmlns);
				
			if (assembly_name == null && !TryGetDefaultAssemblyName (top_level, out assembly_name)) {
				Console.Error.WriteLine ("Unable to find an assembly to load type from.");
				return null;
			}

			Assembly clientlib;
			if (LoadAssembly (assembly_name, out clientlib) != AssemblyLoadResult.Success) {
				Console.Error.WriteLine ("couldn't load assembly:  {0}   namespace:  {1}", assembly_name, ns);
				return null;
			}

			Type attach_type = clientlib.GetType (full_type_name, false);
			if (attach_type == null) {
				attach_type = Application.GetComponentTypeFromName (type_name);
				if (attach_type == null) {
					Console.Error.WriteLine ("attach type is null type name: {0} full type name: {1}", type_name, full_type_name);
					return null;
				}
			}

			MethodInfo [] methods = attach_type.GetMethods (BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

			string method_name = String.Concat (method_prefix, prop_name);
			foreach (MethodInfo method in methods) {

				if (method.Name != method_name)
					continue;

				ParameterInfo [] the_params = method.GetParameters ();
				if (the_params.Length != arg_types.Length)
					continue;

				bool match = true;
				for (int i = 0; i < arg_types.Length; i++) {
					if (!arg_types [i].IsAssignableFrom (the_params [i].ParameterType)) {
						Console.WriteLine ("NOT A MATCH:  {0} -- {1} : {2}", method, arg_types [i], the_params [i]);
						match = false;
						break;
					}
				}

				if (match)
					return method;
			}

			return null;
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:52,代码来源:ManagedXamlLoader.cs

示例2: ParseTemplate

		private static unsafe IntPtr ParseTemplate (Value *context_ptr, string resource_base, IntPtr surface, IntPtr binding_source, string xaml, ref MoonError error)
		{
			XamlContext context = Value.ToObject (typeof (XamlContext), context_ptr) as XamlContext;

			var parser = new XamlParser (context);

			var source = NativeDependencyObjectHelper.FromIntPtr (binding_source);
			if (source == null) {
				error = new MoonError (parser.ParseException ("Attempting to parse a template with an invalid binding source."));
				return IntPtr.Zero;
			}

			FrameworkElement fwe = source as FrameworkElement;
			if (fwe == null) {
				error = new MoonError (parser.ParseException ("Only FrameworkElements can be used as TemplateBinding sources."));
				return IntPtr.Zero;
			}

			context.IsExpandingTemplate = true;
			context.TemplateBindingSource = fwe;

			INativeEventObjectWrapper dob = null;
			try {
				dob = parser.ParseString (xaml) as INativeEventObjectWrapper;
			} catch (Exception e) {
				error = new MoonError (e);
				return IntPtr.Zero;
			}

			if (dob == null) {
				error = new MoonError (parser.ParseException ("Unable to parse template item."));
				return IntPtr.Zero;
			}

			return dob.NativeHandle;
		}
开发者ID:shana,项目名称:moon,代码行数:36,代码来源:XamlParser.cs

示例3: FromObject

		//
		// How do we support "null" values, should the caller take care of that?
		//
		// The caller is responsible for calling value_free_value on the returned Value
		public static Value FromObject (object v, bool box_value_types)
		{
			Value value = new Value ();
			
			unsafe {
				// get rid of this case right away.
				if (box_value_types && v.GetType().IsValueType) {
					//Console.WriteLine ("Boxing a value of type {0}:", v.GetType());

					GCHandle handle = GCHandle.Alloc (v);
					value.k = Deployment.Current.Types.TypeToKind (v.GetType ());
					value.IsGCHandle = true;
					value.u.p = GCHandle.ToIntPtr (handle);
					return value;
				}

				if (v is IEasingFunction && !(v is EasingFunctionBase))
					v = new EasingFunctionWrapper (v as IEasingFunction);

				if (v is INativeEventObjectWrapper) {
					INativeEventObjectWrapper dov = (INativeEventObjectWrapper) v;

					if (dov.NativeHandle == IntPtr.Zero)
						throw new Exception (String.Format (
							"Object {0} has not set its native property", dov.GetType()));

					NativeMethods.event_object_ref (dov.NativeHandle);

					value.k = dov.GetKind ();
					value.u.p = dov.NativeHandle;

				} else if (v is DependencyProperty) {
					value.k = Kind.DEPENDENCYPROPERTY;
					value.u.p = ((DependencyProperty)v).Native;
				}
				else if (v is int || (v.GetType ().IsEnum && Enum.GetUnderlyingType (v.GetType()) == typeof(int))) {
					value.k = Deployment.Current.Types.TypeToKind (v.GetType ());
					value.u.i32 = (int) v;
				}
				else if (v is bool) {
					value.k = Kind.BOOL;
					value.u.i32 = ((bool) v) ? 1 : 0;
				}
				else if (v is double) {
					value.k = Kind.DOUBLE;
					value.u.d = (double) v;
				}
				else if (v is float) {
					value.k = Kind.FLOAT;
					value.u.f = (float) v;
				}
				else if (v is long) {
					value.k = Kind.INT64;
					value.u.i64 = (long) v;
				}
				else if (v is TimeSpan) {
					TimeSpan ts = (TimeSpan) v;
					value.k = Kind.TIMESPAN;
					value.u.i64 = ts.Ticks;
				}
				else if (v is ulong) {
					value.k = Kind.UINT64;
					value.u.ui64 = (ulong) v;
				}
				else if (v is uint) {
					value.k = Kind.UINT32;
					value.u.ui32 = (uint) v;
				}
				else if (v is char) {
					value.k = Kind.CHAR;
					value.u.ui32 = (uint) (char) v;
				}
				else if (v is string) {
					value.k = Kind.STRING;

					value.u.p = StringToIntPtr ((string) v);
				}
				else if (v is Rect) {
					Rect rect = (Rect) v;
					value.k = Kind.RECT;
					value.u.p = Marshal.AllocHGlobal (sizeof (Rect));
					Marshal.StructureToPtr (rect, value.u.p, false); // Unmanaged and managed structure layout is equal.
				}
				else if (v is Size) {
					Size size = (Size) v;
					value.k = Kind.SIZE;
					value.u.p = Marshal.AllocHGlobal (sizeof (Size));
					Marshal.StructureToPtr (size, value.u.p, false); // Unmanaged and managed structure layout is equal.
				}
				else if (v is CornerRadius) {
					CornerRadius corner = (CornerRadius) v;
					value.k = Kind.CORNERRADIUS;
					value.u.p = Marshal.AllocHGlobal (sizeof (CornerRadius));
					Marshal.StructureToPtr (corner, value.u.p, false); // Unmanaged and managed structure layout is equal.
				}
				else if (v is AudioFormat) {
//.........这里部分代码省略.........
开发者ID:shana,项目名称:moon,代码行数:101,代码来源:Value.cs

示例4: Hydrate

		public void Hydrate (Value value, string xaml, bool createNamescope, bool validateTemplates, bool import_default_xmlns)
		{
			HydrateInternal (value, xaml, createNamescope, validateTemplates, import_default_xmlns);
		}
开发者ID:shana,项目名称:moon,代码行数:4,代码来源:XamlLoaderCallbacks.cs

示例5: RegisterAny

        private static DependencyProperty RegisterAny(string name, Type propertyType, Type ownerType, PropertyMetadata metadata, bool attached, bool readOnly, bool setsParent, bool custom)
        {
            ManagedType property_type;
            ManagedType owner_type;
            UnmanagedPropertyChangeHandler handler = null;
            CustomDependencyProperty result;
            bool is_nullable = false;
            object default_value = DependencyProperty.UnsetValue;
            PropertyChangedCallback property_changed_callback = null;

            if (name == null)
                throw new ArgumentNullException ("name");

            if (name.Length == 0)
                throw new ArgumentException("The 'name' argument cannot be an empty string");

            if (propertyType == null)
                throw new ArgumentNullException ("propertyType");

            if (ownerType == null)
                throw new ArgumentNullException ("ownerType");

            if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition () == typeof (Nullable<>)) {
                is_nullable = true;
                // Console.WriteLine ("DependencyProperty.RegisterAny (): found nullable {0}, got nullable {1}", propertyType.FullName, propertyType.GetGenericArguments () [0].FullName);
                propertyType = propertyType.GetGenericArguments () [0];
            }

            Types types = Deployment.Current.Types;

            property_type = types.Find (propertyType);
            owner_type = types.Find (ownerType);

            if (metadata != null) {
                default_value = metadata.DefaultValue ?? UnsetValue;
                property_changed_callback = metadata.property_changed_callback;
            }

            if ((default_value == DependencyProperty.UnsetValue) && propertyType.IsValueType && !is_nullable)
                default_value = Activator.CreateInstance (propertyType);

            if (default_value != null && default_value != UnsetValue && !propertyType.IsAssignableFrom (default_value.GetType ()))
                throw new ArgumentException (string.Format ("DefaultValue is of type {0} which is not compatible with type {1}", default_value.GetType (), propertyType));

            if (property_changed_callback != null)
                handler = UnmanagedPropertyChangedCallbackSafe;

            Value v;
            if (default_value == DependencyProperty.UnsetValue) {
                v = new Value { k = types.TypeToKind (propertyType), IsNull = true };
                default_value = null;
            } else {
                v = Value.FromObject (default_value, true);
            }

            IntPtr handle;
            using (v) {
                var val = v;
                if (custom)
                    handle = NativeMethods.dependency_property_register_custom_property (name, property_type.native_handle, owner_type.native_handle, ref val, attached, readOnly, handler);
                else
                    handle = NativeMethods.dependency_property_register_core_property (name, property_type.native_handle, owner_type.native_handle, ref val, attached, readOnly, handler);
            }

            if (handle == IntPtr.Zero)
                return null;

            if (is_nullable)
                NativeMethods.dependency_property_set_is_nullable (handle, true);

            result = new CustomDependencyProperty (handle, name, property_type, owner_type, default_value);
            result.attached = attached;
            result.PropertyChangedHandler = handler;
            result.property_changed_callback = property_changed_callback;

            return result;
        }
开发者ID:Clancey,项目名称:ClanceyLib,代码行数:77,代码来源:DependencyProperty.cs

示例6: AddChild

		private unsafe bool AddChild (XamlCallbackData *data, Value* parent_parent_ptr, bool parent_is_property, string parent_xmlns, Value *parent_ptr, IntPtr parent_data, Value* child_ptr, IntPtr child_data)
		{
			object parent = Value.ToObject (null, parent_ptr);
			object child = Value.ToObject (null, child_ptr);

			if (parent_is_property) {
				object parent_parent = Value.ToObject (null, parent_parent_ptr);
				return AddChildToProperty (data, parent_parent, parent_xmlns, parent, child, child_data);
			}

			return AddChildToItem (data, parent_parent_ptr, parent, parent_data, child_ptr, child, child_data);
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:12,代码来源:ManagedXamlLoader.cs

示例7: LookupObject

		private unsafe bool LookupObject (Value *top_level, Value *parent, string xmlns, string name, bool create, bool is_property, out Value value)
		{
			if (name == null)
				throw new ArgumentNullException ("type_name");

			
			if (is_property) {
				int dot = name.IndexOf ('.');
				return LookupPropertyObject (top_level, parent, xmlns, name, dot, create, out value);
			}

			if (top_level == null && xmlns == null) {
				return LookupComponentFromName (top_level, name, create, out value);
			}

			string assembly_name = AssemblyNameFromXmlns (xmlns);
			string clr_namespace = ClrNamespaceFromXmlns (xmlns);
			string full_name = string.IsNullOrEmpty (clr_namespace) ? name : clr_namespace + "." + name;

			Type type = LookupType (top_level, assembly_name, full_name);
			if (type == null) {
				Console.Error.WriteLine ("ManagedXamlLoader::LookupObject: GetType ({0}) failed using assembly: {1} ({2}, {3}).", name, assembly_name, xmlns, full_name);
				value = Value.Empty;
				return false;
			}

			if (create) {

				if (!type.IsPublic) {
					value = Value.Empty;
					throw new XamlParseException ("Attempting to create a private type");
				}

				object res = null;
				try {
					res = Activator.CreateInstance (type);
				} catch (TargetInvocationException ex) {
					Console.WriteLine (ex);
					Console.Error.WriteLine ("ManagedXamlLoader::LookupObject: CreateInstance ({0}) failed: {1}", name, ex.InnerException);
					value = Value.Empty;
					return false;
				}

				if (res == null) {
					Console.Error.WriteLine ("ManagedXamlLoader::LookupObject ({0}, {1}, {2}): unable to create object instance: '{3}', the object was of type '{4}'",
								 assembly_name, xmlns, name, full_name, type.FullName);
					value = Value.Empty;
					return false;
				}
				// This is freed in native.
				value = Value.FromObject (res, false);
			} else {
				value = Value.Empty;
				value.k = Deployment.Current.Types.Find (type).native_handle;
			}

			return true;
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:58,代码来源:ManagedXamlLoader.cs

示例8: LookupPropertyObject

		private unsafe bool LookupPropertyObject (Value* top_level, Value* parent_value, string xmlns, string name, int dot, bool create, out Value value)
		{
			string prop_name = name.Substring (dot + 1);
			object parent = Value.ToObject (null, parent_value);

			if (parent == null) {
				value = Value.Empty;
				return false;
			}

			PropertyInfo pi = null;
			bool is_attached = true;
			string type_name = name.Substring (0, dot);

			Type t = parent.GetType ();
			while (t != typeof (object)) {
				if (t.Name == type_name) {
					is_attached = false;
					break;
				}
				t = t.BaseType;
			}

			if (is_attached) {
				Type attach_type = null;
				string full_type_name = type_name;
				if (xmlns != null) {
					string ns = ClrNamespaceFromXmlns (xmlns);
					full_type_name = String.Concat (ns, ".", type_name);
				}

				MethodInfo get_method = GetGetMethodForAttachedProperty (top_level, xmlns, type_name, full_type_name, prop_name);

				if (get_method != null)
					attach_type = get_method.ReturnType;

				if (attach_type == null) {
					value = Value.Empty;
					return false;
				}

				ManagedType mt = Deployment.Current.Types.Find (attach_type);
				value = Value.Empty;
				value.IsNull = true;
				value.k = mt.native_handle;
				return true;
			} else {
				pi = parent.GetType ().GetProperty (name.Substring (dot + 1), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy);

				if (pi == null) {
					value = Value.Empty;
					return false;
				}

				ManagedType mt = Deployment.Current.Types.Find (pi.PropertyType);
				value = Value.Empty;
				value.k = mt.native_handle;
				value.IsNull = true;

				return true;
			}
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:62,代码来源:ManagedXamlLoader.cs

示例9: cb_add_child

		private unsafe bool cb_add_child (XamlCallbackData *data, Value* parent_parent, bool parent_is_property, string parent_xmlns, Value *parent, IntPtr parent_data, Value* child, IntPtr child_data, ref MoonError error)
		{
			try {
				return AddChild (data, parent_parent, parent_is_property, parent_xmlns, parent, parent_data, child, child_data);
			} catch (Exception ex) {
				Console.Error.WriteLine (ex);
				error = new MoonError (ex);
				return false;
			}
				
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:11,代码来源:ManagedXamlLoader.cs

示例10: TryGetDefaultAssemblyName

		private unsafe bool TryGetDefaultAssemblyName (Value* top_level, out string assembly_name)
		{
			if (assembly != null) {
				assembly_name = assembly.GetName ().Name;
				return true;
			}

			object obj = Value.ToObject (null, top_level);

			if (obj == null) {
				assembly_name = null;
				return false;
			}

			assembly_name = obj.GetType ().Assembly.GetName ().Name;
			return true;
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:17,代码来源:ManagedXamlLoader.cs

示例11: cb_set_property

		//
		// Proxy so that we return bool in case of any failures, instead of
		// generating an exception and unwinding the stack.
		//
		private unsafe bool cb_set_property (XamlCallbackData *data, string xmlns, Value* target, IntPtr target_data, Value* target_parent, string prop_xmlns, string name, Value* value_ptr, IntPtr value_data, ref MoonError error)
		{
			try {
				return SetProperty (data, xmlns, target, target_data, target_parent, prop_xmlns, name, value_ptr, value_data);
			} catch (Exception ex) {
				try {
					Console.Error.WriteLine ("ManagedXamlLoader::SetProperty ({0}, {1}, {2}, {3}, {4}) threw an exception: {5}", (IntPtr) data->top_level, xmlns, (IntPtr)target, name, (IntPtr)value_ptr, ex.Message);
					Console.Error.WriteLine (ex);
					error = new MoonError (ex);
					return false;
				}
				catch {
					return false;
				}
			}
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:20,代码来源:ManagedXamlLoader.cs

示例12: cb_lookup_object

		///
		///
		/// Callbacks invoked by the xaml.cpp C++ parser
		///
		///

#region Callbacks from xaml.cpp
		//
		// Proxy so that we return IntPtr.Zero in case of any failures, instead of
		// genereting an exception and unwinding the stack.
		//
		private unsafe bool cb_lookup_object (XamlCallbackData *data, Value* parent, string xmlns, string name, bool create, bool is_property, out Value value, ref MoonError error)
		{
			value = Value.Empty;
			try {
				return LookupObject (data->top_level, parent, xmlns, name, create, is_property, out value);
			} catch (Exception ex) {
				NativeMethods.value_free_value (ref value);
				value = Value.Empty;
				Console.Error.WriteLine ("ManagedXamlLoader::LookupObject ({0}, {1}, {2}, {3}) failed: {3} ({4}).", (IntPtr) data->top_level, xmlns, create, name, ex.Message, ex.GetType ().FullName);
				Console.WriteLine (ex);
				error = new MoonError (ex);
				return false;
			}
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:25,代码来源:ManagedXamlLoader.cs

示例13: GetObjectValue

		private static unsafe object GetObjectValue (object target, IntPtr target_data, string prop_name, IntPtr parser, Value* value_ptr, out string error)
		{
			error = null;

			IntPtr unmanaged_value = IntPtr.Zero;
			object o_value = Value.ToObject (null, value_ptr);
			if (error == null && unmanaged_value != IntPtr.Zero)
				o_value = Value.ToObject (null, unmanaged_value);

			if (o_value is String && SL3MarkupExpressionParser.IsStaticResource ((string) o_value)) {
				MarkupExpressionParser mp = new SL3MarkupExpressionParser ((DependencyObject) target, prop_name, parser, target_data);
				string str_value = o_value as String;
				o_value = mp.ParseExpression (ref str_value);
			}

			return o_value;
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:17,代码来源:ManagedXamlLoader.cs

示例14: TrySetObjectTextProperty

		private unsafe bool TrySetObjectTextProperty (XamlCallbackData *data, string xmlns, object target, Value* target_ptr, IntPtr target_data, Value* value_ptr, IntPtr value_data)
		{
			object obj_value = Value.ToObject (null, value_ptr);
			string str_value = obj_value as string;

			if (str_value == null)
				return false;
			
			string assembly_name = AssemblyNameFromXmlns (xmlns);
			string clr_namespace = ClrNamespaceFromXmlns (xmlns);
			string type_name = NativeMethods.xaml_get_element_name (data->parser, target_data);
			string full_name = String.IsNullOrEmpty (clr_namespace) ? type_name : clr_namespace + "." + type_name;

			Type type = LookupType (data->top_level, assembly_name, full_name);

			if (type == null || type.IsSubclassOf (typeof (DependencyObject)))
				return false;

			// For now just trim the string right here, in the future this should probably be done in the xaml parser
			object e = ConvertType (null, type, str_value.Trim ());

			NativeMethods.value_free_value2 ((IntPtr)target_ptr);

			unsafe {
				Value *val = (Value *) target_ptr;

				GCHandle handle = GCHandle.Alloc (e);
				val->IsGCHandle = true;
				val->k = Deployment.Current.Types.TypeToKind (e.GetType ());
				val->u.p = GCHandle.ToIntPtr (handle);
			}

			return true;
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:34,代码来源:ManagedXamlLoader.cs

示例15: LookupComponentFromName

		private unsafe bool LookupComponentFromName (Value* top_level, string name, bool create, out Value value)
		{
			if (!create) {
				Type type = Application.GetComponentTypeFromName (name);
				if (type == null) {
					value = Value.Empty;
					return false;
				}
				value = Value.Empty;
				value.k = Deployment.Current.Types.Find (type).native_handle;
				return true;
			}

			object obj = Application.CreateComponentFromName (name);
			if (obj == null) {
				value = Value.Empty;
				return false;
			}

			value = Value.FromObject (obj, false);
			return true;
		}
开发者ID:fmaulanaa,项目名称:moon,代码行数:22,代码来源:ManagedXamlLoader.cs


注:本文中的Mono.Value类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。