本文整理汇总了C#中InteropAccessMode类的典型用法代码示例。如果您正苦于以下问题:C# InteropAccessMode类的具体用法?C# InteropAccessMode怎么用?C# InteropAccessMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InteropAccessMode类属于命名空间,在下文中一共展示了InteropAccessMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
}
示例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();
}
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}