private static SmokeClassData GetSmokeClassData(Type t) { SmokeClassData result; if (smokeClassCache.TryGetValue(t, out result)) { return result; } string className = null; object[] attr = t.GetCustomAttributes(typeof(SmokeClass), false); if (attr.Length > 0) { className = ((SmokeClass) attr[0]).signature; } result = new SmokeClassData(); result.className = className; smokeClassCache[t] = result; if (t.IsInterface || t.IsAbstract) { return result; } ConstructorInfo ctor = t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(Type) }, null); if (ctor == null) { return result; } ParameterExpression parameterExpression = Expression.Parameter(typeof(Type), "arg"); NewExpression newExp = Expression.New(ctor, parameterExpression); Expression<Constructor> lambda = Expression.Lambda<Constructor>(newExp, parameterExpression); result.constructor = lambda.Compile(); return result; }
private static SmokeClassData GetSmokeClassData(Type t) { SmokeClassData result = null; if (smokeClassCache.TryGetValue(t, out result)) { return result; } string className = null; object[] attr = t.GetCustomAttributes(typeof(SmokeClass), false); if (attr.Length > 0) { className = ((SmokeClass) attr[0]).signature; } result = new SmokeClassData(); result.className = className; smokeClassCache[t] = result; if (t.IsInterface) { return result; } Type[] paramTypes = new Type[1]; paramTypes[0] = typeof(Type); result.constructorParamTypes = new object[] { paramTypes[0] }; result.constructorInfo = t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[ ] { typeof( Type ) } , null); // Debug.Assert( result.constructorInfo != null, // "GetSmokeClassData(\"" + result.className + "\") constructor method missing" ); Type klass = t; do { result.proxyCreator = klass.GetMethod("CreateProxy", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); klass = klass.BaseType; } while (result.proxyCreator == null && klass != typeof(object)); // Debug.Assert( result.proxyCreator != null, // "GetSmokeClassData(\"" + result.className + "\") no CreateProxy() found" ); result.smokeObjectField = GetPrivateFieldInfo(t, "smokeObject"); return result; }