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


C# ConstructorInfo.GetParameters方法代码示例

本文整理汇总了C#中ConstructorInfo.GetParameters方法的典型用法代码示例。如果您正苦于以下问题:C# ConstructorInfo.GetParameters方法的具体用法?C# ConstructorInfo.GetParameters怎么用?C# ConstructorInfo.GetParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ConstructorInfo的用法示例。


在下文中一共展示了ConstructorInfo.GetParameters方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ItGoodConstructor

 public static bool ItGoodConstructor(ConstructorInfo C)
 {
     ParameterInfo[] ps = C.GetParameters();
     var cs = from p in ps
              let prms = p.ParameterType.GetConstructor
              (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null)
              let pms = p.ParameterType.IsValueType
              where ((prms != null) || pms)
              select p;
     return (cs.Count() == ps.Length);
 }
开发者ID:Martmath,项目名称:ExtReflection_Convert,代码行数:11,代码来源:CLS_NewInstance.cs

示例2: TupleSerializer

        public TupleSerializer(RuntimeTypeModel model, ConstructorInfo ctor, MemberInfo[] members)
        {
            if (ctor == null) throw new ArgumentNullException("ctor");
            if (members == null) throw new ArgumentNullException("members");
            this.ctor = ctor;
            this.members = members;
            this.tails = new IProtoSerializer[members.Length];

            ParameterInfo[] parameters = ctor.GetParameters();
            for (int i = 0; i < members.Length; i++)
            {
                WireType wireType;
                Type finalType = parameters[i].ParameterType;

                Type itemType = null, defaultType = null;

                MetaType.ResolveListTypes(model, finalType, ref itemType, ref defaultType);
                Type tmp = itemType == null ? finalType : itemType;

                bool asReference = false;
                int typeIndex = model.FindOrAddAuto(tmp, false, true, false);
                if (typeIndex >= 0)
                {
                    asReference = model[tmp].AsReferenceDefault;
                }
                IProtoSerializer tail = ValueMember.TryGetCoreSerializer(model, DataFormat.Default, tmp, out wireType,
                    asReference, false, false, true),
                    serializer;
                if (tail == null)
                {
                    throw new InvalidOperationException("No serializer defined for type: " + tmp.FullName);
                }

                tail = new TagDecorator(i + 1, wireType, false, tail);
                if (itemType == null)
                {
                    serializer = tail;
                }
                else
                {
                    if (finalType.IsArray)
                    {
                        serializer = new ArrayDecorator(model, tail, i + 1, false, wireType, finalType, false, false);
                    }
                    else
                    {
                        serializer = ListDecorator.Create(model, finalType, defaultType, tail, i + 1, false, wireType,
                            true, false, false);
                    }
                }
                tails[i] = serializer;
            }
        }
开发者ID:he0x,项目名称:xRAT,代码行数:53,代码来源:TupleSerializer.cs

示例3: ObjectFromConstructor

 public static object ObjectFromConstructor(ConstructorInfo C)
 {
     ParameterInfo[] ps = C.GetParameters();
     List<object> o = new List<object>();
     for (int i = 0; i < ps.Length; i++)
     {
         // if (ps[i].DefaultValue != null) o.Add(ps[i].DefaultValue); else
         if (ps[i].ParameterType.IsValueType) o.Add(Activator.CreateInstance(ps[i].ParameterType));
         else
             o.Add(ps[i].ParameterType.GetConstructor
                  (BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null).Invoke(null));
     }
     return C.Invoke(o.ToArray());
 }
开发者ID:Martmath,项目名称:ExtReflection_Convert,代码行数:14,代码来源:CLS_NewInstance.cs

示例4: AddConstructor

        static void AddConstructor (XmlElement members, ConstructorInfo constructor)
        {
                XmlDocument document = members.OwnerDocument;
                string signature = AddConstructorSignature (constructor);
                string constructor_name = constructor.Name;

                // .cctors are not suppose to be visible
                if (signature == null || constructor.Name == ".cctor")
                        return;

                XmlElement member = document.CreateElement ("Member");
                member.SetAttribute ("MemberName", constructor_name);
                members.AppendChild (member);
                XmlElement constructor_signature = document.CreateElement ("MemberSignature");
                constructor_signature.SetAttribute ("Language", "C#");
                constructor_signature.SetAttribute ("Value", signature);
                member.AppendChild (constructor_signature);
                member.AppendChild (AddElement (document, "MemberType", "Constructor"));

                Type return_type = constructor.DeclaringType;
                ParameterInfo [] parameters = constructor.GetParameters ();

                // constructors have an empty ReturnValue node.
                member.AppendChild (document.CreateElement ("ReturnValue"));
                member.AppendChild (AddParameters (document, parameters));
                member.AppendChild (AddDocsNode (document, return_type, parameters));
        }
开发者ID:emtees,项目名称:old-code,代码行数:27,代码来源:updater.cs

示例5: HasMissingType

			static bool HasMissingType (ConstructorInfo ctor)
			{
#if STATIC
				//
				// Mimic odd csc behaviour where missing type on predefined
				// attributes means the attribute is silently ignored. This can
				// happen with PCL facades
				//
				foreach (var p in ctor.GetParameters ()) {
					if (p.ParameterType.__ContainsMissingType)
						return true;
				}
#endif

				return false;
			}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:16,代码来源:import.cs

示例6: ConstructorGen

	static void ConstructorGen (ConstructorInfo c, Type t)
	{
		ParameterInfo[] parameters = c.GetParameters ();
		FunctionGen (parameters, (MethodBase) c, t, null, true);
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:5,代码来源:cilc.cs

示例7: Emit

	// Emit a call on a constructor.
	public virtual void Emit(OpCode opcode, ConstructorInfo constructor)
			{
				// Bail out if "constructor" is null.
				if(constructor == null)
				{
					throw new ArgumentNullException("constructor");
				}

				// Adjust the stack to account for the changes.
				switch((StackBehaviour)(opcode.stackPop))
				{
					case StackBehaviour.Pop0:
						break;

					case StackBehaviour.Varpop:
					{
						if(constructor is ConstructorBuilder)
						{
							height -= ((ConstructorBuilder)constructor).numParams;
						}
						else
						{
							ParameterInfo[] paramList = constructor.GetParameters();
							if(paramList != null)
							{
								height -= paramList.Length;
							}
						}
					}
					break;

					case StackBehaviour.Pop1:
					case StackBehaviour.Popi:
					case StackBehaviour.Popref:
						--height;
						break;

					case StackBehaviour.Pop1_pop1:
					case StackBehaviour.Popi_pop1:
					case StackBehaviour.Popi_popi:
					case StackBehaviour.Popi_popi8:
					case StackBehaviour.Popi_popr4:
					case StackBehaviour.Popi_popr8:
					case StackBehaviour.Popref_pop1:
					case StackBehaviour.Popref_popi:
						height -= 2;
						break;

					case StackBehaviour.Popi_popi_popi:
					case StackBehaviour.Popref_popi_popi:
					case StackBehaviour.Popref_popi_popi8:
					case StackBehaviour.Popref_popi_popr4:
					case StackBehaviour.Popref_popi_popr8:
					case StackBehaviour.Popref_popi_popref:
						height -= 3;
						break;

					default: break;
				}
				switch((StackBehaviour)(opcode.stackPush))
				{
					case StackBehaviour.Push0:
						break;

					case StackBehaviour.Push1:
					case StackBehaviour.Pushi:
					case StackBehaviour.Pushi8:
					case StackBehaviour.Pushr4:
					case StackBehaviour.Pushr8:
					case StackBehaviour.Pushref:
					case StackBehaviour.Varpush:
						++height;
						break;

					case StackBehaviour.Push1_push1:
						height += 2;
						break;

					default: break;
				}

				if(height > maxHeight)
				{
					maxHeight = height;
				}
				else if(height < 0)
				{
					height = 0;
				}

				// Output the instruction.
				MethodToken token = module.GetConstructorToken(constructor);
				EmitRawOpcode(opcode.value);
				EmitTokenWithFixup(token.Token);
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:96,代码来源:ILGenerator.cs

示例8: CheckArgsCount

    static void CheckArgsCount(ConstructorInfo info, StringBuilder sb) {
        ParameterInfo[] paramInfos;
        int argCount;
        bool isReturn = true;
        sb.Append("            int count = LuaDLL.lua_gettop(L);\r\n");
        if (constructs.Count <= 1) {
            paramInfos = info.GetParameters();
            argCount = paramInfos.Length;
            argsText = "new " + TrimNameSpace(info.ReflectedType) + "(";

            for (int i = 0; i < paramInfos.Length; i++) {
                AppendArgs("\r\n            ", sb, paramInfos, i);
                if (i != 0) {
                    argsText += ",";
                }
                argsText += string.Format("arg{0}", i + 1);
            }
            sb.Append("\r\n            ");
            argsText += ");\r\n";
            if (isReturn) {
                argsText = argsText.Remove(argsText.Length - 3, 3);
                GenPushStr(info.ReflectedType, argsText, sb, GenTypeObjectNameString(paramInfos));
            }

        }
        else {
            for (int i = 0; i < constructs.Count; i++) {
                paramInfos = constructs[i].GetParameters();
                argCount = paramInfos.Length;
                string condition = "count == " + (argCount + 1);
                for (int j = 0; j < paramInfos.Length; j++) {
                    condition += " &&\r\n                LuaStatic.CheckType(L, typeof(" + TrimNameSpace(paramInfos[j].ParameterType) + "), " + (j + 2).ToString() + ")";
                }
                sb.AppendFormat("\r\n            if ({0})", condition);
                sb.Append(" {");
                argsText = "new " + TrimNameSpace(info.ReflectedType) + "(";

                for (int j = 0; j < paramInfos.Length; j++) {
                    AppendArgs("\r\n                ", sb, paramInfos, j);
                    if (j != 0) {
                        argsText += ", ";
                    }
                    argsText += string.Format("arg{0}", j + 1);
                }
                argsText += ");\r\n";
                sb.Append("\r\n                ");
                if (isReturn) {
                    argsText = argsText.Remove(argsText.Length - 3, 3);
                    GenPushStr(info.ReflectedType, argsText, sb, true, GenTypeObjectNameString(paramInfos));
                }

                sb.Append("\r\n                return result;");
                sb.Append("\r\n            }");

                if (i == constructs.Count - 1) {
                    sb.Append("\r\n            LuaStatic.traceback(L, 'count not enough');");
                    sb.Append("\r\n            LuaDLL.lua_error(L);\r\n");
                }


            }
        }
    }
开发者ID:musicseli,项目名称:emoji,代码行数:63,代码来源:LuaApiMaker.cs

示例9: GenConstruct

    static void GenConstruct(ConstructorInfo c, StringBuilder sb) {
        AppendFunctionHead("New", sb);

        ParameterInfo[] paramInfos = c.GetParameters();
        argsText = c.ReflectedType.Name + "." + c.Name + "(";
        CheckArgsCount(c, sb);
        AppendFunctionEnd(sb);
    }
开发者ID:musicseli,项目名称:emoji,代码行数:8,代码来源:LuaApiMaker.cs

示例10: OutlineConstructor

	void OutlineConstructor (ConstructorInfo ci)
	{
		o.Write (GetMethodVisibility (ci));
		o.Write (RemoveGenericArity (t.Name));
		o.Write (" (");
		OutlineParams (ci.GetParameters ());
		o.Write (");");
	}
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:8,代码来源:outline.cs

示例11: ReadConstructorArguments

 void ReadConstructorArguments(StringBuilder sb, ByteReader br, ConstructorInfo constructor, int level)
 {
     bool first = true;
     foreach (var parameter in constructor.GetParameters())
     {
         if (!first)
         {
             AppendNewLine(sb, level);
         }
         first = false;
         ReadFixedArg(sb, br, parameter.ParameterType);
     }
 }
开发者ID:jfrijters,项目名称:ikdasm,代码行数:13,代码来源:CABlob.cs

示例12: DecodeCABlob

 bool DecodeCABlob(StringBuilder sb, ConstructorInfo constructor, byte[] blob, int level)
 {
     try
     {
         // CustomAttribute
         var br = new ByteReader(blob, 2, blob.Length - 4);
         ReadConstructorArguments(sb, br, constructor, level);
         br = new ByteReader(blob, blob.Length - (br.Length + 2), br.Length + 2);
         int named = br.ReadUInt16();
         if (constructor.GetParameters().Length != 0 && named != 0)
         {
             AppendNewLine(sb, level);
         }
         ReadNamedArguments(sb, br, named, level, false);
         return true;
     }
     catch (Managed.Reflection.BadImageFormatException) { }
     catch (ArgumentOutOfRangeException) { }
     return false;
 }
开发者ID:jfrijters,项目名称:ikdasm,代码行数:20,代码来源:CABlob.cs

示例13: GetCtorArgs

        static List<CustomAttributeTypedArgument> GetCtorArgs(object o, ConstructorInfo ctor)
        {
            var args = new List<CustomAttributeTypedArgument>();
            var props = ctor.DeclaringType.GetProperties ();

            if (props.Length == args.Count && args.Count == 1)
            {

            }

            foreach (var p in ctor.GetParameters())
            {
                var val = default(object);
                var ty = typeof(object);

                var prop = props.FirstOrDefault(x => x.Name.ToLowerInvariant() == p.Name.ToLowerInvariant());
                if (prop == null)
                {
                    prop = props.LastOrDefault();
                }

                if (prop != null)
                {
                    val = prop.GetValue(o, null);
                    ty = prop.PropertyType;
                }
                args.Add(new CustomAttributeTypedArgument()
                {
                    ArgumentType = ty,
                    Value = val
                });
            }
            return args;
        }
开发者ID:jorik041,项目名称:runcs,代码行数:34,代码来源:Shims.cs

示例14: writeConstructor

	//constructor
	static void writeConstructor(StreamWriter n, ConstructorInfo info, Type t, string alias)
	{
		writeLine(n, "//---------------------------------");

		ParamTypeData T = new ParamTypeData(t);

		string functionName = alias;
		if (string.IsNullOrEmpty(alias))
			functionName = T.csTypeName;
		funcNames.Add(functionName);

		writeLine(n,"[MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]");
		writeLine(n,"public static int {0}(IntPtr L)", functionName);
		writeLine(n,"{");

		ParameterInfo[] pinfos = info.GetParameters();
		for (int i = 0; i < pinfos.Length; ++i)
		{
			ParamTypeData paramType = new ParamTypeData(pinfos[i].ParameterType);
			paraseParam(n, paramType, i, i + 1);
		}


		ParamTypeData RetT = new ParamTypeData(info.DeclaringType);
		writeLine(n,"{0} ret = new {0}(", RetT.csFullTypeName);
		for (int i = 0; i < pinfos.Length; ++i)
		{
			writeLine(n,"param{0}{1}", i, i == pinfos.Length - 1 ? "" : ",");
		}
		writeLine(n,");");

		writeLine(n,"LuaStatic.addGameObject2Lua(L,ret,\"{0}\");",T.csTypeName);
		writeLine(n,"return 1;");
			
		writeLine(n,"}");
		writeLine(n,"");
		writeLine(n,"");
		writeLine(n,"");
	}
开发者ID:fengqk,项目名称:Art,代码行数:40,代码来源:LuaInterfaceMaker.cs


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