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


C# Type.MakeByRefType方法代码示例

本文整理汇总了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;
		}
开发者ID:ppdai,项目名称:TripSerializer.Net,代码行数:7,代码来源:DeserializerCodegen.cs

示例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);
        }
开发者ID:boformer,项目名称:GrowableOverhaul,代码行数:26,代码来源:RedirectionUtil.cs

示例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));
        }
开发者ID:hxzqlh,项目名称:enode,代码行数:29,代码来源:Helpers.cs

示例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);
            }
        }
开发者ID:mauroa,项目名称:NuGet.VisualStudioExtension,代码行数:35,代码来源:ExtensionManagerShim.cs

示例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;
        }
开发者ID:pczy,项目名称:Pub.Class,代码行数:9,代码来源:DeserializerStub.cs

示例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 ();
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:9,代码来源:MetadataExtensions.cs

示例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;
        }
开发者ID:dkushner,项目名称:SlimDX,代码行数:15,代码来源:TrampolineParameter.cs

示例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);
        }
开发者ID:ahandacgs,项目名称:netserializer,代码行数:10,代码来源:CustomSerializers.cs

示例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];
        }
开发者ID:IIITanbI,项目名称:1,代码行数:13,代码来源:TryParseTypeParser.cs

示例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);
 }
开发者ID:earalov,项目名称:Skylines-BuildAnywhere,代码行数:17,代码来源:RedirectionUtil.cs

示例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;
        }
开发者ID:rjankovic,项目名称:deskmin,代码行数:24,代码来源:Functions.cs

示例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;
        }
开发者ID:blooop,项目名称:MessageShark,代码行数:19,代码来源:CustomBinary.IL.Deserialize.cs

示例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);
		}
开发者ID:pallmall,项目名称:WCell,代码行数:23,代码来源:ReflectionOptimizer.cs

示例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);
        }
开发者ID:Coderik,项目名称:NGauge,代码行数:22,代码来源:MilestoneFinalizingAttribute.cs

示例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);
            }
        }
开发者ID:helderman,项目名称:Qowaiv,代码行数:42,代码来源:SvoAssert.cs


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