本文整理汇总了C#中ConstructorInfo类的典型用法代码示例。如果您正苦于以下问题:C# ConstructorInfo类的具体用法?C# ConstructorInfo怎么用?C# ConstructorInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorInfo类属于命名空间,在下文中一共展示了ConstructorInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssemblyLoaderImporter
public AssemblyLoaderImporter(ModuleReader moduleReader, AssemblyResolver assemblyResolver, EmbedTask embedTask)
{
instructionConstructorInfo = typeof (Instruction).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] {typeof (OpCode), typeof (object)}, null);
this.moduleReader = moduleReader;
this.assemblyResolver = assemblyResolver;
this.embedTask = embedTask;
}
示例2: Test_Load
private void Test_Load(object sender, EventArgs e)
{
_attType = typeof(AsyncStateMachineAttribute);
_assemblies = AppDomain.CurrentDomain.GetAssemblies();
_ignoreList = new[] { "Equals", "GetHashCode", "GetType", "ToString" };
_cboCategories = new Dictionary<int, string> { { 1, "EF" }, { 2, "RPC" }, { 3, "BAL" } };
cboCategories.DataSource = new BindingSource(_cboCategories, null);
cboCategories.DisplayMember = "Value";
cboCategories.ValueMember = "Key";
//cboCategories.SelectedIndex = 0;
_state = new State();
var uow = new TekTak.iLoop.UOW.UnitOfWork();
_constorInfo = new ConstructorInfo
{
ConstorParamType = new[] { uow.GetServices().GetType() },
ConstorParams = new object[] { uow.GetServices() }
};
LoadState();
_samples = API.SampleConfig.GetSamples();
cboClasses.SelectedIndex = cboClasses.Items.Count >= _state.Combo ? _state.Combo : 0;
if (treeMethods.Nodes.Count > 0) treeMethods.SelectedNode = treeMethods.Nodes.Count > _state.Node ? treeMethods.Nodes[_state.Node] : treeMethods.Nodes[0];
treeMethods.Focus();
}
示例3: 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);
}
示例4: 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;
}
}
示例5: BuildConstructors
public static StringBuilder BuildConstructors(Type type, ConstructorInfo[] constructors, int slot, int howmanyConstructors)
{
string fmt = @"
_jstype.definition.{0} = function({1}) [[ CS.Call({2}); ]]";
StringBuilder sb = new StringBuilder();
var argActual = new cg.args();
var argFormal = new cg.args();
for (int i = 0; i < constructors.Length; i++)
{
ConstructorInfo con = constructors[i];
ParameterInfo[] ps = con == null? new ParameterInfo[0] : con.GetParameters();
argActual.Clear().Add(
(int)JSVCall.Oper.CONSTRUCTOR, // OP
slot,
i, // NOTICE
"true", // IsStatics
"this"
);
argFormal.Clear();
// add T to formal param
if (type.IsGenericTypeDefinition)
{
// TODO check
int TCount = type.GetGenericArguments().Length;
for (int j = 0; j < TCount; j++)
{
argFormal.Add("t" + j + "");
argActual.Add("t" + j + ".getNativeType()");
}
}
//StringBuilder sbFormalParam = new StringBuilder();
//StringBuilder sbActualParam = new StringBuilder();
for (int j = 0; j < ps.Length; j++)
{
argFormal.Add("a" + j.ToString());
argActual.Add("a" + j.ToString());
}
sb.AppendFormat(fmt,
SharpKitMethodName("ctor", ps, howmanyConstructors > 1), // [0]
argFormal, // [1]
argActual); // [2]
}
return sb;
}
示例6: 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());
}
示例7: AddAutomagicSerializationToWorkaroundBaseClass
internal static ConstructorInfo AddAutomagicSerializationToWorkaroundBaseClass(TypeBuilder typeBuilderWorkaroundBaseClass, ConstructorInfo baseCtor)
{
if (typeBuilderWorkaroundBaseClass.BaseType.IsSerializable)
{
typeBuilderWorkaroundBaseClass.SetCustomAttribute(serializableAttribute);
if (baseCtor != null && (baseCtor.IsFamily || baseCtor.IsFamilyOrAssembly))
{
return AddConstructor(typeBuilderWorkaroundBaseClass, null, baseCtor, false);
}
}
return null;
}
示例8: BuildConstructors
public static StringBuilder BuildConstructors(Type type, ConstructorInfo[] constructors, int[] constructorsIndex, ClassCallbackNames ccbn)
{
/*
* methods
* 0 function name
* 1 list<CSParam> generation
* 2 function call
*/
string fmt = @"
static bool {0}(JSVCall vc, int argc)
[[
{1}
return true;
]]
";
StringBuilder sb = new StringBuilder();
/*if (constructors.Length == 0 && JSBindingSettings.IsGeneratedDefaultConstructor(type) &&
(type.IsValueType || (type.IsClass && !type.IsAbstract && !type.IsInterface)))
{
int olIndex = 1;
bool returnVoid = false;
string functionName = type.Name + "_" + type.Name +
(olIndex > 0 ? olIndex.ToString() : "") + "";// (cons.IsStatic ? "_S" : "");
sb.AppendFormat(fmt, functionName,
BuildNormalFunctionCall(0, new ParameterInfo[0], type.Name, type.Name, false, returnVoid, null, true));
ccbn.constructors.Add(functionName);
ccbn.constructorsCSParam.Add(GenListCSParam2(new ParameterInfo[0]).ToString());
}*/
// increase index if adding default constructor
// int deltaIndex = 0;
if (JSBindingSettings.NeedGenDefaultConstructor(type))
{
// deltaIndex = 1;
}
for (int i = 0; i < constructors.Length; i++)
{
ConstructorInfo cons = constructors[i];
if (cons == null)
{
sb.AppendFormat("public static ConstructorID constructorID{0} = new ConstructorID({1});\n", i, "null, null");
// this is default constructor
//bool returnVoid = false;
//string functionName = type.Name + "_" + type.Name + "1";
int olIndex = i + 1; // for constuctors, they are always overloaded
string functionName = JSNameMgr.HandleFunctionName(type.Name + "_" + type.Name + (olIndex > 0 ? olIndex.ToString() : ""));
sb.AppendFormat(fmt, functionName,
BuildNormalFunctionCall(0, new ParameterInfo[0], type.Name, false, null, true));
ccbn.constructors.Add(functionName);
ccbn.constructorsCSParam.Add(GenListCSParam2(new ParameterInfo[0]).ToString());
}
else
{
ParameterInfo[] paramS = cons.GetParameters();
int olIndex = i + 1; // for constuctors, they are always overloaded
int methodTag = i/* + deltaIndex*/;
for (int j = 0; j < paramS.Length; j++)
{
if (JSDataExchangeEditor.IsDelegateDerived(paramS[j].ParameterType))
{
StringBuilder sbD = JSDataExchangeEditor.Build_DelegateFunction(type, cons, paramS[j].ParameterType, methodTag, j);
sb.Append(sbD);
}
}
// ConstructorID
if (type.IsGenericTypeDefinition)
{
cg.args arg = new cg.args();
cg.args arg1 = new cg.args();
cg.args arg2 = new cg.args();
foreach (ParameterInfo p in cons.GetParameters())
{
cg.args argFlag = ParameterInfo2TypeFlag(p);
arg1.AddFormat("\"{0}\"", p.ParameterType.Name);
arg2.Add(argFlag.Format(cg.args.ArgsFormat.Flag));
}
if (arg1.Count > 0)
arg.AddFormat("new string[]{0}", arg1.Format(cg.args.ArgsFormat.Brace));
else
arg.Add("null");
if (arg2.Count > 0)
arg.AddFormat("new TypeFlag[]{0}", arg2.Format(cg.args.ArgsFormat.Brace));
else
arg.Add("null");
sb.AppendFormat("public static ConstructorID constructorID{0} = new ConstructorID({1});\n", i, arg.ToString());
}
string functionName = JSNameMgr.HandleFunctionName(type.Name + "_" + type.Name + (olIndex > 0 ? olIndex.ToString() : "") + (cons.IsStatic ? "_S" : ""));
sb.AppendFormat(fmt, functionName,
//.........这里部分代码省略.........
示例9: SmartConstructorMethodWrapper
internal SmartConstructorMethodWrapper(TypeWrapper declaringType, string name, string sig, ConstructorInfo method, TypeWrapper[] parameterTypes, Modifiers modifiers, MemberFlags flags)
: base(declaringType, name, sig, method, PrimitiveTypeWrapper.VOID, parameterTypes, modifiers, flags)
{
}
示例10: GetAllConstructors
static ConstructorInfo [] GetAllConstructors (Type t)
{
BindingFlags static_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Static;
BindingFlags instance_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Instance;
ConstructorInfo [] static_members = t.GetConstructors (static_flag);
ConstructorInfo [] instance_members = t.GetConstructors (instance_flag);
if (static_members == null && instance_members == null)
return null;
ConstructorInfo [] all_members = new ConstructorInfo [static_members.Length + instance_members.Length];
static_members.CopyTo (all_members, 0); // copy all static members
instance_members.CopyTo (all_members, static_members.Length); // copy all instance members
return all_members;
}
示例11: GetConstructor
public static ConstructorInfo GetConstructor(Type type, ConstructorInfo constructor)
{
return new ConstructorInfoImpl(GetMethod(type, constructor.GetMethodInfo()));
}
示例12: CustomClassLoaderCtorCaller
internal CustomClassLoaderCtorCaller(ConstructorInfo ctor, object classLoader, Assembly assembly)
{
this.ctor = ctor;
this.classLoader = classLoader;
this.assembly = assembly;
}
示例13: Initialize
void Initialize(Type targetType, string methodName)
{
if (!_delegateType.IsSubclassOf(_typeMapper.MapType(typeof(Delegate))))
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
IMemberInfo delegateInvocationMethod = null;
foreach (IMemberInfo mi in _typeMapper.TypeInfo.GetMethods(_delegateType))
{
if (mi.Name == "Invoke")
{
if (delegateInvocationMethod != null)
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
delegateInvocationMethod = mi;
}
}
if (delegateInvocationMethod == null)
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
foreach (IMemberInfo mi in _typeMapper.TypeInfo.GetConstructors(_delegateType))
{
if (mi.IsStatic)
continue;
Type[] ctorParamTypes = mi.ParameterTypes;
if (ctorParamTypes.Length == 2 && ctorParamTypes[0] == _typeMapper.MapType(typeof(object)) && ctorParamTypes[1] == _typeMapper.MapType(typeof(IntPtr)))
{
if (_delegateConstructor != null)
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
_delegateConstructor = (ConstructorInfo)mi.Member;
}
}
if (_delegateConstructor == null)
throw new ArgumentException(Properties.Messages.ErrInvalidDelegateType, "delegateType");
Type retType = delegateInvocationMethod.ReturnType;
Type[] parameterTypes = delegateInvocationMethod.ParameterTypes;
for ( ; targetType != null; targetType = targetType.BaseType)
{
foreach (IMemberInfo mi in _typeMapper.TypeInfo.Filter(_typeMapper.TypeInfo.GetMethods(targetType), methodName, false, (object)_target == null, false))
{
if (mi.ReturnType == retType && ArrayUtils.Equals(mi.ParameterTypes, parameterTypes))
{
if (_method == null)
_method = (MethodInfo)mi.Member;
else
throw new AmbiguousMatchException(Properties.Messages.ErrAmbiguousBinding);
}
}
if (_method != null)
break;
}
if (_method == null)
throw new MissingMethodException(Properties.Messages.ErrMissingMethod);
}
示例14: 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;
}
示例15: GetConstructors
internal static void GetConstructors(Type type, out ConstructorInfo defCtor, out ConstructorInfo singleOneArgCtor)
{
defCtor = null;
int oneArgCtorCount = 0;
ConstructorInfo oneArgCtor = null;
ConstructorInfo[] constructors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
// HACK we have a special rule to make some additional custom attributes from mscorlib usable:
// Attributes that have two constructors, one an enum and another one taking a byte, short or int,
// we only expose the enum constructor.
if (constructors.Length == 2 && type.Assembly == Types.Object.Assembly)
{
ParameterInfo[] p0 = constructors[0].GetParameters();
ParameterInfo[] p1 = constructors[1].GetParameters();
if (p0.Length == 1 && p1.Length == 1)
{
Type t0 = p0[0].ParameterType;
Type t1 = p1[0].ParameterType;
bool swapped = false;
if (t1.IsEnum)
{
Type tmp = t0;
t0 = t1;
t1 = tmp;
swapped = true;
}
if (t0.IsEnum && (t1 == Types.Byte || t1 == Types.Int16 || t1 == Types.Int32))
{
if (swapped)
{
singleOneArgCtor = constructors[1];
}
else
{
singleOneArgCtor = constructors[0];
}
return;
}
}
}
if (type.Assembly == Types.Object.Assembly)
{
if (type.FullName == "System.Runtime.CompilerServices.MethodImplAttribute")
{
foreach (ConstructorInfo ci in constructors)
{
ParameterInfo[] p = ci.GetParameters();
if (p.Length == 1 && p[0].ParameterType.IsEnum)
{
singleOneArgCtor = ci;
return;
}
}
}
}
foreach (ConstructorInfo ci in constructors)
{
ParameterInfo[] args = ci.GetParameters();
if (args.Length == 0)
{
defCtor = ci;
}
else if (args.Length == 1)
{
if (IsSupportedType(args[0].ParameterType))
{
oneArgCtor = ci;
oneArgCtorCount++;
}
else
{
// set to two to make sure we don't see the oneArgCtor as viable
oneArgCtorCount = 2;
}
}
}
singleOneArgCtor = oneArgCtorCount == 1 ? oneArgCtor : null;
}