本文整理汇总了C#中System.Type.MakeByRefType方法的典型用法代码示例。如果您正苦于以下问题:C# Type.MakeByRefType方法的具体用法?C# Type.MakeByRefType怎么用?C# Type.MakeByRefType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.MakeByRefType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateStaticDeserializerStub
public static MethodBuilder GenerateStaticDeserializerStub(TypeBuilder tb, Type type)
{
var mb = tb.DefineMethod("Deserialize", MethodAttributes.Public | MethodAttributes.Static, null, new Type[] { typeof(Stream), type.MakeByRefType() });
mb.DefineParameter(1, ParameterAttributes.None, "stream");
mb.DefineParameter(2, ParameterAttributes.Out, "value");
return mb;
}
示例2: RedirectMethod
private static Tuple<MethodInfo, Redirector> RedirectMethod(Type targetType, MethodInfo detour, bool reverse)
{
var parameters = detour.GetParameters();
Type[] types;
if (parameters.Length > 0 && (
(!targetType.IsValueType && parameters[0].ParameterType == targetType) ||
(targetType.IsValueType && parameters[0].ParameterType == targetType.MakeByRefType())))
{
types = parameters.Skip(1).Select(p => p.ParameterType).ToArray();
}
else {
types = parameters.Select(p => p.ParameterType).ToArray();
}
MethodInfo originalMethod = originalMethod = targetType.GetMethod(detour.Name, MethodFlags, null, types, null);
if (originalMethod == null && detour.Name.EndsWith("Alt"))
{
originalMethod = targetType.GetMethod(detour.Name.Substring(0, detour.Name.Length - 3), MethodFlags, null, types, null);
}
var redirector = reverse ? new Redirector(detour, originalMethod) : new Redirector(originalMethod, detour);
redirector.Apply();
return Tuple.New(originalMethod, redirector);
}
示例3: GetPrimitives
public static bool GetPrimitives(Type containerType, Type type, out MethodInfo writer, out MethodInfo reader)
{
if (type.IsEnum)
type = Enum.GetUnderlyingType(type);
if (type.IsGenericType == false)
{
writer = containerType.GetMethod("WritePrimitive", BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding, null,
new Type[] { typeof(Stream), type }, null);
reader = containerType.GetMethod("ReadPrimitive", BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding, null,
new Type[] { typeof(Stream), type.MakeByRefType() }, null);
}
else
{
var genType = type.GetGenericTypeDefinition();
writer = GetGenWriter(containerType, genType);
reader = GetGenReader(containerType, genType);
}
if (writer == null && reader == null)
return false;
else if (writer != null && reader != null)
return true;
else
throw new InvalidOperationException(String.Format("Missing a {0}Primitive() for {1}",
reader == null ? "Read" : "Write", type.FullName));
}
示例4: InitializeTypes
private static void InitializeTypes(Action<string> errorHandler)
{
if (_typesInitialized)
{
return;
}
try
{
Assembly extensionManagerAssembly = AppDomain.CurrentDomain.GetAssemblies()
.First(a => a.FullName.StartsWith("Microsoft.VisualStudio.ExtensionManager,"));
_sVsExtensionManagerType =
extensionManagerAssembly.GetType("Microsoft.VisualStudio.ExtensionManager.SVsExtensionManager");
_iVsExtensionManagerType =
extensionManagerAssembly.GetType("Microsoft.VisualStudio.ExtensionManager.IVsExtensionManager");
_iInstalledExtensionType =
extensionManagerAssembly.GetType("Microsoft.VisualStudio.ExtensionManager.IInstalledExtension");
_tryGetInstalledExtensionMethod = _iVsExtensionManagerType.GetMethod("TryGetInstalledExtension",
new[] { typeof(string), _iInstalledExtensionType.MakeByRefType() });
_installPathProperty = _iInstalledExtensionType.GetProperty("InstallPath", typeof(string));
if (_installPathProperty == null || _tryGetInstalledExtensionMethod == null ||
_sVsExtensionManagerType == null)
{
throw new Exception();
}
_typesInitialized = true;
}
catch
{
// if any of the types or methods cannot be loaded throw an error. this indicates that some API in
// Microsoft.VisualStudio.ExtensionManager got changed.
errorHandler(VsResources.PreinstalledPackages_ExtensionManagerError);
}
}
示例5: GenerateDynamicDeserializerStub
static DynamicMethod GenerateDynamicDeserializerStub(Type type) {
var dm = new DynamicMethod("Deserialize", null,
new Type[] { typeof(Stream), type.MakeByRefType() },
typeof(Serializer), true);
dm.DefineParameter(1, ParameterAttributes.None, "stream");
dm.DefineParameter(2, ParameterAttributes.Out, "value");
return dm;
}
示例6: MakeByRef
public static Type MakeByRef (Type t)
{
var mt = t as MetadataType;
if (mt != null) {
mt.m_isByRef = true;
return mt;
}
return t.MakeByRefType ();
}
示例7: TrampolineParameter
/// <summary>
/// Initializes a new instance of the <see cref="TrampolineParameter"/> class.
/// </summary>
/// <param name="type">The type of the parameter.</param>
/// <param name="flags">Flags specifying the behavior of the parameter.</param>
public TrampolineParameter(Type type, TrampolineParameterFlags flags)
{
if (type == null)
throw new ArgumentNullException("type");
if (flags.HasFlag(TrampolineParameterFlags.Reference))
Type = type.MakeByRefType();
else
Type = type;
}
示例8: GetStaticMethods
public void GetStaticMethods(Type type, out MethodInfo writer, out MethodInfo reader)
{
writer = typeof(CustomSerializers).GetMethod("WritePrimitive",
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.ExactBinding, null,
new Type[] { typeof(Stream), type }, null);
reader = typeof(CustomSerializers).GetMethod("ReadPrimitive",
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.ExactBinding, null,
new Type[] { typeof(Stream), type.MakeByRefType() }, null);
}
示例9: Parse
public object Parse(Type type, XObject config, bool isAssignableTypeAllowed, XmlLocation childLocation, IContext context)
{
var value = config.Value();
var m = type.GetMethod("TryParse", new Type[] { typeof(string), type.MakeByRefType() });
object[] args = { value, null };
var r = (bool)m.Invoke(null, args);
if (!r)
throw new TypeCastException(value, type, config);
return args[1];
}
示例10: RedirectMethod
public static Tuple<MethodInfo, RedirectCallsState> RedirectMethod(Type targetType, MethodInfo detour)
{
var parameters = detour.GetParameters();
Type[] types;
if (parameters.Length > 0 && (
(!targetType.IsValueType && parameters[0].ParameterType == targetType) ||
(targetType.IsValueType && parameters[0].ParameterType == targetType.MakeByRefType()))){
types = parameters.Skip(1).Select(p => p.ParameterType).ToArray();
} else {
types = parameters.Select(p => p.ParameterType).ToArray();
}
var originalMethod = targetType.GetMethod(detour.Name,
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static, null, types,
null);
var redirectCallsState = RedirectionHelper.RedirectCalls(originalMethod, detour);
return Tuple.New(originalMethod, redirectCallsState);
}
示例11: TryTryParse
/// <summary>
/// Tries to convert string to given type if TryParse method exists in the type
/// </summary>
/// <param name="str"></param>
/// <param name="t"></param>
/// <param name="res"></param>
/// <returns>TryParse was present && string was successfully parsed</returns>
public static bool TryTryParse(string str, Type t, out object res)
{
var parseMethod = t.GetMethod("TryParse", new Type[] { typeof(string), t.MakeByRefType() });
if (parseMethod != null)
{
object objectArgument = null;
object[] tryParseParams = new object[] { str, objectArgument };
if ((bool)parseMethod.Invoke(t, tryParseParams))
{
res = Convert.ChangeType(tryParseParams[1], t);
return true;
}
}
res = null;
return false;
}
示例12: GenerateDeserializerClass
static MethodBuilder GenerateDeserializerClass(TypeBuilder typeBuilder, Type objType, Type ownerType = null)
{
MethodBuilder method;
var suffix = ownerType == objType ? "Method" : string.Empty;
var key = objType.FullName + suffix;
var methodPrefix = objType.Name + suffix;
if (ReaderMethodBuilders.TryGetValue(key, out method)) return method;
var methodName = String.Intern("Read") + methodPrefix;
method = typeBuilder.DefineMethod(methodName, MethodAttribute,
typeof(void), new[] { objType.IsValueType ? objType.MakeByRefType() : objType, ByteArrayType, typeof(int).MakeByRefType() });
ReaderMethodBuilders[key] = method;
var methodIL = method.GetILGenerator();
WriteDeserializerClass(typeBuilder, methodIL, objType, tag: 0, setMethod: null, callerType: objType);
methodIL.Emit(OpCodes.Ret);
return method;
}
示例13: ReflectionOptimizer
/// <summary>
/// Class constructor.
/// </summary>
public ReflectionOptimizer(
System.Type mappedType, IGetter[] getters, ISetter[] setters)
{
// save off references
this.mappedType = mappedType;
this.typeOfThis = mappedType.IsValueType ? mappedType.MakeByRefType() : mappedType;
//this.getters = getters;
//this.setters = setters;
GetPropertyValuesInvoker getInvoker = GenerateGetPropertyValuesMethod(getters);
SetPropertyValuesInvoker setInvoker = GenerateSetPropertyValuesMethod(getters, setters);
this.accessOptimizer = new AccessOptimizer(
getInvoker,
setInvoker,
getters,
setters);
this.createInstanceMethod = CreateCreateInstanceMethod(mappedType);
}
示例14: IsMatched
public override bool IsMatched(MethodInfo method, string id, Type testedType = null)
{
if (!base.IsMatched(method, id))
{
return false;
}
bool isSignatureMatches;
var parameters = method.GetParameters();
if (testedType == null)
{
isSignatureMatches = (parameters.Count() == 0);
}
else
{
isSignatureMatches = (parameters.Count() == 1 &&
parameters.First().ParameterType.IsByRef &&
parameters.First().ParameterType == testedType.MakeByRefType());
}
return isSignatureMatches && method.ReturnType == typeof(void);
}
示例15: TryParseMatches
public static void TryParseMatches(Type svo, SingleValueObjectAttribute attr)
{
var staticMethods = svo.GetMethods(BindingFlags.Public | BindingFlags.Static);
// The out parameter.
var byrefSvo = svo.MakeByRefType();
var tryParse = staticMethods.SingleOrDefault(method =>
method.Name == "TryParse" &&
method.GetParameters().Length == 2 &&
method.GetParameters()[0].ParameterType == typeof(String) &&
method.GetParameters()[1].ParameterType == byrefSvo &&
method.GetParameters()[1].IsOut &&
method.ReturnType == typeof(Boolean));
var tryParseCulture = staticMethods.SingleOrDefault(method =>
method.Name == "TryParse" &&
method.GetParameters().Length == 3 &&
method.GetParameters()[0].ParameterType == typeof(String) &&
method.GetParameters()[1].ParameterType == typeof(IFormatProvider) &&
method.GetParameters()[2].ParameterType == byrefSvo &&
method.GetParameters()[2].IsOut &&
method.ReturnType == typeof(Boolean));
if (attr.StaticOptions.HasFlag(SingleValueStaticOptions.TryParse))
{
Assert.IsNotNull(tryParse, "{0} should contain a static TryParse method.", svo);
if (attr.StaticOptions.HasFlag(SingleValueStaticOptions.CultureDependent))
{
Assert.IsNotNull(tryParseCulture, "{0} should contain a static TryParse method with an IFormatProvider parameter.", svo);
}
else
{
Assert.IsNull(tryParseCulture, "{0} should not contain a static TryParse method with an IFormatProvider parameter.", svo);
}
}
else
{
Assert.IsNull(tryParse, "{0} should not contain a static TryParse method.", svo);
Assert.IsNull(tryParseCulture, "{0} should not contain a static TryParse method with an IFormatProvider parameter.", svo);
}
}