/// <summary> /// Gets all non-attached <see cref="AvaloniaProperty"/>s registered on a type. /// </summary> /// <param name="type">The type.</param> /// <returns>A collection of <see cref="AvaloniaProperty"/> definitions.</returns> public IEnumerable <AvaloniaProperty> GetRegistered(Type type) { Contract.Requires <ArgumentNullException>(type != null); if (_registeredCache.TryGetValue(type, out var result)) { return(result); } var t = type; result = new List <AvaloniaProperty>(); while (t != null) { // Ensure the type's static ctor has been run. RuntimeHelpers.RunClassConstructor(t.TypeHandle); if (_registered.TryGetValue(t, out var registered)) { result.AddRange(registered.Values); } t = t.BaseType; } _registeredCache.Add(type, result); return(result); }
private void setupContracts() { RuntimeTypeModel.Default.AutoAddMissingTypes = true; Type contractType = typeof(IContract <>); IEnumerable <TypeInfo> types = typeof(AGSGame).GetTypeInfo().Assembly.DefinedTypes; foreach (var type in types) { if (!type.IsGenericType && type.GetCustomAttribute <ProtoContractAttribute>() != null) { RuntimeHelpers.RunClassConstructor(type.AsType().TypeHandle); //Forcing static constructors for contracts } Type contract = getSupportedInterfaces(type.AsType(), contractType); if (contract == null) { continue; } if (contractType.Equals(type)) { continue; } RuntimeTypeModel.Default.Add(contract, true).AddSubType(ContractsFactory.RunningID++, type.AsType()); Type contractWrapper = typeof(Contract <>); contractWrapper = contractWrapper.MakeGenericType(contract.GetTypeInfo().GenericTypeArguments[0]); RuntimeTypeModel.Default.Add(contract, true).AddSubType(ContractsFactory.RunningID++, contractWrapper); } }
public static void Map(Type t) { RuntimeHelpers.RunClassConstructor(t.BaseType.TypeHandle); var setting = new MapSetting(); setting.AddMapping(null, null); //setting.mappings.Add(new ) //var l = t.GetCustomAttributesData(); //TypeDescriptor.AddAttributes(t, new MapPair()); //TypeDescriptor.AddAttributes(t, new MapPair()); //TypeDescriptor.AddAttributes(t, new MapPair()); TypeDescriptor.AddAttributes(t, setting); TypeDescriptor.AddAttributes(t, new MapPair()); //Console.WriteLine(TypeDescriptor.GetAttributes(t).Count); //l.Add(new MapPair()); //l.Add(new MapPair()); //l.Add(new MapPair()); Console.WriteLine("base: " + t.BaseType.Name); Console.WriteLine("mapping: " + t.Name); }
/// <summary> /// Initializes some static constructors related to the decoder and instruction info. If those /// static constructors are initialized, the jitter generates faster code since it doesn't have /// to add runtime checks to see if those static constructors must be called. /// /// This method should be called before using the decoder and instruction info classes and /// should *not* be called from the same method as any code that uses the decoder / instruction /// info classes. Eg. call this method from Main() and decode instructions / get instruction info /// in a method called by Main(). /// </summary> public static void Initialize() { #if DECODER // The decoder already initializes this stuff, but when it's called, it's a little bit too late. RuntimeHelpers.RunClassConstructor(typeof(Decoder).TypeHandle); #endif }
public void RunClassConstructor_Default() { RuntimeTypeHandle rth = new RuntimeTypeHandle(); Assert.AreEqual(IntPtr.Zero, rth.Value, "Value"); RuntimeHelpers.RunClassConstructor(rth); }
static InjectTypeInfo GetInfoInternal(Type type) { if (ShouldSkipTypeAnalysis(type)) { return(null); } #if ZEN_INTERNAL_PROFILING // Make sure that the static constructor logic doesn't inflate our profile measurements using (ProfileTimers.CreateTimedBlock("User Code")) { RuntimeHelpers.RunClassConstructor(type.TypeHandle); } #endif #if ZEN_INTERNAL_PROFILING using (ProfileTimers.CreateTimedBlock("Type Analysis - Calling Baked Reflection Getter")) #endif { var getInfoMethod = type.GetMethod( ReflectionBakingGetInjectInfoMethodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); if (getInfoMethod != null) { #if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR var infoGetter = (ZenTypeInfoGetter)getInfoMethod.CreateDelegate( typeof(ZenTypeInfoGetter), null); #else var infoGetter = ((ZenTypeInfoGetter)Delegate.CreateDelegate( typeof(ZenTypeInfoGetter), getInfoMethod)); #endif return(infoGetter()); } } if (ReflectionBakingCoverageMode == ReflectionBakingCoverageModes.NoCheckAssumeFullCoverage) { // If we are confident that the reflection baking supplies all the injection information, // then we can avoid the costs of doing reflection on types that were not covered // by the baking return(null); } #if !(UNITY_WSA && ENABLE_DOTNET) || UNITY_EDITOR if (ReflectionBakingCoverageMode == ReflectionBakingCoverageModes.FallbackToDirectReflectionWithWarning) { Log.Warn("No reflection baking information found for type '{0}' - using more costly direct reflection instead", type); } #endif #if ZEN_INTERNAL_PROFILING using (ProfileTimers.CreateTimedBlock("Type Analysis - Direct Reflection")) #endif { return(CreateTypeInfoFromReflection(type)); } }
/// <summary> /// Invokes the class constructor on all types in <paramref name="assembly"/> with /// the <see cref="InitializeOnStartupAttribute"/>. /// </summary> /// <param name="assembly">The assembly whose types will be used.</param> public static void InitializeTypes(Assembly assembly) { foreach (var type in assembly.GetTypes() .Where(t => Attribute.IsDefined(t, typeof(InitializeOnStartupAttribute)))) { RuntimeHelpers.RunClassConstructor(type.TypeHandle); } }
public MyEntityCreationThread() { RuntimeHelpers.RunClassConstructor(typeof(MyEntityIdentifier).TypeHandle); this.m_thread = new Thread(new ThreadStart(this.ThreadProc)); this.m_thread.CurrentCulture = CultureInfo.InvariantCulture; this.m_thread.CurrentUICulture = CultureInfo.InvariantCulture; this.m_thread.Start(); }
protected virtual void DefineIntrinsicObjectFromType(Type type) { if (type.HasAttribute(out IntrinsicObjectAttribute typeAttr) && visitedTypes.Add(type)) { RuntimeHelpers.RunClassConstructor(type.TypeHandle); DefineIntrinsicObjectFromType(type, typeAttr); } }
// Ensures that the weapon sub classes have their static constructors ran // same thing for projectile systems static WeaponFactory() { AppDomain.CurrentDomain.GetAssemblies().ToList() .ForEach(assem => assem.GetTypes() .Where(st => st.BaseType == typeof(ProjectileSystem)).ToList() .ForEach(st => RuntimeHelpers.RunClassConstructor(st.TypeHandle)) ); }
private static MethodInfo FindCloneMethod(Type type) { var genericCloner = typeof(Cloner <>).MakeGenericType(type); RuntimeHelpers.RunClassConstructor(genericCloner.TypeHandle); return(genericCloner.GetMethod("Clone", Reflect.StaticFlags) .ThrowIfNull("Cannot find Cloner<T>.Clone(T value)")); }
public static void RunClassConstructor() { RuntimeTypeHandle t = typeof(HasCctor).TypeHandle; RuntimeHelpers.RunClassConstructor(t); Assert.Equal("Hello", HasCctorReceiver.S); return; }
static PropertyValueSetter() { RuntimeHelpers.RunClassConstructor(typeof(PackedDefinition).TypeHandle); PackedDefinition.SubjectKind.SetValue(ref DefaultPackedValue, SubjectKind.Unspecified); PackedDefinition.PropertyKind.SetValue(ref DefaultPackedValue, PropertyKind.Unspecified); PackedDefinition.ValueKind.SetValue(ref DefaultPackedValue, ValueKind.Unspecified); }
internal DefaultSandbox() { this.Domain = AppDomain.CurrentDomain; this.Symbols = new SymbolTable(typeof(ReplSymbols)) .Apply(s => s["*context*"] = Expression.Default(typeof(EvaluationContext))); this.History = new SortedList <DateTime, String>(); RuntimeHelpers.RunClassConstructor(typeof(StandardGrammar).TypeHandle); }
public static void EnsureClassConstructorRun() { if (!ClassUtility <T> .cctorRun) { ClassUtility <T> .cctorRun = true; RuntimeHelpers.RunClassConstructor(typeof(T).TypeHandle); } }
//[TestMethod] public void DllInit() { var t = typeof(StaticInit); //t.GetInterfaceMap() RuntimeHelpers.RunClassConstructor(t.TypeHandle); RuntimeHelpers.RunClassConstructor(t.TypeHandle); }
static void RunClassConstructor(Type type) { RuntimeHelpers.RunClassConstructor(type.TypeHandle); if (type.BaseType != typeof(object)) { RunClassConstructor(type.BaseType); } }
public MainWindow(MainViewModel mainViewModel) { _mainViewModel = mainViewModel; // Asuring the commands are properly initialized in the grid itself RuntimeHelpers.RunClassConstructor(typeof(RadGridViewCommands).TypeHandle); InitializeComponent(); DataContext = mainViewModel; }
private void GetResourceStringCode(object userDataIn) { GetResourceStringUserData data = (GetResourceStringUserData)userDataIn; Environment.ResourceHelper resourceHelper = data.m_resourceHelper; string key = data.m_key; CultureInfo culture = data.m_culture; Monitor.Enter(resourceHelper, ref data.m_lockWasTaken); if (((resourceHelper.currentlyLoading != null) && (resourceHelper.currentlyLoading.Count > 0)) && resourceHelper.currentlyLoading.Contains(key)) { try { new StackTrace(true).ToString(StackTrace.TraceFormat.NoResourceLookup); } catch (StackOverflowException) { } catch (NullReferenceException) { } catch (OutOfMemoryException) { } data.m_retVal = "[Resource lookup failed - infinite recursion or critical failure detected.]"; } else { if (resourceHelper.currentlyLoading == null) { resourceHelper.currentlyLoading = new Stack(4); } if (!resourceHelper.resourceManagerInited) { RuntimeHelpers.PrepareConstrainedRegions(); try { } finally { RuntimeHelpers.RunClassConstructor(typeof(ResourceManager).TypeHandle); RuntimeHelpers.RunClassConstructor(typeof(ResourceReader).TypeHandle); RuntimeHelpers.RunClassConstructor(typeof(RuntimeResourceSet).TypeHandle); RuntimeHelpers.RunClassConstructor(typeof(BinaryReader).TypeHandle); resourceHelper.resourceManagerInited = true; } } resourceHelper.currentlyLoading.Push(key); if (resourceHelper.SystemResMgr == null) { resourceHelper.SystemResMgr = new ResourceManager(this.m_name, typeof(object).Assembly); } string str2 = resourceHelper.SystemResMgr.GetString(key, null); resourceHelper.currentlyLoading.Pop(); data.m_retVal = str2; } }
/// <summary> /// 确保执行DbType的静态构造函数,以初始化配置 /// </summary> internal static void EnsureDbTypeReg(Type dbType) { if (DbTypeConfigs.ContainsKey(dbType.Name)) { return; } RuntimeHelpers.RunClassConstructor(dbType.TypeHandle); //手动执行静态构造函数 }
private static void EnsureTypeInitialized(Type type) { try { // Ensure the static members are accessed class' ctor RuntimeHelpers.RunClassConstructor(type.TypeHandle); } catch (TypeInitializationException) { } }
public static String GetIdentifier <U>() where U : BaseClass { var t = typeof(U); var identifier = default(String); RuntimeHelpers.RunClassConstructor(t.TypeHandle); m_identities.TryGetValue(t.GetHashCode(), out identifier); return(identifier); }
/// <summary> /// Construct caches /// </summary> public static void InitiateCaches() { var t1 = Task.Run(() => RuntimeHelpers.RunClassConstructor(typeof(PlayerCache).TypeHandle)); var t2 = Task.Run(() => RuntimeHelpers.RunClassConstructor(typeof(VehicleCache).TypeHandle)); var t3 = Task.Run(() => RuntimeHelpers.RunClassConstructor(typeof(WeaponsCache).TypeHandle)); var t4 = Task.Run(() => RuntimeHelpers.RunClassConstructor(typeof(LoadoutCache).TypeHandle)); Task.WhenAll(t1, t2, t3, t4).GetAwaiter().GetResult(); }
/// <summary> /// Calls the static constructor of this type. /// </summary> /// <param name="type">The type of which to call the static constructor.</param> public static void CallStaticConstructor([NotNull] this Type type) { if (type is null) { throw new ArgumentNullException(nameof(type)); } RuntimeHelpers.RunClassConstructor(type.TypeHandle); }
internal static void FullSetup() { foreach (var type in CoreClrTypes) { RuntimeHelpers.RunClassConstructor(type.TypeHandle); } ImportManager.Value.LoadAll(CoreClrTypes, Clr.Imports); }
private static void Main(string[] args) { RuntimeHelpers.RunClassConstructor(typeof(Settings).TypeHandle); RuntimeHelpers.RunClassConstructor(typeof(Logger).TypeHandle); Commands.Parse(args); Logger.Finish(); }
private static void InvokeStaticConstructorFor <T>() { var type = typeof(T); // guarantees that the static constructor is only called once, // regardless how many times the method is called //https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.runtimehelpers.runclassconstructor%28v=vs.110%29.aspx RuntimeHelpers.RunClassConstructor(type.TypeHandle); }
public static Class forName0(Type clazz, string classname, bool initialize, ClassLoader loader, Class caller) { Class found; Console.WriteLine(" searching for {0}", classname); if (loader != null) { found = _loadClass[loader](classname, initialize); } else { if (classname == null) { throw new NullReferenceException(nameof(classname)); } if (classname.StartsWith("[")) { classname = classname.TrimStart('['); initialize = false; } if (classname.StartsWith("L") && classname.EndsWith(";")) { classname = classname.Substring(1, classname.Length - 2); } Type t = null; foreach (var type in typeof(Class).Assembly.GetTypes()) { if (type.FullName == classname) { t = type; } if (type.GetCustomAttribute <JavaNameAttribute>()?.Name.Replace('/', '.') == classname) { t = type; } } if (t == null) { throw new ClassNotFoundException(classname); } if (initialize) { RuntimeHelpers.RunClassConstructor(t.TypeHandle); } found = (Class)ReflectionBridge.GetClass(t); } return(found); }
public void TestRunClassConstructor() { RuntimeHelpers.RunClassConstructor(typeof(FooClass).TypeHandle); Assert.AreEqual(FooClass.counter, 1); // Each static constructor should only be run once RuntimeHelpers.RunClassConstructor(typeof(FooClass).TypeHandle); Assert.AreEqual(FooClass.counter, 1); }
/// <summary> /// Checks <paramref name="assembly"/> for having <see cref="InitializeOnLoadAttribute"/> and runs static constructors for found types. /// If static constructor of type already executed, nothing happens. /// </summary> /// <param name="assembly"></param> public static void InitializeTypesFromAttribute(this Assembly assembly) { var attrType = typeof(InitializeOnLoadAttribute); foreach (InitializeOnLoadAttribute attr in assembly.GetCustomAttributes(attrType, false)) { RuntimeHelpers.RunClassConstructor(attr.Type.TypeHandle); //Static constructor for same type will be executed only once. } }