• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# InteropAccessMode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: Test_ConstIntFieldSetter

		public void Test_ConstIntFieldSetter(InteropAccessMode opt)
		{
			try
			{
				string script = @"    
				myobj.ConstIntProp = 1;
				return myobj.ConstIntProp;";

				Script S = new Script();

				SomeClass obj = new SomeClass() { IntProp = 321 };

				UserData.UnregisterType<SomeClass>();
				UserData.RegisterType<SomeClass>(opt);

				S.Globals.Set("myobj", UserData.Create(obj));

				DynValue res = S.DoString(script);

				Assert.AreEqual(DataType.Number, res.Type);
				Assert.AreEqual(115, res.Number);
			}
			catch (ScriptRuntimeException)
			{
				return;
			}

			Assert.Fail();
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:29,代码来源:UserDataFieldsTests.cs


示例2: TryCreate

		private static PropertyMemberDescriptor TryCreate(PropertyInfo pi, InteropAccessMode accessMode, MethodInfo getter, MethodInfo setter)
		{
			if (getter == null && setter == null)
				return null;
			else
				return new PropertyMemberDescriptor(pi, accessMode, getter, setter);
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:7,代码来源:PropertyMemberDescriptor.cs


示例3: TryCreateIfVisible

		/// <summary>
		/// Tries to create a new StandardUserDataFieldDescriptor, returning <c>null</c> in case the field is not 
		/// visible to script code.
		/// </summary>
		/// <param name="fi">The FieldInfo.</param>
		/// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
		/// <returns>A new StandardUserDataFieldDescriptor or null.</returns>
		public static FieldMemberDescriptor TryCreateIfVisible(FieldInfo fi, InteropAccessMode accessMode)
		{
			if (fi.GetVisibilityFromAttributes() ?? fi.IsPublic)
				return new FieldMemberDescriptor(fi, accessMode);

			return null;
		}
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:14,代码来源:FieldMemberDescriptor.cs


示例4: Test_NIntPropertyGetter

		public void Test_NIntPropertyGetter(InteropAccessMode opt)
		{
			string script = @"    
				x = myobj1.NIntProp;
				y = myobj2.NIntProp;
				return x,y;";

			Script S = new Script();

			SomeClass obj1 = new SomeClass() { NIntProp = 321 };
			SomeClass obj2 = new SomeClass() { NIntProp = null };

			UserData.UnregisterType<SomeClass>();
			UserData.RegisterType<SomeClass>(opt);

			S.Globals.Set("myobj1", UserData.Create(obj1));
			S.Globals.Set("myobj2", UserData.Create(obj2));

			DynValue res = S.DoString(script);

			Assert.AreEqual(DataType.Tuple, res.Type);
			Assert.AreEqual(321.0, res.Tuple[0].Number);
			Assert.AreEqual(DataType.Number, res.Tuple[0].Type);
			Assert.AreEqual(DataType.Nil, res.Tuple[1].Type);
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:25,代码来源:UserDataPropertiesTests.cs


示例5: RegisterExtensionType

		/// <summary>
		/// Registers an extension Type (that is a type containing extension methods)
		/// </summary>
		/// <param name="type">The type.</param>
		/// <param name="mode">The InteropAccessMode.</param>
		public static void RegisterExtensionType(Type type, InteropAccessMode mode = InteropAccessMode.Default)
		{
			lock (s_Lock)
			{
				bool changesDone = false;

				foreach (MethodInfo mi in type.GetMethods().Where(_mi => _mi.IsStatic))
				{
					if (mi.GetCustomAttributes(typeof(ExtensionAttribute), false).Length == 0)
						continue;

					if (mi.ContainsGenericParameters)
					{
						s_UnresolvedGenericsRegistry.Add(mi.Name, new UnresolvedGenericMethod(mi, mode));
						changesDone = true;
						continue;
					}

					if (!MethodMemberDescriptor.CheckMethodIsCompatible(mi, false))
						continue;

					var desc = new MethodMemberDescriptor(mi, mode);

					s_Registry.Add(mi.Name, desc);
					changesDone = true;
				}

				if (changesDone)
					++s_ExtensionMethodChangeVersion;
			}
		}
开发者ID:InfectedBytes,项目名称:moonsharp,代码行数:36,代码来源:ExtensionMethodsRegistry.cs


示例6: FieldMemberDescriptor

		/// <summary>
		/// Initializes a new instance of the <see cref="PropertyMemberDescriptor"/> class.
		/// </summary>
		/// <param name="fi">The FieldInfo.</param>
		/// <param name="accessMode">The <see cref="InteropAccessMode" /> </param>
		public FieldMemberDescriptor(FieldInfo fi, InteropAccessMode accessMode)
		{
			if (Script.GlobalOptions.Platform.IsRunningOnAOT())
				accessMode = InteropAccessMode.Reflection;

			this.FieldInfo = fi;
			this.AccessMode = accessMode;
			this.Name = fi.Name;
			this.IsStatic = this.FieldInfo.IsStatic;

			if (this.FieldInfo.IsLiteral)
			{
				IsConst = true;
				m_ConstValue = FieldInfo.GetValue(null);
			}
			else
			{
				IsReadonly = this.FieldInfo.IsInitOnly;
			}

			if (AccessMode == InteropAccessMode.Preoptimized)
			{
				this.OptimizeGetter();
			}
		}
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:30,代码来源:FieldMemberDescriptor.cs


示例7: FromDelegate

		/// <summary>
		/// Creates a CallbackFunction from a delegate.
		/// </summary>
		/// <param name="script">The script.</param>
		/// <param name="del">The delegate.</param>
		/// <param name="accessMode">The access mode.</param>
		/// <returns></returns>
		public static CallbackFunction FromDelegate(Script script, Delegate del, InteropAccessMode accessMode = InteropAccessMode.Default)
		{
			if (accessMode == InteropAccessMode.Default)
				accessMode = m_DefaultAccessMode;

			MethodMemberDescriptor descr = new MethodMemberDescriptor(del.Method, accessMode);
			return descr.GetCallbackFunction(script, del.Target);
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:15,代码来源:CallbackFunction.cs


示例8: EventMemberDescriptor

 /// <summary>
 ///     Initializes a new instance of the <see cref="EventMemberDescriptor" /> class.
 /// </summary>
 /// <param name="ei">The ei.</param>
 /// <param name="accessMode">The access mode.</param>
 public EventMemberDescriptor(EventInfo ei, InteropAccessMode accessMode = InteropAccessMode.Default)
 {
     CheckEventIsCompatible(ei, true);
     EventInfo = ei;
     m_Add = ei.GetAddMethod(true);
     m_Remove = ei.GetRemoveMethod(true);
     IsStatic = m_Add.IsStatic;
 }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:13,代码来源:EventMemberDescriptor.cs


示例9: StandardGenericsUserDataDescriptor

		/// <summary>
		/// Initializes a new instance of the <see cref="StandardUserDataDescriptor"/> class.
		/// </summary>
		/// <param name="type">The type this descriptor refers to.</param>
		/// <param name="accessMode">The interop access mode this descriptor uses for members access</param>
		public StandardGenericsUserDataDescriptor(Type type, InteropAccessMode accessMode)
		{
			if (accessMode == InteropAccessMode.NoReflectionAllowed)
				throw new ArgumentException("Can't create a StandardGenericsUserDataDescriptor under a NoReflectionAllowed access mode");

			AccessMode = accessMode;
			this.Type = type;
			this.Name = "@@" + type.FullName;
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:14,代码来源:StandardGenericsUserDataDescriptor.cs


示例10: MethodMemberDescriptor

		/// <summary>
		/// Initializes a new instance of the <see cref="MethodMemberDescriptor"/> class.
		/// </summary>
		/// <param name="methodBase">The MethodBase (MethodInfo or ConstructorInfo) got through reflection.</param>
		/// <param name="accessMode">The interop access mode.</param>
		/// <exception cref="System.ArgumentException">Invalid accessMode</exception>
		public MethodMemberDescriptor(MethodBase methodBase, InteropAccessMode accessMode = InteropAccessMode.Default)
		{
			CheckMethodIsCompatible(methodBase, true);

			IsConstructor = (methodBase is ConstructorInfo);
			this.MethodInfo = methodBase;

			bool isStatic = methodBase.IsStatic || IsConstructor;

			if (IsConstructor)
				m_IsAction = false;
			else
				m_IsAction = ((MethodInfo)methodBase).ReturnType == typeof(void);

			ParameterInfo[] reflectionParams = methodBase.GetParameters();
			ParameterDescriptor[] parameters;
			
			if (this.MethodInfo.DeclaringType.IsArray)
			{
				m_IsArrayCtor = true;

				int rank = this.MethodInfo.DeclaringType.GetArrayRank();

				parameters = new ParameterDescriptor[rank];

				for (int i = 0; i < rank; i++)
					parameters[i] = new ParameterDescriptor("idx" + i.ToString(), typeof(int));
			}
			else
			{
				parameters = reflectionParams.Select(pi => new ParameterDescriptor(pi)).ToArray();
			}
		
			
			bool isExtensionMethod = (methodBase.IsStatic && parameters.Length > 0 && methodBase.GetCustomAttributes(typeof(ExtensionAttribute), false).Any());

			base.Initialize(methodBase.Name, isStatic, parameters, isExtensionMethod);

			// adjust access mode
			if (Script.GlobalOptions.Platform.IsRunningOnAOT())
				accessMode = InteropAccessMode.Reflection;

			if (accessMode == InteropAccessMode.Default)
				accessMode = UserData.DefaultAccessMode;

			if (accessMode == InteropAccessMode.HideMembers)
				throw new ArgumentException("Invalid accessMode");

			if (parameters.Any(p => p.Type.IsByRef))
				accessMode = InteropAccessMode.Reflection;

			this.AccessMode = accessMode;

			if (AccessMode == InteropAccessMode.Preoptimized)
				((IOptimizableDescriptor)this).Optimize();
		}
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:62,代码来源:MethodMemberDescriptor.cs


示例11: TryCreateIfVisible

		/// <summary>
		/// Tries to create a new StandardUserDataEventDescriptor, returning <c>null</c> in case the method is not 
		/// visible to script code.
		/// </summary>
		/// <param name="ei">The EventInfo.</param>
		/// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
		/// <returns>A new StandardUserDataEventDescriptor or null.</returns>
		public static EventMemberDescriptor TryCreateIfVisible(EventInfo ei, InteropAccessMode accessMode)
		{
			if (!CheckEventIsCompatible(ei, false))
				return null;

			if (ei.GetVisibilityFromAttributes() ?? (ei.GetAddMethod().IsPublic && ei.GetRemoveMethod().IsPublic))
				return new EventMemberDescriptor(ei, accessMode);

			return null;
		}
开发者ID:InfectedBytes,项目名称:moonsharp,代码行数:17,代码来源:EventMemberDescriptor.cs


示例12: TryCreateIfVisible

		/// <summary>
		/// Tries to create a new StandardUserDataEventDescriptor, returning <c>null</c> in case the method is not 
		/// visible to script code.
		/// </summary>
		/// <param name="ei">The EventInfo.</param>
		/// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
		/// <returns>A new StandardUserDataEventDescriptor or null.</returns>
		public static EventMemberDescriptor TryCreateIfVisible(EventInfo ei, InteropAccessMode accessMode)
		{
			if (!CheckEventIsCompatible(ei, false))
				return null;

	        MethodInfo addm = ei.GetAddMethod();
	        MethodInfo remm = ei.GetRemoveMethod();

	        if (ei.GetVisibilityFromAttributes() ?? ((remm != null && remm.IsPublic) && (addm != null && addm.IsPublic)))
	            return new EventMemberDescriptor(ei, accessMode);

			return null;
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:20,代码来源:EventMemberDescriptor.cs


示例13: StandardUserDataDescriptor

		/// <summary>
		/// Initializes a new instance of the <see cref="StandardUserDataDescriptor"/> class.
		/// </summary>
		/// <param name="type">The type this descriptor refers to.</param>
		/// <param name="accessMode">The interop access mode this descriptor uses for members access</param>
		/// <param name="friendlyName">A human readable friendly name of the descriptor.</param>
		public StandardUserDataDescriptor(Type type, InteropAccessMode accessMode, string friendlyName = null)
			: base(type, friendlyName)
		{
			if (accessMode == InteropAccessMode.NoReflectionAllowed)
				throw new ArgumentException("Can't create a StandardUserDataDescriptor under a NoReflectionAllowed access mode");

			if (Script.GlobalOptions.Platform.IsRunningOnAOT())
				accessMode = InteropAccessMode.Reflection;

			if (accessMode == InteropAccessMode.Default)
				accessMode = UserData.DefaultAccessMode;

			AccessMode = accessMode;

			FillMemberList();
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:22,代码来源:StandardUserDataDescriptor.cs


示例14: Test_IntPropertyGetter

		public void Test_IntPropertyGetter(InteropAccessMode opt)
		{
			string script = @"    
				x = myobj.IntProp;
				return x;";

			Script S = new Script();

			SomeClass obj = new SomeClass() { IntProp = 321 };

			UserData.UnregisterType<SomeClass>();
			UserData.RegisterType<SomeClass>(opt);

			S.Globals.Set("myobj", UserData.Create(obj));

			DynValue res = S.DoString(script);

			Assert.AreEqual(DataType.Number, res.Type);
			Assert.AreEqual(321, res.Number);
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:20,代码来源:UserDataPropertiesTests.cs


示例15: MethodMemberDescriptor

        /// <summary>
        ///     Initializes a new instance of the <see cref="MethodMemberDescriptor" /> class.
        /// </summary>
        /// <param name="methodBase">The MethodBase (MethodInfo or ConstructorInfo) got through reflection.</param>
        /// <param name="accessMode">The interop access mode.</param>
        /// <exception cref="System.ArgumentException">Invalid accessMode</exception>
        public MethodMemberDescriptor(MethodBase methodBase, InteropAccessMode accessMode = InteropAccessMode.Default)
        {
            CheckMethodIsCompatible(methodBase, true);

            IsConstructor = (methodBase is ConstructorInfo);
            MethodInfo = methodBase;

            var isStatic = methodBase.IsStatic || IsConstructor;

            if (IsConstructor)
                m_IsAction = false;
            else
                m_IsAction = ((MethodInfo) methodBase).ReturnType == typeof (void);

            var reflectionParams = methodBase.GetParameters();
            var parameters = reflectionParams.Select(pi => new ParameterDescriptor(pi)).ToArray();

            var isExtensionMethod = (methodBase.IsStatic && parameters.Length > 0 &&
                                     methodBase.GetCustomAttributes(typeof (ExtensionAttribute), false).Any());

            Initialize(methodBase.Name, isStatic, parameters, isExtensionMethod);

            // adjust access mode
            if (Script.GlobalOptions.Platform.IsRunningOnAOT())
                accessMode = InteropAccessMode.Reflection;

            if (accessMode == InteropAccessMode.Default)
                accessMode = UserData.DefaultAccessMode;

            if (accessMode == InteropAccessMode.HideMembers)
                throw new ArgumentException("Invalid accessMode");

            if (parameters.Any(p => p.Type.IsByRef))
                accessMode = InteropAccessMode.Reflection;

            AccessMode = accessMode;

            if (AccessMode == InteropAccessMode.Preoptimized)
                ((IOptimizableDescriptor) this).Optimize();
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:46,代码来源:MethodMemberDescriptor.cs


示例16: TryCreateIfVisible

		/// <summary>
		/// Tries to create a new StandardUserDataPropertyDescriptor, returning <c>null</c> in case the property is not 
		/// visible to script code.
		/// </summary>
		/// <param name="pi">The PropertyInfo.</param>
		/// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
		/// <returns>A new StandardUserDataPropertyDescriptor or null.</returns>
		public static PropertyMemberDescriptor TryCreateIfVisible(PropertyInfo pi, InteropAccessMode accessMode)
		{
			MethodInfo getter = pi.GetGetMethod(true);
			MethodInfo setter = pi.GetSetMethod(true);

			bool? pvisible = pi.GetVisibilityFromAttributes();
			bool? gvisible = getter.GetVisibilityFromAttributes();
			bool? svisible = setter.GetVisibilityFromAttributes();

			if (pvisible.HasValue)
			{
				return PropertyMemberDescriptor.TryCreate(pi, accessMode,
					(gvisible ?? pvisible.Value) ? getter : null,
					(svisible ?? pvisible.Value) ? setter : null);
			}
			else 
			{
				return PropertyMemberDescriptor.TryCreate(pi, accessMode,
					(gvisible ?? getter.IsPublic) ? getter : null,
					(svisible ?? setter.IsPublic) ? setter : null);
			}
		}
开发者ID:eddy5641,项目名称:LuaSharp,代码行数:29,代码来源:PropertyMemberDescriptor.cs


示例17: PropertyMemberDescriptor

        /// <summary>
        ///     Initializes a new instance of the <see cref="PropertyMemberDescriptor" /> class.
        /// </summary>
        /// <param name="pi">The PropertyInfo.</param>
        /// <param name="accessMode">The <see cref="InteropAccessMode" /></param>
        /// <param name="getter">The getter method. Use null to make the property writeonly.</param>
        /// <param name="setter">The setter method. Use null to make the property readonly.</param>
        public PropertyMemberDescriptor(PropertyInfo pi, InteropAccessMode accessMode, MethodInfo getter,
            MethodInfo setter)
        {
            if (getter == null && setter == null)
                throw new ArgumentNullException("getter and setter cannot both be null");

            if (Script.GlobalOptions.Platform.IsRunningOnAOT())
                accessMode = InteropAccessMode.Reflection;

            PropertyInfo = pi;
            AccessMode = accessMode;
            Name = pi.Name;

            m_Getter = getter;
            m_Setter = setter;

            IsStatic = (m_Getter ?? m_Setter).IsStatic;

            if (AccessMode == InteropAccessMode.Preoptimized)
            {
                OptimizeGetter();
                OptimizeSetter();
            }
        }
开发者ID:eddy5641,项目名称:moonsharp,代码行数:31,代码来源:PropertyMemberDescriptor.cs


示例18: Test_PropertyAccessOverrides

		public void Test_PropertyAccessOverrides(InteropAccessMode opt)
		{
			SomeClass obj = new SomeClass();

			try
			{
				string script = @"    
				myobj.AccessOverrProp = 19;
				return myobj.AccessOverrProp;
			";

				Script S = new Script();

				obj.AccessOverrProp = 13;

				UserData.UnregisterType<SomeClass>();
				UserData.RegisterType<SomeClass>(opt);

				S.Globals.Set("myobj", UserData.Create(obj));

				DynValue res = S.DoString(script);
			}
			catch (ScriptRuntimeException)
			{
				Assert.AreEqual(19, obj.AccessOverrProp);
				return;
			}

			Assert.Fail();
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:30,代码来源:UserDataPropertiesTests.cs


示例19: Test_WoIntProperty2Setter

		public void Test_WoIntProperty2Setter(InteropAccessMode opt)
		{
			string script = @"    
				myobj.WoIntProp2 = 19;
			";

			Script S = new Script();

			SomeClass obj = new SomeClass();

			UserData.UnregisterType<SomeClass>();
			UserData.RegisterType<SomeClass>(opt);

			S.Globals.Set("myobj", UserData.Create(obj));

			DynValue res = S.DoString(script);

			Assert.AreEqual(19, obj.WoIntProp2);
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:19,代码来源:UserDataPropertiesTests.cs


示例20: Test_RoIntProperty2Setter

		public void Test_RoIntProperty2Setter(InteropAccessMode opt)
		{
			try
			{
				string script = @"    
				myobj.RoIntProp2 = 19;
				return myobj.RoIntProp2;
			";

				Script S = new Script();

				SomeClass obj = new SomeClass();

				UserData.UnregisterType<SomeClass>();
				UserData.RegisterType<SomeClass>(opt);

				S.Globals.Set("myobj", UserData.Create(obj));

				DynValue res = S.DoString(script);
			}
			catch (ScriptRuntimeException)
			{
				return;
			}

			Assert.Fail();
		}
开发者ID:cyecp,项目名称:moonsharp,代码行数:27,代码来源:UserDataPropertiesTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# InteropFFTWFlags类代码示例发布时间:2022-05-24
下一篇:
C# WinHttp.SafeWinHttpHandle类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap